Ask Your Question
0

Opencv Python 3.4 : Error in loading Tensorflow object detection Model

asked 2018-03-28 07:05:41 -0600

prat gravatar image

I trained my own model using the faster_rcnn_resnet50_coco.config. After training, I saved the model using export_inference_graph.py. The frozen_inference_graph.pb, labelmap.pbtxt, graph.pbtxt are here.

Could you please tell me what I am doing wrong here.

import numpy as np
import cv2

# read and convert the image to the format that similar to mnist image
x_image = cv2.imread('test.png')
x_image = cv2.resize(x_image, dsize=(320,180))
x_image = 255 - x_image x_image = x_image / 255. x_image = x_image.astype(np.float32)

# read model and inference inputBlob = cv2.dnn.blobFromImage(x_image)
net = cv2.dnn.readNetFromTensorflow('inference_graph/frozen_inference_graph.pb') 
net.setInput(inputBlob) result = net.forward()
print(result) print(np.argmax(result, 1))

Error message

ToFloat:Cast(Const)
DstT:[ ]
SrcT:[ ]
OpenCV Error: Unspecified error (Unknown layer type Cast in op ToFloat) in cv::dnn::experimental_dnn_v3::`anonymous-namespace'::TFImporter::populateNet, file C:\projects\opencv-python\opencv\modules\dnn\src\tensorflow\tf_importer.cpp, line 1487
---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
C:\tensorflow1\models\research\object_detection\opencvtesting.py in <module>()
     12 inputBlob = cv2.dnn.blobFromImage(x_image)
     13
---> 14 net = cv2.dnn.readNetFromTensorflow('inference_graph/frozen_inference_graph.pb')
     15 net.setInput(inputBlob)
     16 result = net.forward()

error: C:\projects\opencv-python\opencv\modules\dnn\src\tensorflow\tf_importer.cpp:1487: error: (-2) Unknown layer type Cast in op ToFloat in function cv::dnn::experimental_dnn_v3::`anonymous-namespace'::TFImporter::populateNet
edit retag flag offensive close merge delete

Comments

@prat, A feature request to enable Faster-RCNN models from TensorFlow is still opened: https://github.com/opencv/opencv/issu....

dkurt gravatar imagedkurt ( 2018-03-28 07:35:53 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-04-10 01:38:16 -0600

dkurt gravatar image

@prat, We've opened a pull request with a new script to import Faster-RCNN networks from TensorFlow Object Detection API. Work is still in progress but you can test it and get a feedback! Thank you!

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2018-03-28 07:05:41 -0600

Seen: 779 times

Last updated: Apr 10 '18