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

9 views (last 30 days)
Ryan Monroe
Ryan Monroe on 17 Apr 2021
Commented: Pierre Harouimi on 13 Jan 2022
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');
save(out,'model','-v7.3');
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...')
try
load cnn.mat model
dout = predict(model, din);
disp('mat win!')
catch e
disp('mat fail!')
disp(e)
end
% model=model0.model;
try
modelCoder=coder.loadDeepLearningNetwork(fullfile(modelDir, 'cnn.mat'));
dout = predict(modelCoder, din);
disp('coder win!')
catch e
disp('coder fail!')
disp(e)
end
try
modelOnnx=importONNXNetwork(fullfile(modelDir, 'cnn.onnx'),'outputlayertype','regression');
dout = predict(modelOnnx, din);
disp('onnx win!')
catch e
disp('onnx fail!')
disp(e)
end

Answers (1)

Pierre Harouimi
Pierre Harouimi on 19 May 2021
Hi
Could you share the ONNX file, so that I can reproduce it?
It seems there is a dynamic licensing issue...
  5 Comments
Pierre Harouimi
Pierre Harouimi on 13 Jan 2022
There is a “workaround”: you have to overload the DL objects (SeriesNetwork & DAGNetwork) and add it to your compiled function 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