Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Issue Using TensorFlow Self-Trained Model in DNN Module

I am trying to use a model I trained myself with OpenCV's DNN module based off of these examples:

  • https://github.com/opencv/opencv/wiki/TensorFlow-Object-Detection-API
  • https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/running_locally.md
  • https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/exporting_models.md

I used "ssd_mobilenet_v1_coco_2017_11_17" as the checkpoint for my model. I also only trained it for one class.

After I exported the model I used the tf_text_graph_ssd.py file to try and generate the config file:

python c:\code\opencv\opencv\samples\dnn\tf_text_graph_ssd.py --input=C:\code\video-object-detection\models\mobilenet_ssd_v1_balls\frozen_inference_graph.pb --output=C:\code\video-object-detection\models\mobilenet_ssd_v1_balls\ssd_mobilenet_v1_balls_2018_05_20.pbtxt --num_classes=1

but I got this error:

2018-05-21 16:01:18.354975: I T:\src\github\tensorflow\tensorflow\tools\graph_transforms\transform_graph.cc:264] Applying sort_by_execution_order
Traceback (most recent call last):
  File "c:\code\opencv\opencv\samples\dnn\tf_text_graph_ssd.py", line 137, in <module>
assert(graph_def.node[0].op == 'Placeholder')
AssertionError

I did some research and kept coming across the solution to transform the graph so I tried building TensorFlow's graph_transforms tool

bazel build tensorflow/tools/graph_transforms:transform_graph

but got this error

ERROR: C:/code/tensorflow/tensorflow/tensorflow/cc/BUILD:422:1: Linking of rule '//tensorflow/cc:ops/no_op_gen_cc' failed (Exit 1181)

Of course, I'm sure the bazel build error has nothing to do with OpenCV but I thought I'd add the information

Basically, I need help creating a .pbtxt config file from my exported frozen_inference_graph.pb file.

I tried using the graph.pbtxt that was generated during training but I get this error

[libprotobuf ERROR D:\Build\OpenCV\opencv-3.4.1\3rdparty\protobuf\src\google\protobuf\text_format.cc:288] Error parsing text-format tensorflow.GraphDef: 1178:9: Unknown enumeration value of "DT_RESOURCE" for field "type".
OpenCV(3.4.1) Error: Unspecified error (FAILED: ReadProtoFromTextFile(param_file, param). Failed to parse GraphDef file: models/mobilenet_ssd_v1_balls/graph.pbtxt) in cv::dnn::ReadTFNetParamsFromTextFileOrDie, file D:\Build\OpenCV\opencv-3.4.1\modules\dnn\src\tensorflow\tf_io.cpp, line 54

cv2.error: OpenCV(3.4.1) D:\Build\OpenCV\opencv-3.4.1\modules\dnn\src\tensorflow\tf_io.cpp:54: error: (-2) FAILED: ReadProtoFromTextFile(param_file, param). Failed to parse GraphDef file: models/mobilenet_ssd_v1_balls/graph.pbtxt in function cv::dnn::ReadTFNetParamsFromTextFileOrDie

and I tried running cv::dnn::readNetFromTensorflow without a config file at all and I get this error:

OpenCV(3.4.1) Error: Unspecified error (Unknown layer type Cast in op ToFloat) in cv::dnn::experimental_dnn_v4::`anonymous-namespace'::TFImporter::populateNet, file D:\Build\OpenCV\opencv-3.4.1\modules\dnn\src\tensorflow\tf_importer.cpp, line 1582

cv2.error: OpenCV(3.4.1) D:\Build\OpenCV\opencv-3.4.1\modules\dnn\src\tensorflow\tf_importer.cpp:1582: error: (-2) Unknown layer type Cast in op ToFloat in function cv::dnn::experimental_dnn_v4::`anonymous-namespace'::TFImporter::populateNet

Any help is greatly appreciated.