ONNX Wrapper for ESPnet
Project description
espnet_onnx
ESPNet without PyTorch!
Utility library to easily export espnet models to onnx format. There is no need to install PyTorch or ESPNet on your machine if you already have exported files!
Note
Currently TTS is not supported.
Install
espnet_onnxcan be installed with pip
pip install espnet_onnx
- If you want to export pretrained model, you need to install
torch>=1.11.0,espnet,espnet_model_zooadditionally.
Usage
-
espnet_onnxcan export pretrained model published onespnet_model_zoo.By default, exported files will be stored in
${HOME}/.cache/espnet_onnx/<tag_name>.
from espnet2.bin.asr_inference import Speech2Text
from espnet_onnx.export import ModelExport
m = ModelExport()
# download with espnet_model_zoo and export from pretrained model
m.export_from_pretrained('<tag name>', quantize=True)
# export from trained model
speech2text = Speech2Text(args)
m.export(speech2text, '<tag name>', quantize=True)
- For inference,
tag_nameormodel_diris used to load onnx file.tag_namehas to be defined intag_config.yaml
import librosa
from espnet_onnx import Speech2Text
speech2text = Speech2Text(tag_name='<tag name>')
# speech2text = Speech2Text(model_dir='path to the onnx directory')
y, sr = librosa.load('sample.wav', sr=16000)
nbest = speech2text(y)
API Reference
espnet_onnx.Speech2Text
args
-
tag_name:tag_namedefined intable.csvinespnet_model_zoo. If a user set a custommodel_namewhen export model withexport(), thentag_nameshould bemodel_name. Thetag_nameshould be defined intag_config.yaml, which will be created when exporting model. -
model_dir: Path to the model directory. Configuration file should be located in<model_dir>/config.yaml -
use_quantized: Flag to use quantized model.
espnet_onnx.export.ModelExport
function
exportmodel: Instance ofespnet2.bin.asr_inference.Speech2Text.tag_name: Tag name to identify onnx model.quantize: Flag to create quantized model.
export_from_pretrainedtag_name: Tag name to identify onnx model.quantize: Flag to create quantized model.
Changes from ESPNet
To avoid the cache problem, I modified some scripts from the original espnet implementation.
- Add
<blank>before<sos> - Give some
torch.zeros()arrays to the model. - Remove the first token in post process. (remove
blank)
And I removed extend_pe() from positional encoding module. The length of pe is 512 by default.
Supported Archs
ASR: Supported architecture for ASR
References
COPYRIGHT
Copyright (c) 2022 Maso Someki
Released under MIT licence
Author
Masao Someki
contact: masao.someki@gmail.com
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file espnet_onnx-0.1.3.tar.gz.
File metadata
- Download URL: espnet_onnx-0.1.3.tar.gz
- Upload date:
- Size: 52.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
594fb19910cc227e22bfaa7b5fd59d1fdf526e9ab6f6c14a22a5c7376d20788e
|
|
| MD5 |
784b589379cd7981f1671fee6b9488c6
|
|
| BLAKE2b-256 |
d46917f737b1a09dbcbe0fb09f1b52ef7a0ca7e6e5f64f457716c6853190821e
|
File details
Details for the file espnet_onnx-0.1.3-py3-none-any.whl.
File metadata
- Download URL: espnet_onnx-0.1.3-py3-none-any.whl
- Upload date:
- Size: 72.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
03e45dad2074743b739650bdc89ddc2f4e876b20e5c3a14d3052542e664bc536
|
|
| MD5 |
4a330a633fc7b98407cf2eb717a09b92
|
|
| BLAKE2b-256 |
67330a4ee22bf47bac80e04069d57b0a5c5623cbf4df634e4abf26decced51bb
|