opencv: Reshape Layer: Assertion failed dstTotal != 0 in function 'computeShapeByReshapeMask'

System information (version)
  • OpenCV => 4.4.0
  • Operating System / Platform => Arch 64 Bit
  • Compiler => GCC 10.2.0
Detailed description

Loading the following ONNX model causes OpenCV to fail with:

cv2.error: OpenCV(4.4.0) /build/opencv/src/opencv-4.4.0/modules/dnn/src/layers/reshape_layer.cpp:149: error: (-215:Assertion failed) dstTotal != 0 in function 'computeShapeByReshapeMask'
Steps to reproduce
import cv2
net=cv2.dnn.readNetFromONNX('model.onnx') 

The model is quite big. But I’ll upload it if required.

Thanks in advance for some hints!

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 17 (7 by maintainers)

Most upvoted comments

Try using this script to set input shapes.

import onnx
import os
from onnx.tools import update_model_dims

# Preprocessing: load the old model
old_model_path = os.path.join('content', 'model.onnx')
onnx_model = onnx.load(old_model_path)

# Preprocessing: get the path to the saved model
new_model_path = os.path.join('content', 'new_model.onnx')

# Save the ONNX model
variable_length_model = update_model_dims.update_inputs_outputs_dims(onnx_model, {'input': ['batch', 3, 32, 32]}, {'out': [64, 1, 5531]})
onnx.save(onnx_model, new_model_path)

Can you step-by-step instructions? I’m a newbie, I want to load onnx model, but I have the same problem

@duongvvuet Please upload ONNX model to reproduce error

Thanks for your respone ! My ONNX model and code …

model.onnx.zip

import cv2
model = cv2.dnn.readNetFromONNX("model.onnx")

Here you go: model.onnx.txt I adapted the input layers for a smaller model size.

import cv2
net=cv2.dnn.readNetFromONNX('model.onnx.txt')