How to run NeMo VAD preprocessing separately when using ONNX inference?

#4
by nmcuong - opened

Thank you for sharing the model. I find it works quite well. However, I have a question regarding the use of ONNX:

When I want to preprocess the input for ONNX, I still have to use vad_model.preprocessor from NeMo. This forces me to load all dependencies from NeMo such as PyTorch, NeMo itself, etc. Honestly, I don’t think this should be necessary, but currently I cannot find where the preprocessing code for the model is located.

Could you please let me know if it’s possible to execute this preprocessing function separately? Below is the preprocessing code I am currently using before running inference with ONNX:

import onnx 
import onnxruntime
from nemo.core import typecheck
typecheck.set_typecheck_enabled(False)

vad_model = vad_model.cpu()

# Preprocess input signal
processed_signal, processed_signal_length = vad_model.preprocessor(
    input_signal=input_signal,
    length=input_signal_length
)

# Define input example for ONNX export
inputs = {
    "processed_signal": processed_signal,
    "processed_signal_length": processed_signal_length
}

# Load the ONNX model
session = onnxruntime.InferenceSession(
    ONNX_EXPORT_PATH, 
    providers=["CPUExecutionProvider"]
)

# Prepare input for ONNX Runtime
ort_inputs = {
    input.name: inputs[input.name].numpy()
    for input in session.get_inputs()
}

# Run inference
onnx_outputs = session.run(None, ort_inputs)[0]

Thank you.

NVIDIA org

Hi @nmcuong ,

Preprocessing code located here: https://github.com/NVIDIA-NeMo/NeMo/blob/main/nemo/collections/asr/modules/audio_preprocessing.py

You can find the preprocessing parameters inside the .nemo file by extracting (tar -xvf .nemo) it.

@nmcuong
Feel free refer to this Python script to facilitate the export of the modified ONNX NeMo-VAD model, complete with its pre-processing code.

Thank you @naymaraq and @H5N1AIDS for your answers. I really appreciate your support and guidance.

Sign up or log in to comment