File Exchange

image thumbnail

Deep Learning Toolbox Converter for ONNX Model Format

Import and export ONNX™ models within MATLAB for interoperability with other deep learning frameworks

39 Downloads

Updated 12 Dec 2018

Import and export ONNX™ (Open Neural Network Exchange) models within MATLAB for interoperability with other deep learning frameworks. ONNX enables models to be trained in one framework and transferred to another for inference.

Opening the onnxconverter.mlpkginstall file from your operating system or from within MATLAB will initiate the installation process for the release you have.
This mlpkginstall file is functional for R2018a and beyond.

Usage example:
%% Export to ONNX model format
net = squeezenet; % Pretrained Model to be exported
filename = 'squeezenet.onnx';
exportONNXNetwork(net,filename);

%% Import the network that was exported
net2 = importONNXNetwork('squeezenet.onnx', 'OutputLayerType', 'classification');

% Compare the predictions of the two networks on a random input image
img = rand(net.Layers(1).InputSize);
y = predict(net, img);
y2 = predict(net2,img);

max(abs(y-y2))

For more details, please visit the documentation at https://www.mathworks.com/help/nnet/ref/exportonnxnetwork.html

Comments and Ratings (6)

Kenneth Post

exportONNXNetwork does not work properly using CNTK and Python. The conversion produces a ValueError: Gemm: Invalid shape, input A and B are expected to be rank=2 matrices.

Hui Yin Lee

Hi, Is the code or toolbox available for Faster R-CNN model to be exported? As i get the error mentioning the model is not DAGnetwork. Hopefully can get some feedback or help here

Do you guys know when support for the constant operator will get added?

Error using importONNXNetwork (line 39)
Node 'node_20': Constant operator is not supported yet.

umit kacar

I worked this code:) It is very good. Thank you.

Ting Su

Hi Trihn,
We would like to hear more details on the problem of importONNXNetwork(). Have you installed an old version of this converter before?

Trinh Pham

The function importONNXNetwork() doesn't work when I use example above!

MATLAB Release Compatibility
Created with R2018a
Compatible with R2018a to R2019a
Platform Compatibility
Windows macOS Linux

Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.


Learn About Live Editor