Error in example slexPyTorc​hPredictEx​ample

How to fix the following error of slexPyTorchPredictExample Link?
Error due to multiple causes.
Caused by:
Error using PredictResponsesPyTorchModelPredictBlockExample (line 6)
MATLAB System block 'slexPyTorchPredictExample/PyTorch Model Predict/PyTorch Model Block' error occurred when invoking 'getOutputSizeImpl' method of 'nnet.pycoexblks.PyTorchModelBlock'. The error was thrown from '
'C:\Program Files\Matlab\R2025b\toolbox\nnet\pycoexblks\+nnet\+pycoexblks\PyTorchModelBlock.m' at line 47
'C:\Program Files\Matlab\R2025b\toolbox\shared\pycoexblks\+internal\+pycoexblks\PythonModelBlockBase.p' at line 0
'C:\Program Files\Matlab\R2025b\toolbox\shared\pycoexblks\+internal\+pycoexblks\PythonModelBlockBase.p' at line 0
'C:\Users\<username>\Documents\MATLAB\Examples\R2025b\deeplearning_shared\PredictResponsesPyTorchModelPredictBlockExample\PredictResponsesPyTorchModelPredictBlockExample.mlx' at line 6'.
Error using PredictResponsesPyTorchModelPredictBlockExample (line 6)
Unable to load specified PyTorch model file 'ptmodel.pth' in Python. The PyTorch model file must be valid, and the PyTorch model class must be on the Python path. The Python error message is: 'The Python model could not be loaded. The Python error message was: 'Python Error: ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject'.'.
Error using PredictResponsesPyTorchModelPredictBlockExample (line 6)
Error in port widths or dimensions. 'Output Port 1' of 'slexPyTorchPredictExample/PyTorch Model Predict/In1' is a one dimensional vector with 34 elements.

 채택된 답변

Zhi
Zhi 2026년 4월 30일 9:05

0 개 추천

Use torch version 2.0 it works

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

제품

릴리스

R2025b

질문:

Zhi
2026년 4월 30일 8:19

답변:

Zhi
2026년 4월 30일 9:05

Community Treasure Hunt

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

Start Hunting!

Translated by