mirror of
https://github.com/modelscope/FunASR.git
synced 2026-10-12 02:19:18 +00:00
bugfix
This commit is contained in:
@@ -20,10 +20,10 @@ print(res)
|
||||
|
||||
# # 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)
|
||||
|
||||
@@ -15,10 +15,10 @@ python -m funasr.bin.export \
|
||||
++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
|
||||
|
||||
@@ -17,13 +17,13 @@ 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)
|
||||
# # 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)
|
||||
|
||||
@@ -4,11 +4,8 @@
|
||||
# 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} \
|
||||
++type="onnx" \
|
||||
@@ -16,12 +13,12 @@ python -m funasr.bin.export \
|
||||
++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
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
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(
|
||||
@@ -19,17 +19,30 @@ 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",
|
||||
|
||||
@@ -31,7 +31,7 @@ def export_rebuild_model(model, **kwargs):
|
||||
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
|
||||
|
||||
|
||||
@@ -83,4 +83,4 @@ def export_dynamic_axes(self):
|
||||
def export_name(
|
||||
self,
|
||||
):
|
||||
return "model.onnx"
|
||||
return "model"
|
||||
|
||||
@@ -8,32 +8,6 @@ import torch
|
||||
from funasr.register import tables
|
||||
|
||||
|
||||
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"
|
||||
@@ -64,7 +38,7 @@ def export_rebuild_model(model, **kwargs):
|
||||
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)
|
||||
@@ -72,7 +46,7 @@ def export_rebuild_model(model, **kwargs):
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user