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.

 Accepted Answer

More Answers (0)

Products

Release

R2025b

Asked:

Zhi
on 30 Apr 2026 at 8:19

Answered:

Zhi
on 30 Apr 2026 at 9:05

Community Treasure Hunt

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

Start Hunting!