Skip to main content

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

  1. espnet_onnx can be installed with pip
pip install espnet_onnx
  1. If you want to export pretrained model, you need to install torch>=1.11.0, espnet, espnet_model_zoo additionally.

Usage

  1. espnet_onnx can export pretrained model published on espnet_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)
  1. For inference, tag_name or model_dir is used to load onnx file. tag_name has to be defined in tag_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_name defined in table.csv in espnet_model_zoo. If a user set a custom model_name when export model with export(), then tag_name should be model_name. The tag_name should be defined in tag_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

  • export
    • model: Instance of espnet2.bin.asr_inference.Speech2Text.
    • tag_name: Tag name to identify onnx model.
    • quantize: Flag to create quantized model.
  • export_from_pretrained
    • tag_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.

  1. Add <blank> before <sos>
  2. Give some torch.zeros() arrays to the model.
  3. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

espnet_onnx-0.1.3.tar.gz (52.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

espnet_onnx-0.1.3-py3-none-any.whl (72.2 kB view details)

Uploaded Python 3

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

Hashes for espnet_onnx-0.1.3.tar.gz
Algorithm Hash digest
SHA256 594fb19910cc227e22bfaa7b5fd59d1fdf526e9ab6f6c14a22a5c7376d20788e
MD5 784b589379cd7981f1671fee6b9488c6
BLAKE2b-256 d46917f737b1a09dbcbe0fb09f1b52ef7a0ca7e6e5f64f457716c6853190821e

See more details on using hashes here.

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

Hashes for espnet_onnx-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 03e45dad2074743b739650bdc89ddc2f4e876b20e5c3a14d3052542e664bc536
MD5 4a330a633fc7b98407cf2eb717a09b92
BLAKE2b-256 67330a4ee22bf47bac80e04069d57b0a5c5623cbf4df634e4abf26decced51bb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page