Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Cant run inference using model from tf zoo


I am trying to use opencv dnn module to run inference using the model from 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:

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 "", 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