Cant run inference using model from tf zoo

asked 2018-07-06 17:50:04 -0600

moshel gravatar image

Hi,

I am trying to use opencv dnn module to run inference using the model from http://download.tensorflow.org/models... I am using the following code:

import cv2 as cv

cvNet = cv.dnn.readNetFromTensorflow('frcnn2.pb')

img = cv.imread('in.png')
rows = img.shape[0]
cols = img.shape[1]
cvNet.setInput(cv.dnn.blobFromImage(img, 1.0/127.5, (300, 300), (127.5, 127.5, 127.5), swapRB=True, crop=False))
cvOut = cvNet.forward()

for detection in cvOut[0,0,:,:]:
    score = float(detection[2])
    if score > 0.3:
        left = detection[3] * cols
        top = detection[4] * rows
        right = detection[5] * cols
        bottom = detection[6] * rows
        cv.rectangle(img, (int(left), int(top)), (int(right), int(bottom)), (23, 230, 210), thickness=2)

I get the following message:

ToFloat_3:Cast(image_tensor:0)
DstT:[ ]
SrcT:[ ]
OpenCV(3.4.1) Error: Unspecified error (Unknown layer type Cast in op ToFloat_3) in populateNet, file /io/opencv/modules/dnn/src/tensorflow/tf_importer.cpp, line 1582
Traceback (most recent call last):
  File "t1.py", line 3, in <module>
    cvNet = cv.dnn.readNetFromTensorflow('frcnn2.pb')
cv2.error: OpenCV(3.4.1) /io/opencv/modules/dnn/src/tensorflow/tf_importer.cpp:1582: error: (-2) Unknown layer type Cast in op ToFloat_3 in function populateNet

I tried the troubleshooting but the optimization took over 2h on i7 (stopped it) and my build does not have the transform_graph. using opencv 3.4.1

Any help will be greatly appreciated! Moshe

edit retag flag offensive close merge delete

Comments

if you can't manage the optimization, maybe you want to try a faster-rcnn model from the opencv model zoo

berak gravatar imageberak ( 2018-07-07 03:41:57 -0600 )edit

also, did you see the processing scripts here ?

berak gravatar imageberak ( 2018-07-08 04:23:11 -0600 )edit

yes, i did run it and the script run quietly without errors and created the pbtxt. i passed the pbtxt as second parameter but no joy - i get:

    FirstStageFeatureExtractor/InceptionResnetV2/InceptionResnetV2/Repeat_1/block17_1/Branch_0/Conv2d_1x1/Shape:Shape(FirstStageFeatureExtractor/InceptionResnetV2/InceptionResnetV2/Mixed_6a/concat)
out_type:[ ]
OpenCV(3.4.1) Error: Unspecified error (Unknown layer type Shape in op FirstStageFeatureExtractor/InceptionResnetV2/InceptionResnetV2/Repeat_1/block17_1/Branch_0/Conv2d_1x1/Shape) in populateNet, file /io/opencv/modules/dnn/src/tensorflow/tf_importer.cpp, line 1582
Traceback (most recent call last):
  File "t1.py", line 3, in <module>
    cvNet = cv.dnn.readNetFromTensorflow('faster_rcnn_inception_resnet_v2_atrous_oid_2018_01
moshel gravatar imagemoshel ( 2018-07-08 05:12:02 -0600 )edit

cvNet = cv.dnn.readNetFromTensorflow('faster_rcnn_inception_resnet_v2_atrous_oid_2018_01_28/frozen_inference_graph.pb', 'frcnn.pbtxt') cv2.error: OpenCV(3.4.1) /io/opencv/modules/dnn/src/tensorflow/tf_importer.cpp:1582: error: (-2) Unknown layer type Shape in op FirstStageFeatureExtractor/InceptionResnetV2/InceptionResnetV2/Repeat_1/block17_1/Branch_0/Conv2d_1x1/Shape in function populateNet

moshel gravatar imagemoshel ( 2018-07-08 05:13:34 -0600 )edit

also, re the suggestion to use the network from the opencsv zoo, it is not object detection model so won't help me much. this is a remarkably easy to reproduce problem... just download the model and try the short program. I have tried the optimize for inference script - it fails (probably frozen graphs in the zoo are already optimized)

moshel gravatar imagemoshel ( 2018-07-08 18:57:17 -0600 )edit