Error generating code for network net0_0. Index exceeds the number of array elements. Index must not exceed 0.

2 views (last 30 days)
Trying to generate code for trained mobilenetV2 for arm target.
But its failing with error. Could not find more description what can cause this error. Need pointers to debug.
cfg = coder.config('lib');
cfg.TargetLang = 'C++';
cfg.GenCodeOnly=true;
dlcfg = coder.DeepLearningConfig('arm-compute');
dlcfg.ArmArchitecture = 'armv7';
dlcfg.ArmComputeVersion = '19.05';
cfg.DeepLearningConfig = dlcfg;
codegen -config cfg Mobilenet_predict -args {ones(320,592,3,'single')} -report
function out = Mobilenet_predict(in)
persistent mynet;
opencv_linkflags = '`pkg-config --cflags --libs opencv`';
coder.updateBuildInfo('addLinkFlags',opencv_linkflags);
if isempty(mynet)
mynet = coder.loadDeepLearningNetwork('Mobilenet.mat','net');
end
out = predict(mynet,in);
end
  3 Comments
Manish N
Manish N on 10 Feb 2022
Edited: Manish N on 14 Feb 2022
Thanks for the response @Hariprasad Ravishankar
My starting point was mobilnetv2, but i have trained it for image size of 320,592,3
My network looks like
With the original mobilnetv2 pakage with default image size 224,224,3 codegeneration works.
I face same issue with resnet50 and resnet 18.
For Unet code generation works fine without any issue.
When i run the function for semantic segmentation it works correctly, only code generation fails.
How do you want me to share the file for debugging?
Sayan Saha
Sayan Saha on 28 Feb 2022
Hello @Manish N,
Were you able to resolve this issue? If not, can you attach the trained mobilenetv2 model in this post? You should be able to edit the question and attach the model.
If you do not feel comfortable attaching the model MATFile, please contact MathWorks technical support for furhter assistance.
Thanks,
Sayan

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 10 Feb 2022
You might need to use a %#function directive to bring in the class that predict is a method of; https://www.mathworks.com/matlabcentral/answers/568818-predict-function-doesn-t-work-in-standalone-matlab-application
mobilenetV2 appears to be an instance of the class https://www.mathworks.com/help/deeplearning/ref/dagnetwork.html
  1 Comment
Manish N
Manish N on 10 Feb 2022
Edited: Manish N on 14 Feb 2022
Thanks for the response, i added the function directive but i am still getting same error during code generation.
Predict function is working correctly when i run segmentaiton in matlab but only during code generation i am facing issues.
I am using Matlab 2021b.
@Walter Roberson is there anything else i can try?
function out = Mobilenet_predict(in)
%#function DAGNetwork
persistent mynet;
if isempty(mynet)
mynet = coder.loadDeepLearningNetwork('Mat_Mobilenet.mat','mobilenet');
end
out = predict(mynet,in);
end

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!