Generation of C++ Code from DAGNetwork fails
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 regardsDear 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 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 deep learning, matlab coder, c++, neural network, onnx, mex MATLAB Answers — New Questions