-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
readNetFromONNX error slice/index operations #14672
Copy link
Copy link
Closed
Labels
Milestone
Description
System information (version)
- OpenCV => 4.1.0
- python 3.7.3
- Operating System / Platform => Ubuntu 64 Bit
- PyTorch => 1.1.0
- onnx => 1.5.0
- conda => 4.6.14
Detailed description
I'm trying to export a model from PyTorch to ONNX to be run in OpenCV, but am getting an error when running cv2.dnn.readNetFromONNX. I've isolated the cause of the error to slicing a tensor. As an example, I've attached a file that attempts to follow these steps for a simple model. The model slices the last dimension of the input and returns.
Script:
import torch
import torch.nn as nn
import onnx
import cv2
class Net(nn.Module):
def __init__(self):
super(Net, self).__init__()
def forward(self, x):
return x[...,2:5]
dummy = torch.rand((4,3,10,10))
net = Net()
torch.onnx.export(net, dummy, 'test.onnx', verbose=True)
model_cv2 = cv2.dnn.readNetFromONNX('test.onnx')
I get the following error:
cv2.error: OpenCV(4.1.0) /io/opencv/modules/dnn/src/layers/slice_layer.cpp:147: error: (-215:Assertion failed) requiredOutputs > 0 && inpShape[axis] % requiredOutputs == 0 in function 'getMemoryShapes'
The ONNX graph:
graph(%0 : Float(4, 3, 10, 10)):
%1 : Float(4, 3, 10!, 3) = onnx::Slice[axes=[3], ends=[5], starts=[2]](%0), scope: Net
return (%1)
Steps to reproduce
I've attached a python script to reproduce.
I've also attached the ONNX model.
files.zip
Reactions are currently unavailable