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.

 Akzeptierte Antwort

Zhi
Zhi am 30 Apr. 2026 um 9:05

0 Stimmen

Use torch version 2.0 it works

Weitere Antworten (0)

Kategorien

Produkte

Version

R2025b

Gefragt:

Zhi
am 30 Apr. 2026 um 8:19

Beantwortet:

Zhi
am 30 Apr. 2026 um 9:05

Community Treasure Hunt

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

Start Hunting!

Translated by