Error in importing YOLO ONNX model in MATLAB
56 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I tried to import an YOLO ONNX model to MATLAB (I have the DeepLearning Toolbox installed), but got an error.
I created my ONNX model using the following python code:
from ultralytics import YOLO
YOLO("yolo_model.pt").export(
format="onnx", opset=12, simplify=True, dynamic=False, nms=False)
(I tried also with dynamic=True and without specifying opset arg but got same results)
On MATLAB I used this code to import the model:
modelPath = 'yolo_model.onnx';
net = importNetworkFromONNX(modelPath);
dummyInput = dlarray(rand(1, 3, 256, 256), 'BCSS');
net = initialize(net, dummyInput);
out = predict(net, dummyInput);
and got the following:
Warning:
Unable to import some ONNX operators, because they are not supported.
They have been replaced by placholder layers or by placeholder functions inside generated custom layers. To find the
placeholder layers, call the function findPlaceholderLayers on the returned object.
2 operator(s) : Attribute 'atialias' is not supported.
To import the ONNX network as a function, use importONNXFunction.
> In nnet.internal.cnn.onnx.importONNXNetwork>iWarnIfContainsPlaceholders (line 163)
In nnet.internal.cnn.onnx.importONNXNetwork>iHandleTranslationIssues (line 104)
In nnet.internal.cnn.onnx.importONNXNetwork (line 57)
In importNetworkFromONNX (line 77)
In LoadONNX (line 6)
Warning: Returning an uninitialized dlnetwork. Initialize the network by passing example input data to the initialized object function.
> In nnet.internal.cnn.onnx.importONNXNetwork>constructDlnetwork (line 93)
In nnet.internal.cnn.onnx.importONNXNetwork (line 62)
In nnet.internal.cnn.onnx.importNetworkFromONNX (line 13)
In importNetworkFromONNX (line 77)
In LoadONNX (line 6)
Error using dlnetwork/initialize (line 600)
Invalid network.
Error in LoadONNX (line 10)
net = initialize(net, dummyInput);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Caused by:
Layer 'Reshape_To_ReshapeLayer1072': Error using the predict function in layer yolo_model.Reshape_To_ReshapeLayer1072. The function threw an error and could not be executed.
Error using reshape
Number of elements must not change. Use [] as one of the size inputs to automatically calculate the appropriate size for that dimension.
Error in dlarray/reshape (line 40)
objdata = reshape(objdata, varargin{:});
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in yolo_model.Reshape_To_ReshapeLayer1072>Reshape_To_ReshapeGraph1066 (line 204)
Vars.x_model_10_m_m_0__9 = reshape(Vars.x_model_10_m_m_0__19, shape{:});
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in yolo_model.Reshape_To_ReshapeLayer1072>Reshape_To_ReshapeFcn (line 190)
[x_model_10_m_m_0__11, x_model_10_m_m_0__12, x_model_10_m_m_0__8, x_model_10_m_m_0__13, x_model_10_m_m_0__11NumDims, x_model_10_m_m_0__12NumDims, x_model_10_m_m_0__8NumDims,
x_model_10_m_m_0__13NumDims, state] = Reshape_To_ReshapeGraph1066(x_model_10_m_m_0__18, NumDims.x_model_10_m_m_0__18, Vars, NumDims, Training, params.State);
Error in yolo_model.Reshape_To_ReshapeLayer1072/predict (line 34)
[x_model_10_m_m_0__11, x_model_10_m_m_0__12, x_model_10_m_m_0__8, x_model_10_m_m_0__13, x_model_10_m_m_0__11NumDims, x_model_10_m_m_0__12NumDims,
x_model_10_m_m_0__8NumDims, x_model_10_m_m_0__13NumDims] = Reshape_To_ReshapeFcn(x_model_10_m_m_0__18, x_model_10_m_m_0__18NumDims, onnxParams, 'Training', false, ...
Please help
0 commentaires
Réponses (2)
Taylor
le 13 Nov 2025
There is a YOLOX object detector built into the Deep Learning Toolbox, and a YOLO v4 object detector built into the Computer Vision Toolbox if you have that as well.
4 commentaires
Taylor
le 20 Nov 2025 à 15:52
Did you trying using importONNXFunction instead? You could also trying using opset=11 since 12 introduced the antialias attribute which is what is being called out in the error message.
Jiangyin
il y a environ 6 heures
Hi Noy,
I tried to create a ONNX model with the python script you shared, it's giving me an error message:
"No such file or directory: 'yolo_model.pt'"
I'm using ultralytics version 8.3.240.
Based on the error message, I think we could provide further help with more information, for example the exact onnx model you exported.
Could you contact our tech support: https://www.mathworks.com/help/matlab/matlab_env/contact-technical-support.html, and we could provide further help from there.
0 commentaires
Voir également
Catégories
En savoir plus sur Startup and Shutdown dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!