Error in importing YOLO ONNX model in MATLAB

56 visualizzazioni (ultimi 30 giorni)
Noy
Noy il 13 Nov 2025
Risposto: Jiangyin circa 18 ore fa
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

Risposte (2)

Taylor
Taylor il 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 Commenti
Taylor
Taylor il 20 Nov 2025 alle 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.
Noy
Noy il 3 Dic 2025 alle 7:33
I built the onnx with opset=8, opset=11, opset=12, without opset. In all of these scenarios I had the same error.
I also tried using the importONNXFunction as you suggested but got the same problem:
Warning: Unable to import some ONNX operators or attributes. They may have been replace by 'PLACEHOLDER' functions in the imported model function.
2 operator(s): Attribute 'atialis' is not supported.
Unrecognized function or variable 'PLACEHOLDER'.
Error in onnxFunc>main_graphGraph1000
[Vars.x_model_11_Resize_output_0, NumDims.x_model_11_Resize_output_0] = PLACEHOLDER(Vars.x_model_10_cv2_act_Mul_output_0, Vars.x_model_11_Constant_output_0);
...

Accedi per commentare.


Jiangyin
Jiangyin circa 18 ore fa
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.

Categorie

Scopri di più su Startup and Shutdown in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by