revise some programming mistakes

pull/1021/head
huangyuxin 3 years ago
parent 2274a07235
commit 649fcc4c16

@ -4,22 +4,22 @@ This example contains code used to train a [Conformer](http://arxiv.org/abs/2008
## Overview ## Overview
All the scirpt you need is in the ```run.sh```. There are several stages in the ```run.sh```, and each stage has it's function. All the scirpts you need are in the ```run.sh```. There are several stages in the ```run.sh```, and each stage has its function.
| Stage | Function | | Stage | Function |
| :---- | :----------------------------------------------------------- | | :---- | :----------------------------------------------------------- |
| 0 | Process data. It includes: <br> (1) Download the dataset <br> (2) Caculate the CMVN of the train dataset <br> (3) Get the vocabulary file <br> (4) Get the manifest files of the train, development and test dataset | | 0 | Process data. It includes: <br> (1) Download the dataset <br> (2) Caculate the CMVN of the train dataset <br> (3) Get the vocabulary file <br> (4) Get the manifest files of the train, development and test dataset |
| 1 | Train the model | | 1 | Train the model |
| 2 | Get the final model by average the top-k model , set k = 1 means choose the best model | | 2 | Get the final model by averaging the top-k models, set k = 1 means choose the best model |
| 3 | Test the final model performance | | 3 | Test the final model performance |
| 4 | Get ctc alignment of test data using the final model | | 4 | Get ctc alignment of test data using the final model |
| 5 | Infer the single audio file | | 5 | Infer the single audio file |
| 51 | (Not supported at now) Transform the dynamic graph model to static graph model | | 51 | (Not supported at now) Transform the dynamic graph model to static graph model |
| 101 | (Need further installation) Train language model and Build TLG | | 101 | (Need further installation) Train language model and Build TLG |
You can choose to run a range of stages by set the ```stage``` and ```stop_stage ``` . You can choose to run a range of stages by setting the ```stage``` and ```stop_stage ``` .
For example , if you want to execute the code in stage 2 and stage 3, you can run this script: For example, if you want to execute the code in stage 2 and stage 3, you can run this script:
```bash ```bash
bash run.sh --stage 2 --stop_stage 3 bash run.sh --stage 2 --stop_stage 3
@ -33,7 +33,7 @@ bash run.sh --stage 0 --stop_stage 0
The document below will decribe the scripts in the ```run.sh``` in detail. The document below will describe the scripts in the ```run.sh``` in detail.
## The environment variables ## The environment variables
@ -41,7 +41,7 @@ The path.sh contains the environment variable.
```bash ```bash
source path.sh source path.sh
``` ```
This script needs to be run firstly. This script needs to be run firstly.
And another script is also needed: And another script is also needed:
@ -56,14 +56,14 @@ It will support the way of using```--varibale value``` in the shell scripts.
## The local variables ## The local variables
Some local variables are set in the ```run.sh```. Some local variables are set in the ```run.sh```.
```gpus``` denotes the GPU number you want to use. If you set ```gpus=```, it means you only use CPU. ```gpus``` denotes the GPU number you want to use. If you set ```gpus=```, it means you only use CPU.
```stage``` denotes the number of stage you want to start from in the expriments. ```stage``` denotes the number of stage you want to start from in the expriments.
```stop stage```denotes the number of stage you want to end at in the expriments. ```stop stage```denotes the number of stage you want to end at in the expriments.
```conf_path``` denotes the config path of the model. ```conf_path``` denotes the config path of the model.
```avg_num``` denotes the number K of top-K model you want to average to get the final model. ```avg_num``` denotes the number K of top-K models you want to average to get the final model.
```ckpt``` denotes the checkpoint prefix of the model, e.g. "conformer" ```ckpt``` denotes the checkpoint prefix of the model, e.g. "conformer"
@ -81,7 +81,7 @@ bash run.sh --gpus 0,1 --avg_num 20
## Stage 0: Data processing ## Stage 0: Data processing
To use this example, you need to process data firstly and you can use the stage 0 in the ```run.sh``` to do this. The code is shown below: To use this example, you need to process data firstly and you can use stage 0 in the ```run.sh``` to do this. The code is shown below:
```bash ```bash
if [ ${stage} -le 0 ] && [ ${stop_stage} -ge 0 ]; then if [ ${stage} -le 0 ] && [ ${stop_stage} -ge 0 ]; then
# prepare data # prepare data
@ -89,7 +89,7 @@ To use this example, you need to process data firstly and you can use the stage
fi fi
``` ```
The stage 0 is for processing the data. Stage 0 is for processing the data.
If you only want to process the data. You can run If you only want to process the data. You can run
@ -105,49 +105,53 @@ source ${MAIN_ROOT}/utils/parse_options.sh
bash ./local/data.sh bash ./local/data.sh
``` ```
Aftre processing the data, the ``data`` directory will be look like this: After processing the data, the ``data`` directory will look like this:
```bash ```bash
data/ data/
├── dev.meta |-- dev.meta
├── manifest.dev.raw |-- lang_char
├── manifest.test.raw | `-- vocab.txt
├── manifest.train.raw |-- manifest.dev
├── mean_std.json |-- manifest.dev.raw
├── test.meta |-- manifest.test
├── train.meta |-- manifest.test.raw
└── vocab.txt |-- manifest.train
|-- manifest.train.raw
|-- mean_std.json
|-- test.meta
`-- train.meta
``` ```
## Stage 1: Model training ## Stage 1: Model training
If you want to train the model. you can use the stage 1 in the ```run.sh```. The code is shown below. If you want to train the model. you can use stage 1 in the ```run.sh```. The code is shown below.
```bash ```bash
if [ ${stage} -le 1 ] && [ ${stop_stage} -ge 1 ]; then if [ ${stage} -le 1 ] && [ ${stop_stage} -ge 1 ]; then
# train model, all `ckpt` under `exp` dir # train model, all `ckpt` under `exp` dir
CUDA_VISIBLE_DEVICES=${gpus} ./local/train.sh ${conf_path} ${ckpt} CUDA_VISIBLE_DEVICES=${gpus} ./local/train.sh ${conf_path} ${ckpt}
fi fi
``` ```
If you want to train the model, you can use the script below to execute the stage 0 and stage 1: If you want to train the model, you can use the script below to execute stage 0 and stage 1:
```bash ```bash
bash run.sh --stage 0 --stop_stage 1 bash run.sh --stage 0 --stop_stage 1
``` ```
or you can run these scripts in command line (only use CPU). or you can run these scripts in the command line (only use CPU).
```bash ```bash
source path.sh source path.sh
source ${MAIN_ROOT}/utils/parse_options.sh source ${MAIN_ROOT}/utils/parse_options.sh
bash ./local/data.sh bash ./local/data.sh
CUDA_VISIBLE_DEVICES= ./local/train.sh conf/conformer.yaml conformer CUDA_VISIBLE_DEVICES= ./local/train.sh conf/conformer.yaml conformer
``` ```
## Stage 2: Top-k model averaging ## Stage 2: Top-k models averaging
After training the model, we need to get the final model for test and infer. In every epoch, the model checkpoint is saved , so we can choose the best model from them based on the validation loss or we can sort them and average the top-k model parameters to get the final model. We can use the stage 2 to do this, and the code is shown below: After training the model, we need to get the final model for testing and inference. In every epoch, the model checkpoint is saved, so we can choose the best model from them based on the validation loss or we can sort them and average the parameters of the top-k models to get the final model. We can use stage 2 to do this, and the code is shown below:
```bash ```bash
if [ ${stage} -le 2 ] && [ ${stop_stage} -ge 2 ]; then if [ ${stage} -le 2 ] && [ ${stop_stage} -ge 2 ]; then
# avg n best model # avg n best model
@ -155,13 +159,13 @@ After training the model, we need to get the final model for test and infer. In
fi fi
``` ```
The ```avg.sh``` is in the ```../../../utils/``` which is define in the ```path.sh```. The ```avg.sh``` is in the ```../../../utils/``` which is define in the ```path.sh```.
If you want to get the final model, you can use the script below to execute the stage 0, stage 1, and stage 2: If you want to get the final model, you can use the script below to execute stage 0, stage 1, and stage 2:
```bash ```bash
bash run.sh --stage 0 --stop_stage 2 bash run.sh --stage 0 --stop_stage 2
``` ```
or you can run these scripts in command line (only use CPU). or you can run these scripts in the command line (only use CPU).
```bash ```bash
source path.sh source path.sh
source ${MAIN_ROOT}/utils/parse_options.sh source ${MAIN_ROOT}/utils/parse_options.sh
@ -174,7 +178,7 @@ avg.sh best exp/conformer/checkpoints 20
## Stage 3: Model Testing ## Stage 3: Model Testing
To know the preformence of the model, test stage is needed. The code of test stage is shown below: The test stage is to evaluate the model performance.. The code of test stage is shown below:
```bash ```bash
if [ ${stage} -le 3 ] && [ ${stop_stage} -ge 3 ]; then if [ ${stage} -le 3 ] && [ ${stop_stage} -ge 3 ]; then
@ -183,13 +187,13 @@ To know the preformence of the model, test stage is needed. The code of test sta
fi fi
``` ```
If you want to train a model and test it, you can use the script below to execute the stage 0, stage 1, stage 2, and stage 3 : If you want to train a model and test it, you can use the script below to execute stage 0, stage 1, stage 2, and stage 3:
```bash ```bash
bash run.sh --stage 0 --stop_stage 3 bash run.sh --stage 0 --stop_stage 3
``` ```
or you can run these scripts in command line (only use CPU). or you can run these scripts in the command line (only use CPU).
```bash ```bash
source path.sh source path.sh
@ -213,20 +217,20 @@ If you want to get the alignment between the audio and the text, you can use the
fi fi
``` ```
If you want to train the model, test it and do the alignment, you can use the script below to execute the stage 0, stage 1, stage 2, and stage 3 : If you want to train the model, test it and do the alignment, you can use the script below to execute stage 0, stage 1, stage 2, and stage 3 :
```bash ```bash
bash run.sh --stage 0 --stop_stage 4 bash run.sh --stage 0 --stop_stage 4
``` ```
or if you only need to train a model and do the alignment, you can use these scripts to escape the stage 3(test stage): or if you only need to train a model and do the alignment, you can use these scripts to escape stage 3(test stage):
```bash ```bash
bash run.sh --stage 0 --stop_stage 2 bash run.sh --stage 0 --stop_stage 2
bash run.sh --stage 4 --stop_stage 4 bash run.sh --stage 4 --stop_stage 4
``` ```
or you can also use these scripts in command line (only use CPU). or you can also use these scripts in the command line (only use CPU).
```bash ```bash
source path.sh source path.sh
@ -243,7 +247,7 @@ CUDA_VISIBLE_DEVICES= ./local/align.sh conf/conformer.yaml exp/conformer/checkpo
## Stage 5: Single audio file inference ## Stage 5: Single audio file inference
In some situation, you want to use the trained model to do the inference for the single audio file. You can use the stage 5. The code is shown below In some situations, you want to use the trained model to do the inference for the single audio file. You can use stage 5. The code is shown below
```bash ```bash
if [ ${stage} -le 5 ] && [ ${stop_stage} -ge 5 ]; then if [ ${stage} -le 5 ] && [ ${stop_stage} -ge 5 ]; then
@ -252,14 +256,14 @@ In some situation, you want to use the trained model to do the inference for the
fi fi
``` ```
you can train the model by yourself using ```bash run.sh --stage 0 --stop_stage 3``` or you can download the pretrained model by the script below: you can train the model by yourself using ```bash run.sh --stage 0 --stop_stage 3```, or you can download the pretrained model by the script below:
``` ```
wget https://deepspeech.bj.bcebos.com/release2.1/aishell/s1/aishell.release.tar.gz wget https://deepspeech.bj.bcebos.com/release2.1/aishell/s1/aishell.release.tar.gz
tar aishell.release.tar.gz tar aishell.release.tar.gz
``` ```
You need to prepare an audio file, please confirme the sample rate of the audio is 16K. Assume the path of the audio file is ```data/test_audio.wav```, you can get the result by runing the script below. You need to prepare an audio file, please confirm the sample rate of the audio is 16K. Assume the path of the audio file is ```data/test_audio.wav```, you can get the result by running the script below.
```bash ```bash
CUDA_VISIBLE_DEVICES= ./local/test_hub.sh conf/conformer.yaml exp/conformer/checkpoints/avg_20 data/test_audio.wav CUDA_VISIBLE_DEVICES= ./local/test_hub.sh conf/conformer.yaml exp/conformer/checkpoints/avg_20 data/test_audio.wav
@ -284,7 +288,7 @@ It is not supported at now, so we set a large stage number for this stage.
## Stage: 101 Language model training and TLG building (Need further installation! ) ## Stage: 101 Language model training and TLG building (Need further installation! )
You need to install the kaldi and srilm to use the stage 101, it is used for train language model and build TLG. To do further installation, you need to do these: You need to install the kaldi and srilm to use stage 101, it is used for training language model and building TLG. To do further installation, you need to do these:
```bash ```bash
# go to the root of the repo # go to the root of the repo

Loading…
Cancel
Save