| | |
| | | |
| | | model = AutoModel(model="fsmn-vad") |
| | | |
| | | wav_file = f"{model.model_path}/example/asr_example.wav" |
| | | wav_file = f"{model.model_path}/example/vad_example.wav" |
| | | res = model.generate(input=wav_file) |
| | | print(res) |
| | | ``` |
| | |
| | | ```shell |
| | | funasr/bin/train.py \ |
| | | ++model="${model_name_or_model_dir}" \ |
| | | ++model_revision="${model_revision}" \ |
| | | ++train_data_set_list="${train_data}" \ |
| | | ++valid_data_set_list="${val_data}" \ |
| | | ++dataset_conf.batch_size=20000 \ |
| | |
| | | ++train_conf.validate_interval=2000 \ |
| | | ++train_conf.save_checkpoint_interval=2000 \ |
| | | ++train_conf.keep_nbest_models=20 \ |
| | | ++train_conf.avg_nbest_model=5 \ |
| | | ++train_conf.avg_nbest_model=10 \ |
| | | ++optim_conf.lr=0.0002 \ |
| | | ++output_dir="${output_dir}" &> ${log_file} |
| | | ``` |
| | | |
| | | - `model`(str):模型名字(模型仓库中的ID),此时脚本会自动下载模型到本读;或者本地已经下载好的模型路径。 |
| | | - `model_revision`(str):当 `model` 为模型名字时,下载指定版本的模型。 |
| | | - `train_data_set_list`(str):训练数据路径,默认为jsonl格式,具体参考([例子](https://github.com/alibaba-damo-academy/FunASR/blob/main/data/list))。 |
| | | - `valid_data_set_list`(str):验证数据路径,默认为jsonl格式,具体参考([例子](https://github.com/alibaba-damo-academy/FunASR/blob/main/data/list))。 |
| | | - `dataset_conf.batch_type`(str):`example`(默认),batch的类型。`example`表示按照固定数目batch_size个样本组batch;`length` or `token` 表示动态组batch,batch总长度或者token数为batch_size。 |
| | | - `dataset_conf.batch_size`(int):与 `batch_type` 搭配使用,当 `batch_type=example` 时,表示样本个数;当 `batch_type=length` 时,表示样本中长度,单位为fbank帧数(1帧10ms)或者文字token个数。 |
| | | - `train_conf.max_epoch`(int):训练总epoch数。 |
| | | - `train_conf.log_interval`(int):打印日志间隔step数。 |
| | | - `train_conf.resume`(int):是否开启断点重训。 |
| | | - `train_conf.validate_interval`(int):训练中做验证测试的间隔step数。 |
| | | - `train_conf.save_checkpoint_interval`(int):训练中模型保存间隔step数。 |
| | | - `train_conf.keep_nbest_models`(int):保留最大多少个模型参数,按照验证集acc排序,从高到底保留。 |
| | | - `train_conf.avg_nbest_model`(int):对acc最高的n个模型取平均。 |
| | | - `train_conf.max_epoch`(int):`100`(默认),训练总epoch数。 |
| | | - `train_conf.log_interval`(int):`50`(默认),打印日志间隔step数。 |
| | | - `train_conf.resume`(int):`True`(默认),是否开启断点重训。 |
| | | - `train_conf.validate_interval`(int):`5000`(默认),训练中做验证测试的间隔step数。 |
| | | - `train_conf.save_checkpoint_interval`(int):`5000`(默认),训练中模型保存间隔step数。 |
| | | - `train_conf.avg_keep_nbest_models_type`(str):`acc`(默认),保留nbest的标准为acc(越大越好)。`loss`表示,保留nbest的标准为loss(越小越好)。 |
| | | - `train_conf.keep_nbest_models`(int):`500`(默认),保留最大多少个模型参数,配合 `avg_keep_nbest_models_type` 按照验证集 acc/loss 保留最佳的n个模型,其他删除,节约存储空间。 |
| | | - `train_conf.avg_nbest_model`(int):`10`(默认),保留最大多少个模型参数,配合 `avg_keep_nbest_models_type` 按照验证集 acc/loss 对最佳的n个模型平均。 |
| | | - `train_conf.accum_grad`(int):`1`(默认),梯度累积功能。 |
| | | - `train_conf.grad_clip`(float):`10.0`(默认),梯度截断功能。 |
| | | - `train_conf.use_fp16`(bool):`False`(默认),开启fp16训练,加快训练速度。 |
| | | - `optim_conf.lr`(float):学习率。 |
| | | - `output_dir`(str):模型保存路径。 |
| | | - `**kwargs`(dict): 所有在`config.yaml`中参数,均可以直接在此处指定,例如,过滤20s以上长音频:`dataset_conf.max_token_length=2000`,单位为音频fbank帧数(1帧10ms)或者文字token个数。 |
| | |
| | | export CUDA_VISIBLE_DEVICES="0,1" |
| | | gpu_num=$(echo $CUDA_VISIBLE_DEVICES | awk -F "," '{print NF}') |
| | | |
| | | torchrun --nnodes 2 --nproc_per_node ${gpu_num} --master_addr=192.168.1.1 --master_port=12345 \ |
| | | torchrun --nnodes 2 --node_rank 0 --nproc_per_node ${gpu_num} --master_addr 192.168.1.1 --master_port 12345 \ |
| | | ../../../funasr/bin/train.py ${train_args} |
| | | ``` |
| | | 在从节点上(假设IP为192.168.1.2),你需要确保MASTER_ADDR和MASTER_PORT环境变量与主节点设置的一致,并运行同样的命令: |
| | |
| | | export CUDA_VISIBLE_DEVICES="0,1" |
| | | gpu_num=$(echo $CUDA_VISIBLE_DEVICES | awk -F "," '{print NF}') |
| | | |
| | | torchrun --nnodes 2 --nproc_per_node ${gpu_num} --master_addr=192.168.1.1 --master_port=12345 \ |
| | | torchrun --nnodes 2 --node_rank 1 --nproc_per_node ${gpu_num} --master_addr 192.168.1.1 --master_port 12345 \ |
| | | ../../../funasr/bin/train.py ${train_args} |
| | | ``` |
| | | |
| | | --nnodes 表示参与的节点总数,--nproc_per_node 表示每个节点上运行的进程数 |
| | | --nnodes 表示参与的节点总数,--node_rank 表示当前节点id,--nproc_per_node 表示每个节点上运行的进程数(通常为gpu个数) |
| | | |
| | | #### 准备数据 |
| | | |
| | |
| | | ``` |
| | | 浏览器中打开:http://localhost:6006/ |
| | | |
| | | ### 训练后模型测试 |
| | | |
| | | |
| | | #### 有configuration.json |
| | | |
| | | 假定,训练模型路径为:./model_dir,如果改目录下有生成configuration.json,只需要将 [上述模型推理方法](https://github.com/alibaba-damo-academy/FunASR/blob/main/examples/README_zh.md#%E6%A8%A1%E5%9E%8B%E6%8E%A8%E7%90%86) 中模型名字修改为模型路径即可 |
| | | |
| | | 例如: |
| | | |
| | | 从shell推理 |
| | | ```shell |
| | | python -m funasr.bin.inference ++model="./model_dir" ++input=="${input}" ++output_dir="${output_dir}" |
| | | ``` |
| | | 从python推理 |
| | | |
| | | ```python |
| | | from funasr import AutoModel |
| | | |
| | | model = AutoModel(model="./model_dir") |
| | | |
| | | res = model.generate(input=wav_file) |
| | | print(res) |
| | | ``` |
| | | |
| | | #### 无configuration.json时 |
| | | |
| | | 如果模型路径中无configuration.json时,需要手动指定具体配置文件路径与模型路径 |
| | | |
| | | ```shell |
| | | python -m funasr.bin.inference \ |
| | | --config-path "${local_path}" \ |
| | | --config-name "${config}" \ |
| | | ++init_param="${init_param}" \ |
| | | ++tokenizer_conf.token_list="${tokens}" \ |
| | | ++frontend_conf.cmvn_file="${cmvn_file}" \ |
| | | ++input="${input}" \ |
| | | ++output_dir="${output_dir}" \ |
| | | ++device="${device}" |
| | | ``` |
| | | |
| | | 参数介绍 |
| | | - `config-path`:为实验中保存的 `config.yaml`,可以从实验输出目录中查找。 |
| | | - `config-name`:配置文件名,一般为 `config.yaml`,支持yaml格式与json格式,例如 `config.json` |
| | | - `init_param`:需要测试的模型参数,一般为`model.pt`,可以自己选择具体的模型文件 |
| | | - `tokenizer_conf.token_list`:词表文件路径,一般在 `config.yaml` 有指定,无需再手动指定,当 `config.yaml` 中路径不正确时,需要在此处手动指定。 |
| | | - `frontend_conf.cmvn_file`:wav提取fbank中用到的cmvn文件,一般在 `config.yaml` 有指定,无需再手动指定,当 `config.yaml` 中路径不正确时,需要在此处手动指定。 |
| | | |
| | | 其他参数同上,完整 [示例](https://github.com/alibaba-damo-academy/FunASR/blob/main/examples/industrial_data_pretraining/paraformer/infer_from_local.sh) |
| | | |
| | | |
| | | <a name="模型导出与测试"></a> |
| | | ## 模型导出与测试 |
| | |
| | | print(result) |
| | | ``` |
| | | |
| | | 更多例子请参考 [样例](runtime/python/onnxruntime) |
| | | 更多例子请参考 [样例](https://github.com/alibaba-damo-academy/FunASR/tree/main/runtime/python/onnxruntime) |