Error on C++ code generation: Batch size of input passed to the predict method must be a code generation time constant.
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Yusheng Hao
el 31 de Oct. de 2022
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!
Respuestas (2)
Hariprasad Ravishankar
el 3 de Nov. de 2022
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);
1 comentario
Sergio Matiz Romero
el 19 de Oct. de 2022
Movida: Walter Roberson
el 3 de Nov. de 2022
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 comentarios
Ver también
Categorías
Más información sobre CPU Code Generation from MATLAB Applications en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!