Error on C++ code generation: Batch size of input passed to the predict method must be a code generation time constant.
6 次查看(过去 30 天)
显示 更早的评论
During the deployment to Raspberry Pi hardware, the code generator gives error " Batch size of input passed to the predict method must be a code generation time constant". How to resolve this issue?
1 个评论
Yusheng Hao
2022-10-31
I came across the same problem when I tried to deploy ResNet-50 to my raspberry 4B accrording to the tutorial below.
The function raspi_webcam_resnet() can be correctly run in Matlab 2022b. When I tried deploy the function to my raspberry 4B, some errors occured. The report is listed below.
It seems as if the input batchsize of the ResNet-50 is not a constant, but I don't know how to correct it.
Sincerely hope someone can help. Thank you very much!
回答(2 个)
Hariprasad Ravishankar
2022-11-3
This is a limitation of imresize function returning a variable-size output. Can you try explicitly slicing a fixed size batch as follows?
imgSizeAdjusted = imresize(img, inputSize(1:2));
imSizeFixed = imgSizeAdjusted(:,:,1:3, 1);
[llabel, score] = net.classify(imgSizeFixed);
Sergio Matiz Romero
2022-10-19
移动:Walter Roberson
2022-11-3
Deep learning code generation does not support variable sized batch dimension in the input to the predict method.
For more information on variable sized data, you can check:
To know if the input passed to the predict method is variabled sized in the batch dimension you can do:
- Add the option "-report" to the codegen command, as shown in the link below: https://www.mathworks.com/help/coder/ref/codegen.html#mw_304303a0-26f3-4ea3-a76d-cb8fad6f9986
- Open the report and check the entry point function (the function containing the call to the predict method). Do you see the batch size of the input marked as variable sized in the report?
Variable sized dimensions are marked with either : or :? in the report, as shown in the link below:
To revolve this issue, you will likely have to modify your code such that the input batch size is a constant in the program. If you hover the scroll over the input to the predict method and trace it back through the program in the report, you may be able to see where it becamse varsize (this is assuming it was constant when you first passed it to the entry point function and there was some pre-processing to the input that made it varsize). Feel free to attach the report to this post. The report can be found under the codegen/html/ folder as 'report.mldatx'
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!