File size: 3,531 Bytes
3c50954 78224f0 3c50954 78224f0 3c50954 78224f0 3c50954 78224f0 3c50954 78224f0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | # wenet.axera
WeNet on Axera.
预转换好的模型在[Release](https://github.com/ml-inory/wenet.axera/releases/download/v1.0/axmodel.tar.gz) 基于AIShell数据集的100条语音量化
## 安装依赖
x86:
```bash
pip install -r requirements_x86.txt
```
开发板:
```bash
pip install -r requirements_ax.txt
```
## 导出 ONNX
```bash
python export_onnx.py \
--pretrained_model_dir pretrained/aishell_u2pp_conformer_exp \
--output_onnx_dir onnx_model
```
如果不指定参数,默认会下载并使用 `pretrained/aishell_u2pp_conformer_exp`。
输出:
```text
onnx_model/encoder_offline.onnx
onnx_model/encoder_online.onnx
onnx_model/decoder.onnx
```
## 生成量化数据集
```bash
wget https://github.com/ml-inory/whisper.axera/releases/download/v1.0/datasets.zip
unzip datasets.zip -d datasets
```
```bash
python generate_data.py \
-i datasets \
--config pretrained/aishell_u2pp_conformer_exp/train.yaml \
--vocab pretrained/aishell_u2pp_conformer_exp/units.txt \
--onnx_dir onnx_model \
--calib_data_path calibration_dataset \
--max_num 100
```
## 转 axmodel
转换:
```bash
pulsar2 build \
--input onnx_model/encoder_offline.onnx \
--config config_encoder_offline.json \
--output_dir axmodel/encoder_offline \
--output_name encoder_offline.axmodel \
--target_hardware AX650 \
--npu_mode NPU3
pulsar2 build \
--input onnx_model/encoder_online.onnx \
--config config_encoder_online.json \
--output_dir axmodel/encoder_online \
--output_name encoder_online.axmodel \
--target_hardware AX650 \
--npu_mode NPU3
pulsar2 build \
--input onnx_model/decoder.onnx \
--config config_decoder.json \
--output_dir axmodel/decoder \
--output_name decoder.axmodel \
--target_hardware AX650 \
--npu_mode NPU3
```
## 跑 ONNX
Offline CTC:
```bash
python run_ort.py \
-i demo.wav \
--config pretrained/aishell_u2pp_conformer_exp/train.yaml \
--vocab pretrained/aishell_u2pp_conformer_exp/units.txt \
--onnx_dir onnx_model \
--mode ctc_prefix_beam_search \
--calib_data_path ""
```
Online CTC:
```bash
python run_ort.py \
-i demo.wav \
--online \
--config pretrained/aishell_u2pp_conformer_exp/train.yaml \
--vocab pretrained/aishell_u2pp_conformer_exp/units.txt \
--onnx_dir onnx_model \
--mode ctc_prefix_beam_search \
--calib_data_path ""
```
Attention rescoring:
```bash
python run_ort.py \
-i demo.wav \
--config pretrained/aishell_u2pp_conformer_exp/train.yaml \
--vocab pretrained/aishell_u2pp_conformer_exp/units.txt \
--onnx_dir onnx_model \
--mode attention_rescoring \
--calib_data_path ""
```
## 跑 axmodel
在开发板仓库目录运行。
Offline CTC:
```bash
python3 run_ax.py -i demo.wav --mode ctc_prefix_beam_search --provider AxEngineExecutionProvider
```
Online CTC:
```bash
python3 run_ax.py -i demo.wav --online --mode ctc_prefix_beam_search --provider AxEngineExecutionProvider
```
Offline attention rescoring:
```bash
python3 run_ax.py -i demo.wav --mode attention_rescoring --provider AxEngineExecutionProvider
```
Online attention rescoring:
```bash
python3 run_ax.py -i demo.wav --online --mode attention_rescoring --provider AxEngineExecutionProvider
```
RTF 测试结果,`demo.wav` 时长 4.204s,repeat 5,不含模型加载:
| 模式 | 平均耗时 | RTF |
| --- | ---: | ---: |
| offline CTC | 0.5202s | 0.1237 |
| online CTC | 0.5582s | 0.1328 |
| offline attention rescoring | 0.5266s | 0.1253 |
| online attention rescoring | 0.5626s | 0.1338 |
|