Unable to import an ONNX network in complied application / issues loading DAG networks from MAT files / cannot include support package in compiled application

18 views (last 30 days)
Ryan Monroe
Ryan Monroe on 17 Apr 2021
Edited: Mirko Prezioso on 2 Aug 2022 at 20:34
I'm having an issue with a deployed application and a DAG/ONNX network:
  • The network was originally trained in pytorch and written to an ONNX file.
  • I subsequently produced a .mat file with the following routine <updateCnnMat>
  • I then run <testCnn> in both deployed mode and in a native environment: it runs successfully in the latter and fails in the former.
  • Variable names and file names have been changed for this copy because of IP reasons
  • I checked <mccExcludedFiles.log>, which does not indicate that anything important is being excluded
  • I confirmed that the file is being included in my path
  • I do not get the support package section in the compiler window as suggested by https://www.mathworks.com/help/compiler/manage-support-packages.html
  • Note that I'm using R2020a - changing this could be a little painful, but I could do it if really needed.
Any ideas? I feel like I've turned over every stone at this point.
$ cat mccExcludedFiles.log
The List of Excluded Files
Excluded files Exclusion Message ID Reason For Exclusion Exclusion Rule
function updateCnnMat(in,out)
model =importONNXNetwork(in,'outputlayertype','regression');
Log output:
DAGNetwork with no properties.
mat fail!
MException with properties:
identifier: 'MATLAB:structRefFromNonStruct'
message: 'Dot indexing is not supported for variables of this type.'
cause: {}
stack: [4x1 struct]
Correction: []
coder fail!
MException with properties:
identifier: 'MATLAB:undefinedVarOrClass'
message: 'Unable to resolve the name coder.internal.loadDeepLearningNetwork.'
cause: {}
stack: [3x1 struct]
Correction: []
onnx fail!
MException with properties:
identifier: 'nnet_cnn:supportpackages:InstallRequired'
message: 'importONNXNetwork requires the Deep Learning Toolbox Converter for ONNX Model Format support package. To install this support package, use the <a href="matlab: matlab.addons.supportpackage.internal.explorer.showSupportPackages('ONNXCONVERTER', 'tripwire')">Add-On Explorer</a>.'
cause: {}
stack: [4x1 struct]
Correction: []
function testCnn(din)
% modelDir is already specified
load cnn.mat model
disp('if you got here, you were able to read the mat file...')
load cnn.mat model
dout = predict(model, din);
disp('mat win!')
catch e
disp('mat fail!')
% model=model0.model;
modelCoder=coder.loadDeepLearningNetwork(fullfile(modelDir, 'cnn.mat'));
dout = predict(modelCoder, din);
disp('coder win!')
catch e
disp('coder fail!')
modelOnnx=importONNXNetwork(fullfile(modelDir, 'cnn.onnx'),'outputlayertype','regression');
dout = predict(modelOnnx, din);
disp('onnx win!')
catch e
disp('onnx fail!')

Answers (1)

Pierre Harouimi
Pierre Harouimi on 19 May 2021
Could you share the ONNX file, so that I can reproduce it?
It seems there is a dynamic licensing issue...
Mirko Prezioso
Mirko Prezioso on 2 Aug 2022 at 20:30
Hi Pierre, I am having the same problem. Could you simplify your workaround in English? :)
What does overload means, and how I can add the overloaded functions after?

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by