Error in importing YOLO ONNX model in MATLAB
11 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Taylor
on 13 Nov 2025 at 20:30
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.
See Also
Categories
Find more on Image Data Workflows in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!