# Unable to import ONNX model

**URL:** https://forum.opencv.org/t/unable-to-import-onnx-model/3730
**Category:** Python
**Tags:** dnn, onnx
**Created:** [June 7, 2021, 3:46pm UTC](https://forum.opencv.org/t/unable-to-import-onnx-model/3730 "2021-06-07T15:46:44Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Matt\_Nelson](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/matt_nelson/32/2335_2.png) [@Matt\_Nelson](https://forum.opencv.org/u/Matt_Nelson)
#### Post date: [June 7, 2021, 3:46pm UTC](https://forum.opencv.org/t/unable-to-import-onnx-model/3730/1 "2021-06-07T15:46:45Z")

</div>

I am trying to use an adult content detection ONNX model. This model was originally converted from a tensorflow model by the author. When importing the model using the following I get an error message. Here is the line throwing the error:

```auto
net = cv2.dnn.readNetFromONNX("/home/matt/.NudeNet/detector_v2_default_checkpoint.onnx")

```

Error Message:

```auto
[ERROR:0] global /tmp/pip-req-build-dzetuct2/opencv/modules/dnn/src/onnx/onnx_importer.cpp (2108) handleNode DNN/ONNX: ERROR during processing node with 1 inputs and 4 outputs: [Split]:(clipped_boxes/unstack:0)
Traceback (most recent call last):
  File "cv.py", line 5, in <module>
    net = cv2.dnn.readNetFromONNX("/home/matt/.NudeNet/detector_v2_default_checkpoint.onnx")                                                                                     
cv2.error: OpenCV(4.5.2) /tmp/pip-req-build-dzetuct2/opencv/modules/dnn/src/onnx/onnx_importer.cpp:2129: error: (-2:Unspecified error) in function 'handleNode'                  
> Node [Split]:(clipped_boxes/unstack:0) parse error: OpenCV(4.5.2) /tmp/pip-req-build-dzetuct2/opencv/modules/dnn/src/layers/slice_layer.cpp:164: error: (-215:Assertion failed)
inputs.size() == 1 in function 'getMemoryShapes'

```

The model can be found here: [https://github.com/notAI-tech/NudeNet/releases/download/v0/detector\_v2\_default\_checkpoint.onnx](https://github.com/notAI-tech/NudeNet/releases/download/v0/detector_v2_default_checkpoint.onnx)

I’m running version 4.5.2 of OpenCV.

Steps to Reproduce:

1. Download the model above.
2. Run the following code:

```auto
import numpy as np
import cv2

net = cv2.dnn.readNetFromONNX("/home/matt/.NudeNet/detector_v2_default_checkpoint.onnx")

```

I’ve spent the day trying toi debug this and have read through lots of github issues anf foruym posts but can’t find out how I can go about fixing this.

I have checked the model itself and the order of the nodes seems OK as I’ve run it through this checker:

```auto
import onnx
onnx_model = onnx.load('/home/matt/.NudeNet/detector_v2_default_checkpoint.onnx')

# Check the model
try:
    onnx.checker.check_model(onnx_model)
except onnx.checker.ValidationError as e:
    print('The model is invalid: %s' % e)
else:
    print('The model is valid!')

```

I can also confirm the model actually works using the onnxruntime:

```auto
from detector_utils import preprocess_image
import numpy as np
import onnxruntime as rt

image, scale = preprocess_image('./boobs.jpeg')
sample = np.expand_dims(image, axis=0)

onnx_path = '/home/matt/.NudeNet/detector_v2_default_checkpoint.onnx'
sess = rt.InferenceSession(onnx_path)
x_name = sess.get_inputs()[0].name
y1_name = sess.get_outputs()[0].name
y2_name = sess.get_outputs()[1].name
y3_name = sess.get_outputs()[2].name
outPred = sess.run([y1_name, y2_name, y3_name], {x_name: sample})

print(outPred)

```

Any help would be appreciated!

---

<div class="post-metadata">

### Author: ![Thien\_Pham](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/thien_pham/32/3236_2.png) [@Thien\_Pham](https://forum.opencv.org/u/Thien_Pham)
#### Post date: [September 20, 2021, 3:20am UTC](https://forum.opencv.org/t/unable-to-import-onnx-model/3730/2 "2021-09-20T03:20:52Z")

</div>

I also got the same issue.

---

<div class="post-metadata">

### Author: ![xamapl99](https://avatars.discourse-cdn.com/v4/letter/x/4da419/32.png) [@xamapl99](https://forum.opencv.org/u/xamapl99)
#### Post date: [November 24, 2021, 11:54am UTC](https://forum.opencv.org/t/unable-to-import-onnx-model/3730/3 "2021-11-24T11:54:51Z")

</div>

Hi, I’m having the same issue. You could solved?

---

<div class="post-metadata">

### Author: ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)
#### Post date: [November 24, 2021, 12:19pm UTC](https://forum.opencv.org/t/unable-to-import-onnx-model/3730/4 "2021-11-24T12:19:46Z")

</div>

try with 4,5.4 (or master), it should be fixed

---

<div class="post-metadata">

### Author: ![xamapl99](https://avatars.discourse-cdn.com/v4/letter/x/4da419/32.png) [@xamapl99](https://forum.opencv.org/u/xamapl99)
#### Post date: [November 25, 2021, 8:09am UTC](https://forum.opencv.org/t/unable-to-import-onnx-model/3730/5 "2021-11-25T08:09:50Z")

</div>

I’m still with the problem. Now i have this:

error: OpenCV(4.5.4) /tmp/pip-req-build-24v3eisa/opencv/modules/dnn/src/onnx/onnx\_importer.cpp:739: error: (-2:Unspecified error) in function ‘handleNode’

> Node [Equal]:(80) parse error: OpenCV(4.5.4) /tmp/pip-req-build-24v3eisa/opencv/modules/dnn/src/dnn.cpp:615: error: (-2:Unspecified error) Can’t create layer “80” of type “Equal” in function ‘getLayerInstance’

---

<div class="post-metadata">

### Author: ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)
#### Post date: [November 25, 2021, 8:20am UTC](https://forum.opencv.org/t/unable-to-import-onnx-model/3730/6 "2021-11-25T08:20:23Z")

</div>

maybe you can add [a custom “Equal” layer](https://docs.opencv.org/4.x/dc/db1/tutorial_dnn_custom_layers.html)

---

<div class="post-metadata">

### Author: ![Shahrzad\_Mostafaei](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/shahrzad_mostafaei/32/10981_2.png) [@Shahrzad\_Mostafaei](https://forum.opencv.org/u/Shahrzad_Mostafaei)
#### Post date: [August 21, 2024, 11:11am UTC](https://forum.opencv.org/t/unable-to-import-onnx-model/3730/7 "2024-08-21T11:11:14Z")

</div>

Did you find the solution?
