Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

Hi all, is exporting the emotion2vec_plus models to onnx supported?
Is there a way to do this?

Thanks a lot!

You must be logged in to vote

Emotion2Vec ONNX export is available now. Support was added in #2359. I re-tested the current main (1d8080af) with the public iic/emotion2vec_plus_large checkpoint and ONNX Runtime CPU.

One current filename issue is easy to miss: the exporter writes a valid graph named emotion2vec without the .onnx suffix. Rename that file after export; no conversion is needed.

from pathlib import Path

import numpy as np
import onnx
import onnxruntime as ort
from funasr import AutoModel

output_dir = Path("./emotion2vec_onnx")
model = AutoModel(
    model="iic/emotion2vec_plus_large",
    hub="ms",
    device="cpu",
    disable_update=True,
)

export_dir = Path(
    model.export(
        type="onnx",
  …

Replies: 2 comments

Comment options

Looking for onnx as well. I made some progress but this repository deleted the related issue where I wrote the notes :(

You must be logged in to vote
0 replies
Comment options

Emotion2Vec ONNX export is available now. Support was added in #2359. I re-tested the current main (1d8080af) with the public iic/emotion2vec_plus_large checkpoint and ONNX Runtime CPU.

One current filename issue is easy to miss: the exporter writes a valid graph named emotion2vec without the .onnx suffix. Rename that file after export; no conversion is needed.

from pathlib import Path

import numpy as np
import onnx
import onnxruntime as ort
from funasr import AutoModel

output_dir = Path("./emotion2vec_onnx")
model = AutoModel(
    model="iic/emotion2vec_plus_large",
    hub="ms",
    device="cpu",
    disable_update=True,
)

export_dir = Path(
    model.export(
        type="onnx",
        quantize=False,
        device="cpu",
        output_dir=str(output_dir),
        opset_version=14,
    )
)

onnx_path = export_dir / "emotion2vec.onnx"
if not onnx_path.is_file():
    raw_path = export_dir / "emotion2vec"
    if not raw_path.is_file():
        raise FileNotFoundError(f"No Emotion2Vec ONNX graph found in {export_dir}")
    raw_path.rename(onnx_path)

graph = onnx.load(str(onnx_path), load_external_data=True)
onnx.checker.check_model(graph)

session = ort.InferenceSession(
    str(onnx_path),
    providers=["CPUExecutionProvider"],
)
waveform = np.random.randn(1, 16000).astype(np.float32)  # 16 kHz mono, [batch, samples]
features = session.run(["output"], {"input": waveform})[0]
print(features.shape)  # (1, 49, 1024)

Fresh verification results:

  • exported graph: 648,972,628 bytes, opset 14;
  • input/output names: input and output;
  • 16,000 samples -> [1, 49, 1024], maximum absolute difference from PyTorch 6.20e-6;
  • 32,000 samples -> [1, 99, 1024], maximum absolute difference 4.77e-6.

The exported interface is the dynamic-length Emotion2Vec feature extractor. Its output is frame-level 1024-dimensional features, not the final labels / scores dictionary returned by AutoModel.generate(). If you need the packaged emotion classifier and label post-processing, keep using the PyTorch AutoModel path for now.

The missing suffix is a naming bug in the current exporter, not a broken ONNX graph.

You must be logged in to vote
0 replies
Answer selected by LauraGPT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.