Skip to content

EfficientDet text graph generator#17384

Merged
opencv-pushbot merged 1 commit intoopencv:3.4from
dkurt:efficientdet
May 28, 2020
Merged

EfficientDet text graph generator#17384
opencv-pushbot merged 1 commit intoopencv:3.4from
dkurt:efficientdet

Conversation

@dkurt
Copy link
Copy Markdown
Member

@dkurt dkurt commented May 26, 2020

Model from https://github.com/google/automl/

DNN_BACKEND_OPENCV DNN_BACKEND_INFERENCE_ENGINE
241.67ms 88.53ms

CPU: Intel(R) Core(TM) i5-4460 CPU @ 3.20GHz

Merge with extra: opencv/opencv_extra#763

Prepare frozen graph

  1. Download repository and checkout from https://github.com/google/automl/tree/master/efficientdet#2-pretrained-efficientdet-checkpoints
  2. Run
python3 model_inspect.py --runmode=saved_model --model_name=efficientdet-d0  --ckpt_path=efficientdet-d0 --saved_model_dir=savedmodeldir
  1. Optimize
import tensorflow as tf
from tensorflow.python.tools import optimize_for_inference_lib
from tensorflow.tools.graph_transforms import TransformGraph

pb_file = 'savedmodeldir/efficientdet-d0_frozen.pb'
graph_def = tf.compat.v1.GraphDef()

try:
    with tf.io.gfile.GFile(pb_file, 'rb') as f:
        graph_def.ParseFromString(f.read())
except:
    with tf.gfile.FastGFile(pb_file, 'rb') as f:
        graph_def.ParseFromString(f.read())

graph_def = optimize_for_inference_lib.optimize_for_inference(graph_def, ['image_arrays'], ['detections'], tf.uint8.as_datatype_enum)
graph_def = TransformGraph(graph_def, ['image_arrays'], ['detections'], ['fold_constants'])

with tf.gfile.FastGFile('efficientdet-d0_opt.pb', 'wb') as f:
   f.write(graph_def.SerializeToString())
  1. Generate a .pbtxt text graph by
python3 tf_text_graph_efficientdet.py --input efficientdet-d0_opt.pb --output efficientdet-d0_opt.pbtxt
  1. Test
import cv2 as cv

net = cv.dnn_DetectionModel('efficientdet-d0_opt.pb', 'efficientdet-d0_opt.pbtxt')
net.setInputSize(512, 512)
net.setInputScale(1.0 / 255)
net.setInputMean((123.675, 116.28, 103.53))

frame = cv.imread('example.jpg')

classes, confidences, boxes = net.detect(frame, confThreshold=0.5, nmsThreshold=0.4)
for classId, confidence, box in zip(classes.flatten(), confidences.flatten(), boxes):
    cv.rectangle(frame, box, color=(255, 0, 0), thickness=3)
    cv.rectangle(frame, box, color=(0, 255, 0), thickness=1)

cv.imshow('out', frame)
cv.waitKey()

force_builders=Custom,Custom Win,Custom Mac
build_image:Custom=ubuntu-openvino-2020.2.0:16.04
build_image:Custom Win=openvino-2020.2.0
build_image:Custom Mac=openvino-2020.2.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=*

@dkurt dkurt marked this pull request as draft May 26, 2020 08:09
@dkurt dkurt marked this pull request as ready for review May 26, 2020 21:13
@dkurt dkurt force-pushed the efficientdet branch 5 times, most recently from e27e771 to 76e2393 Compare May 28, 2020 12:16
@dkurt dkurt requested a review from l-bat May 28, 2020 12:37
Copy link
Copy Markdown
Contributor

@l-bat l-bat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you 👍!

@opencv-pushbot opencv-pushbot merged commit 319db07 into opencv:3.4 May 28, 2020
@rchglev

This comment has been minimized.

@rchglev

This comment has been minimized.

@dkurt

This comment has been minimized.

@rchglev

This comment has been minimized.

@dkurt

This comment has been minimized.

@rchglev

This comment has been minimized.

@alalek

This comment has been minimized.

@rchglev

This comment has been minimized.

@dkurt

This comment has been minimized.

@rchglev

This comment has been minimized.

@opencv opencv locked as off-topic and limited conversation to collaborators Jun 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants