Skip to content

Enable ONNX SSD from https://github.com/amdegroot/ssd.pytorch#16925

Merged
opencv-pushbot merged 1 commit intoopencv:3.4from
dkurt:dnn_ssd.pytorch
Apr 13, 2020
Merged

Enable ONNX SSD from https://github.com/amdegroot/ssd.pytorch#16925
opencv-pushbot merged 1 commit intoopencv:3.4from
dkurt:dnn_ssd.pytorch

Conversation

@dkurt
Copy link
Copy Markdown
Member

@dkurt dkurt commented Mar 28, 2020

Merge with extra: opencv/opencv_extra#744

Let's merge after #16985

Convert to ONNX

To export model to ONNX, see amdegroot/ssd.pytorch#462

python3 export_to_onnx.py --model ssd300_mAP_77.43_v2.pth

Run with OpenCV

import numpy as np
import cv2 as cv

net = cv.dnn.readNet('ssd.onnx')

img = cv.imread('example.jpg')
rows, cols = img.shape[0:2]
inp = cv.dnn.blobFromImage(img, 1.0, (300, 300), mean=(123, 117, 104), swapRB=True)

net.setInput(inp)
out = net.forward()

for detection in out[0,0,:,:]:
    score = float(detection[2])
    if score > 0.7:
        xmin, ymin, xmax, ymax = [int(v) for v in detection[3:] * [cols, rows, cols, rows]]
        cv.rectangle(img, (xmin, ymin), (xmax, ymax), (23, 230, 210), thickness=2)

cv.imshow('Object detection', img)
cv.waitKey()

OpenVINO conversion flags

python3 /opt/intel/openvino/deployment_tools/model_optimizer/mo_onnx.py \
  --input_model ssd.onnx \
  --mean_values [123,117,104] \
  --reverse_input_channels \
  --input_shape [1,3,300,300]

res

force_builders=Custom,Custom Win,Custom Mac
build_image:Custom=ubuntu-openvino-2020.1.0:16.04
build_image:Custom Win=openvino-2020.1.0
build_image:Custom Mac=openvino-2020.1.0

test_modules:Custom=dnn,python2,python3,java
test_modules:Custom Win=dnn,python2,python3,java
test_modules:Custom Mac=dnn,python2,python3,java

buildworker:Custom=linux-1
# disabled due high memory usage: test_opencl:Custom=ON
test_opencl:Custom=OFF
test_bigdata:Custom=1
test_filter:Custom=*

@alalek
Copy link
Copy Markdown
Member

alalek commented Apr 13, 2020

@dkurt Please rebase code & tests branches (after #16985).

@dkurt dkurt force-pushed the dnn_ssd.pytorch branch from 22da0be to d3f9ad1 Compare April 13, 2020 12:13
@opencv-pushbot opencv-pushbot merged commit 245b2fe into opencv:3.4 Apr 13, 2020
@alalek alalek mentioned this pull request Apr 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants