游雁
2023-10-19 b9bcf1f093c3053fdc4e2cf4a1d38e27bbf429fb
funasr/runtime/python/onnxruntime/funasr_onnx/vad_bin.py
@@ -31,14 +31,42 @@
                quantize: bool = False,
                intra_op_num_threads: int = 4,
                max_end_sil: int = None,
                cache_dir: str = None
                ):
      
      if not Path(model_dir).exists():
         raise FileNotFoundError(f'{model_dir} does not exist.')
         try:
            from modelscope.hub.snapshot_download import snapshot_download
         except:
            raise "You are exporting model from modelscope, please install modelscope and try it again. To install modelscope, you could:\n" \
                  "\npip3 install -U modelscope\n" \
                  "For the users in China, you could install with the command:\n" \
                  "\npip3 install -U modelscope -i https://mirror.sjtu.edu.cn/pypi/web/simple"
         try:
            model_dir = snapshot_download(model_dir, cache_dir=cache_dir)
         except:
            raise "model_dir must be model_name in modelscope or local path downloaded from modelscope, but is {}".format(
               model_dir)
      
      model_file = os.path.join(model_dir, 'model.onnx')
      if quantize:
         model_file = os.path.join(model_dir, 'model_quant.onnx')
      if not os.path.exists(model_file):
         print(".onnx is not exist, begin to export onnx")
         try:
            from funasr.export.export_model import ModelExport
         except:
            raise "You are exporting onnx, please install funasr and try it again. To install funasr, you could:\n" \
                  "\npip3 install -U funasr\n" \
                  "For the users in China, you could install with the command:\n" \
                  "\npip3 install -U funasr -i https://mirror.sjtu.edu.cn/pypi/web/simple"
         export_model = ModelExport(
            cache_dir=cache_dir,
            onnx=True,
            device="cpu",
            quant=quantize,
         )
         export_model.export(model_dir)
      config_file = os.path.join(model_dir, 'vad.yaml')
      cmvn_file = os.path.join(model_dir, 'vad.mvn')
      config = read_yaml(config_file)
@@ -172,14 +200,41 @@
                quantize: bool = False,
                intra_op_num_threads: int = 4,
                max_end_sil: int = None,
                cache_dir: str = None
                ):
      if not Path(model_dir).exists():
         raise FileNotFoundError(f'{model_dir} does not exist.')
         try:
            from modelscope.hub.snapshot_download import snapshot_download
         except:
            raise "You are exporting model from modelscope, please install modelscope and try it again. To install modelscope, you could:\n" \
                  "\npip3 install -U modelscope\n" \
                  "For the users in China, you could install with the command:\n" \
                  "\npip3 install -U modelscope -i https://mirror.sjtu.edu.cn/pypi/web/simple"
         try:
            model_dir = snapshot_download(model_dir, cache_dir=cache_dir)
         except:
            raise "model_dir must be model_name in modelscope or local path downloaded from modelscope, but is {}".format(
               model_dir)
      
      model_file = os.path.join(model_dir, 'model.onnx')
      if quantize:
         model_file = os.path.join(model_dir, 'model_quant.onnx')
      if not os.path.exists(model_file):
         print(".onnx is not exist, begin to export onnx")
         try:
            from funasr.export.export_model import ModelExport
         except:
            raise "You are exporting onnx, please install funasr and try it again. To install funasr, you could:\n" \
                  "\npip3 install -U funasr\n" \
                  "For the users in China, you could install with the command:\n" \
                  "\npip3 install -U funasr -i https://mirror.sjtu.edu.cn/pypi/web/simple"
         export_model = ModelExport(
            cache_dir=cache_dir,
            onnx=True,
            device="cpu",
            quant=quantize,
         )
         export_model.export(model_dir)
      config_file = os.path.join(model_dir, 'vad.yaml')
      cmvn_file = os.path.join(model_dir, 'vad.mvn')
      config = read_yaml(config_file)