FunASR icon indicating copy to clipboard operation
FunASR copied to clipboard

导入funasr包时间过长

Open Erlonealpha opened this issue 1 year ago • 0 comments

问题: 从funasr包导入AutoModel,初始化funasr用了1分钟多

Code

import soundfile
import os

model_path = r"model\zh-streaming"

chunk_size = [0, 10, 5] #[0, 10, 5] 600ms, [0, 8, 4] 480ms
encoder_chunk_look_back = 4 #number of chunks to lookback for encoder self-attention
decoder_chunk_look_back = 1 #number of encoder chunks to lookback for decoder cross-attention

wav_file = os.path.join(r"model\zh-streaming\asr_example.wav")
speech, sample_rate = soundfile.read(wav_file)
chunk_stride = chunk_size[1] * 960 # 600ms

from funasr import AutoModel

model = AutoModel(model=model_path)
cache = {}
total_chunk_num = int(len((speech)-1)/chunk_stride+1)
for i in range(total_chunk_num):
    speech_chunk = speech[i*chunk_stride:(i+1)*chunk_stride]
    is_final = i == total_chunk_num - 1
    res = model.generate(input=speech_chunk, cache=cache, is_final=is_final, 
                         chunk_size=chunk_size, encoder_chunk_look_back=encoder_chunk_look_back, 
                         decoder_chunk_look_back=decoder_chunk_look_back)
    print(res)

导入包时输出:

Failed to import funasr.bin.tokenize_text: No module named 'funasr.utils.cli_utils'
Failed to import funasr.bin.train: cannot import name 'AutoModel' from partially initialized module 'funasr' (most likely due to a circular import) (f:\Anaconda3\envs\KemonoManager_gui\Lib\site-packages\funasr\__init__.py)
Failed to import funasr.download.runtime_sdk_download_tool: No module named 'humanfriendly'
Failed to import funasr.frontends.fused: No module named 'humanfriendly'
Failed to import funasr.frontends.s3prl: No module named 'humanfriendly'
Failed to import funasr.models.data2vec.data2vec: No module named 'funasr.frontends.abs_frontend'
Failed to import funasr.models.language_model.rnn.decoders: No module named 'funasr.models.transformer.utils.scorers'
Failed to import funasr.models.language_model.seq_rnn_lm: No module named 'funasr.train'
Failed to import funasr.models.language_model.transformer_lm: No module named 'funasr.models.encoder'
Failed to import funasr.models.mfcca.e2e_asr_mfcca: cannot import name 'ErrorCalculator' from 'funasr.metrics' (f:\Anaconda3\envs\KemonoManager_gui\Lib\site-packages\funasr\metrics\__init__.py)
Failed to import funasr.models.mfcca.mfcca_encoder: No module named 'funasr.models.encoder'
Failed to import funasr.models.mossformer.e2e_ss: No module named 'funasr.models.base_model'
Failed to import funasr.models.mossformer.mossformer_encoder: No module named 'funasr.models.transformer.mossformer'
Failed to import funasr.models.sa_asr.beam_search_sa_asr: cannot import name 'end_detect' from 'funasr.metrics' (f:\Anaconda3\envs\KemonoManager_gui\Lib\site-packages\funasr\metrics\__init__.py)
Failed to import funasr.models.sa_asr.e2e_sa_asr: No module named 'funasr.layers'
Failed to import funasr.models.sense_voice.whisper_lib.triton_ops: triton import failed; try `pip install --pre triton`
Failed to import funasr.models.sond.e2e_diar_sond: No module named 'funasr.models.decoder'
Failed to import funasr.models.sond.encoder.conv_encoder: No module named 'funasr.models.encoder'
Failed to import funasr.models.sond.encoder.fsmn_encoder: No module named 'funasr.models.encoder'
Failed to import funasr.models.sond.encoder.resnet34_encoder: No module named 'funasr.models.encoder'
Failed to import funasr.models.sond.encoder.self_attention_encoder: cannot import name 'CTC' from 'funasr.models.ctc' (f:\Anaconda3\envs\KemonoManager_gui\Lib\site-packages\funasr\models\ctc\__init__.py)
Failed to import funasr.models.sond.sv_decoder: No module named 'funasr.models.decoder'
Failed to import funasr.models.whisper_lid.eres2net.simple_avg: No module named 'funasr.models.encoder'
Failed to import funasr.models.xvector.e2e_sv: No module named 'funasr.layers'
Failed to import funasr.utils.speaker_utils: No module named 'funasr.utils.modelscope_file'
Failed to import funasr.utils.types: No module named 'humanfriendly'

What have you tried?

尝试将__init__.py中导入子模块改为非递归(没区别) 尝试不导入子模块(会出现完整性错误)

What's your environment?

  • OS (e.g., Linux): Windows 11
  • FunASR Version (e.g., 1.0.0): 1.0.27
  • ModelScope Version (e.g., 1.11.0): 1.14.0
  • PyTorch Version (e.g., 2.0.0):
  • How you installed funasr (pip, source): pip
  • Python version: 3.12.3
  • GPU (e.g., V100M32) : 3060 laptop
  • CUDA/cuDNN version (e.g., cuda11.7): cuda 12
  • Docker version (e.g., funasr-runtime-sdk-cpu-0.4.1)
  • Any other relevant information:

Erlonealpha avatar Jun 02 '24 08:06 Erlonealpha