-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add doc for using WeNet CTC models with sherpa-onnx (#507)
- Loading branch information
1 parent
a34c2c8
commit 1c4fe27
Showing
10 changed files
with
155 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
All models from WeNet | ||
===================== | ||
|
||
`<https://github.com/wenet-e2e/wenet/blob/main/docs/pretrained_models.en.md>`_ | ||
lists all pre-trained models from `WeNet`_ and we have converted all of them | ||
to `sherpa-onnx`_ using the following script: | ||
|
||
`<https://github.com/k2-fsa/sherpa-onnx/blob/master/scripts/wenet/run.sh>`_. | ||
|
||
We have uploaded the exported models to huggingface and you can find them from | ||
the following figure: | ||
|
||
.. figure:: ./pic/wenet-models-onnx-list.jpg | ||
:alt: All pretrained models from `WeNet` | ||
:width: 600 | ||
|
||
All pre-trained models from `WeNet`_. | ||
|
||
To make it easier to copy the links, we list them below: | ||
|
||
- `<https://huggingface.co/csukuangfj/sherpa-onnx-zh-wenet-aishell>`_ | ||
- `<https://huggingface.co/csukuangfj/sherpa-onnx-zh-wenet-aishell2>`_ | ||
- `<https://huggingface.co/csukuangfj/sherpa-onnx-en-wenet-gigaspeech>`_ | ||
- `<https://huggingface.co/csukuangfj/sherpa-onnx-en-wenet-librispeech>`_ | ||
- `<https://huggingface.co/csukuangfj/sherpa-onnx-zh-wenet-multi-cn>`_ | ||
- `<https://huggingface.co/csukuangfj/sherpa-onnx-zh-wenet-wenetspeech>`_ | ||
|
||
Colab | ||
----- | ||
|
||
We provide a colab notebook | ||
|Sherpa-onnx wenet ctc colab notebook| | ||
for you to try the exported `WeNet`_ models with `sherpa-onnx`_. | ||
|
||
.. |Sherpa-onnx wenet ctc colab notebook| image:: https://colab.research.google.com/assets/colab-badge.svg | ||
:target: https://github.com/k2-fsa/colab/blob/master/sherpa-onnx/sherpa_onnx_with_models_from_wenet.ipynb |
99 changes: 99 additions & 0 deletions
99
docs/source/onnx/pretrained_models/wenet/how-to-export.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
How to export models from WeNet to sherpa-onnx | ||
============================================== | ||
|
||
Suppose you have the following files from `WeNet`_: | ||
|
||
- ``final.pt`` | ||
- ``train.yaml`` | ||
- ``global_cmvn`` | ||
- ``units.txt`` | ||
|
||
We describe below how to use scripts from `sherpa-onnx`_ to export your files. | ||
|
||
.. hint:: | ||
|
||
Both streaming and non-streaming models are supported. | ||
|
||
Export for non-streaming inference | ||
---------------------------------- | ||
|
||
You can use the following script | ||
|
||
`<https://github.com/k2-fsa/sherpa-onnx/blob/master/scripts/wenet/export-onnx.py>`_ | ||
|
||
to export your model to `sherpa-onnx`_. After running it, you should get two files: | ||
|
||
- ``model.onnx`` | ||
- ``model.int8.onnx``. | ||
|
||
Next, we rename ``units.txt`` to ``tokens.txt`` to follow the convention used in `sherpa-onnx`_: | ||
|
||
.. code-block:: bash | ||
mv units.txt tokens.txt | ||
Now you can use the following command for speech recognition with the exported models: | ||
|
||
.. code-block:: bash | ||
# with float32 models | ||
./build/bin/sherpa-onnx-offline \ | ||
--wenet-ctc-model=./model.onnx | ||
--tokens=./tokens.txt \ | ||
/path/to/some.wav | ||
# with int8 models | ||
./build/bin/sherpa-onnx-offline \ | ||
--wenet-ctc-model=./model.int8.onnx | ||
--tokens=./tokens.txt \ | ||
/path/to/some.wav | ||
Export for streaming inference | ||
------------------------------ | ||
|
||
You can use the following script | ||
|
||
`<https://github.com/k2-fsa/sherpa-onnx/blob/master/scripts/wenet/export-onnx-streaming.py>`_ | ||
|
||
to export your model to `sherpa-onnx`_. After running it, you should get two files: | ||
|
||
- ``model-streaming.onnx`` | ||
- ``model-streaming.int8.onnx``. | ||
|
||
Next, we rename ``units.txt`` to ``tokens.txt`` to follow the convention used in `sherpa-onnx`_: | ||
|
||
.. code-block:: bash | ||
mv units.txt tokens.txt | ||
Now you can use the following command for speech recognition with the exported models: | ||
|
||
.. code-block:: bash | ||
# with float32 models | ||
./build/bin/sherpa-onnx \ | ||
--wenet-ctc-model=./model-streaming.onnx | ||
--tokens=./tokens.txt \ | ||
/path/to/some.wav | ||
# with int8 models | ||
./build/bin/sherpa-onnx \ | ||
--wenet-ctc-model=./model-streaming.int8.onnx | ||
--tokens=./tokens.txt \ | ||
/path/to/some.wav | ||
FAQs | ||
---- | ||
|
||
sherpa-onnx/csrc/online-wenet-ctc-model.cc:Init:144 head does not exist in the metadata | ||
--------------------------------------------------------------------------------------- | ||
|
||
.. code-block:: | ||
/Users/fangjun/open-source/sherpa-onnx/sherpa-onnx/csrc/online-wenet-ctc-model.cc:Init:144 head does not exist in the metadata | ||
To fix the above error, please check the following two items: | ||
|
||
- Make sure you are using ``model-streaming.onnx`` or ``model-streaing.int8.onnx``. The executable | ||
you are running requires a streaming model as input. | ||
- Make sure you use the script from `sherpa-onnx`_ to export your model. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
WeNet | ||
===== | ||
|
||
This page lists all CTC models from `WeNet`_. | ||
|
||
|
||
.. toctree:: | ||
:maxdepth: 5 | ||
|
||
how-to-export | ||
all-models | ||
|
Binary file added
BIN
+389 KB
docs/source/onnx/pretrained_models/wenet/pic/wenet-models-onnx-list.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters