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
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
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
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:
  1. 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
  2. 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'

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by