Generation of C++ Code from DAGNetwork fails

2 vues (au cours des 30 derniers jours)
greencactus
greencactus le 6 Juin 2022
Dear cummunity,
I try to generate C/C++ code from an DAGNetwork, which is generated imported from an ONNX model. When I try to run this model in MATLAB itself, no errrors occour. The model is saved as *.mat file. Loading and running the model again is working well.
If I want to generate C/C++ code from the model via the following code (in two separate files gencode.m and myNet_predict.m), I get the error message: ??? Layer hyper-parameters for custom layer 'PadLayer1183' must be numeric scalar, scalar logical, character or string array, or a matrix of type double or single.
% codegen.m
cfg = coder.config('mex');
cfg.TargetLang = 'C++';
cfg.DeepLearningConfig = coder.DeepLearningConfig('mkldnn');
args = {zeros(1024,1024,3,'single')};
codegen -config cfg -args args myNet_predict -report
% myNet_predict.m
function out = myNet_predict(img)
persistent mynet;
if isempty(mynet)
mynet = coder.loadDeepLearningNetwork('DeepLabV3plus.mat');
end
pred = predict(mynet, img);
end
Unfortunately the *.mat files of the neural network and PadLayer1183 are to big for uploading here, I uploaded them under https://cloudstore.zih.tu-dresden.de/index.php/s/ajSCte9G9HN2pqP for save downloading. These are all files which are neccessary to reproduce the discribed behaviour.
I tried to debug the code so far, but I do not got an idea why this error occours. As I followed the compilation process, the error appears only when the prediction is called.
The input is every time an image with the dimension 1024x1024x3. I know its very big, but thats a requirement of the neural network. I guess that the problem is the attribute ONNXParams from the type ONNXParameters. Because it would be a very huge workaround to replace this variable with single parameters, I do not think that MATLAB would handle code generations in this way.
Hopefully anyone can help me to figure out whats wrong in the model code or my code.
Thanks in advance.
Best regards

Réponse acceptée

Sivylla Paraskevopoulou
Sivylla Paraskevopoulou le 6 Juin 2022
I am assuming that you using the importONNXNetwork function to import the ONNX model, and importONNXNetwork automatically generates custom layers. You can see the automatically generated custom layers in the created package in your current folder. Automatically generated custom layers do not support code generation.
To deploy the imported network, you must replace the autogenerated custom layer with built-in MATLAB layer(s). For more information, see Generate Code for Imported Network. Check also the functionLayer documentation. The functionLayer also supports code generation with some limitations (see, Code Generation for functionLayer).

Plus de réponses (0)

Catégories

En savoir plus sur Deep Learning Code Generation Fundamentals dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by