| | |
| | | |
| | | # # method2, inference from local path |
| | | # from funasr import AutoModel |
| | | |
| | | # |
| | | # model = AutoModel( |
| | | # model="/Users/zhifu/.cache/modelscope/hub/iic/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch" |
| | | # ) |
| | | |
| | | # |
| | | # res = model.export(type="onnx", quantize=False) |
| | | # print(res) |
| | |
| | | ++quantize=false |
| | | |
| | | |
| | | # method2, inference from local path |
| | | model="/Users/zhifu/.cache/modelscope/hub/iic/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch" |
| | | |
| | | python -m funasr.bin.export \ |
| | | ++model=${model} \ |
| | | ++type="onnx" \ |
| | | ++quantize=false |
| | | ## method2, inference from local path |
| | | #model="/Users/zhifu/.cache/modelscope/hub/iic/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch" |
| | | # |
| | | #python -m funasr.bin.export \ |
| | | #++model=${model} \ |
| | | #++type="onnx" \ |
| | | #++quantize=false |
| | |
| | | print(res) |
| | | |
| | | |
| | | # method2, inference from local path |
| | | from funasr import AutoModel |
| | | |
| | | |
| | | model = AutoModel( |
| | | model="/Users/zhifu/.cache/modelscope/hub/iic/speech_paraformer_asr_nat-zh-cn-16k-common-vocab8404-online" |
| | | ) |
| | | |
| | | res = model.export(type="onnx", quantize=False) |
| | | print(res) |
| | | # # method2, inference from local path |
| | | # from funasr import AutoModel |
| | | # |
| | | # |
| | | # model = AutoModel( |
| | | # model="/Users/zhifu/.cache/modelscope/hub/iic/speech_paraformer_asr_nat-zh-cn-16k-common-vocab8404-online" |
| | | # ) |
| | | # |
| | | # res = model.export(type="onnx", quantize=False) |
| | | # print(res) |
| | |
| | | # method1, inference from model hub |
| | | export HYDRA_FULL_ERROR=1 |
| | | |
| | | |
| | | model="iic/speech_paraformer_asr_nat-zh-cn-16k-common-vocab8404-online" |
| | | |
| | | |
| | | |
| | | python -m funasr.bin.export \ |
| | | ++model=${model} \ |
| | |
| | | ++device="cpu" |
| | | |
| | | |
| | | # method2, inference from local path |
| | | model="/Users/zhifu/.cache/modelscope/hub/iic/speech_paraformer_asr_nat-zh-cn-16k-common-vocab8404-online" |
| | | |
| | | python -m funasr.bin.export \ |
| | | ++model=${model} \ |
| | | ++type="onnx" \ |
| | | ++quantize=false \ |
| | | ++device="cpu" \ |
| | | ++debug=false |
| | | ## method2, inference from local path |
| | | #model="/Users/zhifu/.cache/modelscope/hub/iic/speech_paraformer_asr_nat-zh-cn-16k-common-vocab8404-online" |
| | | # |
| | | #python -m funasr.bin.export \ |
| | | #++model=${model} \ |
| | | #++type="onnx" \ |
| | | #++quantize=false \ |
| | | #++device="cpu" \ |
| | | #++debug=false |
| | |
| | | from funasr import AutoModel |
| | | from funasr.utils.postprocess_utils import rich_transcription_postprocess |
| | | |
| | | model_dir = "iic/SenseVoiceSmall" |
| | | model_dir = "/Users/zhifu/Downloads/modelscope_models/SenseVoiceSmall" # "iic/SenseVoiceSmall" |
| | | |
| | | |
| | | model = AutoModel( |
| | |
| | | |
| | | # en |
| | | res = model.generate( |
| | | input=f"{model.model_path}/example/en.mp3", |
| | | input="/Users/zhifu/Downloads/8_output.wav", |
| | | cache={}, |
| | | language="auto", # "zn", "en", "yue", "ja", "ko", "nospeech" |
| | | use_itn=True, |
| | | batch_size_s=60, |
| | | merge_vad=True, # |
| | | merge_length_s=15, |
| | | merge_length_s=0.1, |
| | | ) |
| | | text = rich_transcription_postprocess(res[0]["text"]) |
| | | print(text) |
| | | |
| | | # en |
| | | res = model.generate( |
| | | input="/Users/zhifu/Downloads/8_output.wav", |
| | | cache={}, |
| | | language="auto", # "zn", "en", "yue", "ja", "ko", "nospeech" |
| | | use_itn=True, |
| | | batch_size_s=60, |
| | | merge_vad=False, # |
| | | merge_length_s=15, |
| | | ) |
| | | text = rich_transcription_postprocess(res[0]["text"]) |
| | | print(text) |
| | | raise "exit" |
| | | # zh |
| | | res = model.generate( |
| | | input=f"{model.model_path}/example/zh.mp3", |
| | |
| | | model.export_dynamic_axes = types.MethodType(export_dynamic_axes, model) |
| | | model.export_name = types.MethodType(export_name, model) |
| | | |
| | | model.export_name = 'model' |
| | | model.export_name = "model" |
| | | return model |
| | | |
| | | |
| | |
| | | def export_name( |
| | | self, |
| | | ): |
| | | return "model.onnx" |
| | | return "model" |
| | |
| | | |
| | | |
| | | def export_rebuild_model(model, **kwargs): |
| | | model.device = kwargs.get("device") |
| | | is_onnx = kwargs.get("type", "onnx") == "onnx" |
| | | encoder_class = tables.encoder_classes.get(kwargs["encoder"] + "Export") |
| | | model.encoder = encoder_class(model.encoder, onnx=is_onnx) |
| | | |
| | | predictor_class = tables.predictor_classes.get(kwargs["predictor"] + "Export") |
| | | model.predictor = predictor_class(model.predictor, onnx=is_onnx) |
| | | |
| | | decoder_class = tables.decoder_classes.get(kwargs["decoder"] + "Export") |
| | | model.decoder = decoder_class(model.decoder, onnx=is_onnx) |
| | | |
| | | from funasr.utils.torch_function import sequence_mask |
| | | |
| | | model.make_pad_mask = sequence_mask(kwargs["max_seq_len"], flip=False) |
| | | |
| | | model.forward = types.MethodType(export_forward, model) |
| | | model.export_dummy_inputs = types.MethodType(export_dummy_inputs, model) |
| | | model.export_input_names = types.MethodType(export_input_names, model) |
| | | model.export_output_names = types.MethodType(export_output_names, model) |
| | | model.export_dynamic_axes = types.MethodType(export_dynamic_axes, model) |
| | | model.export_name = types.MethodType(export_name, model) |
| | | |
| | | return model |
| | | |
| | | |
| | | def export_rebuild_model(model, **kwargs): |
| | | # self.device = kwargs.get("device") |
| | | is_onnx = kwargs.get("type", "onnx") == "onnx" |
| | | encoder_class = tables.encoder_classes.get(kwargs["encoder"] + "Export") |
| | |
| | | encoder_model.export_input_names = types.MethodType(export_encoder_input_names, encoder_model) |
| | | encoder_model.export_output_names = types.MethodType(export_encoder_output_names, encoder_model) |
| | | encoder_model.export_dynamic_axes = types.MethodType(export_encoder_dynamic_axes, encoder_model) |
| | | encoder_model.export_name = types.MethodType(export_encoder_name, encoder_model) |
| | | encoder_model.export_name = "model" # types.MethodType(export_encoder_name, encoder_model) |
| | | |
| | | # decoder |
| | | decoder_model.forward = types.MethodType(export_decoder_forward, decoder_model) |
| | |
| | | decoder_model.export_input_names = types.MethodType(export_decoder_input_names, decoder_model) |
| | | decoder_model.export_output_names = types.MethodType(export_decoder_output_names, decoder_model) |
| | | decoder_model.export_dynamic_axes = types.MethodType(export_decoder_dynamic_axes, decoder_model) |
| | | decoder_model.export_name = types.MethodType(export_decoder_name, decoder_model) |
| | | decoder_model.export_name = "decoder" # types.MethodType(export_decoder_name, decoder_model) |
| | | |
| | | return encoder_model, decoder_model |
| | | |