opencv: cv::dnn::readNetFromTensorflow errors loading ssd_mobilenet_v1_coco_11_06_2017 in opencv 3.3.1

In the tensorflow model zoo, ssd_mobilenet_v1_coco is a newly trained model to download (warning: large file)

If you download it and run the following line from OpenCV 3.3.1, you’ll get an error.

cv::dnn::Net net = cv::dnn::readNetFromTensorflow("ssd_mobilenet_v1_coco_11_06_2017/frozen_inference_graph.pb", "ssd_mobilenet_v1_coco_11_06_2017/graph.pbtxt");

The error message is:

[libprotobuf ERROR opencv-3.3.1/3rdparty/protobuf/src/google/protobuf/text_format.cc:298] Error parsing text-format tensorflow.GraphDef: 113344:5: Unknown enumeration value of "DT_RESOURCE" for field "type".
OpenCV Error: Unspecified error (FAILED: ReadProtoFromTextFileTF(param_file, param). Failed to parse GraphDef file: ssd_mobilenet_v1_coco_11_06_2017/graph.pbtxt) in ReadTFNetParamsFromTextFileOrDie, file opencv-3.3.1/modules/dnn/src/tensorflow/tf_io.cpp, line 72
opencv-3.3.1/modules/dnn/src/tensorflow/tf_io.cpp:72: error: (-2) FAILED: ReadProtoFromTextFileTF(param_file, param). Failed to parse GraphDef file: ssd_mobilenet_v1_coco_11_06_2017/graph.pbtxt in function ReadTFNetParamsFromTextFileOrDie

The pbtxt file contains a node around line 113,344 that has the following type definition:

  attr {
    key: "T"
    value {
      type: DT_RESOURCE
    }
  }

Could this be fixed by updating OpenCV’s embedded dnn/src/tensorflow/tensor.proto to match the updated tensor.proto at github.com/tensorflow/tensorflow, which contains DT_RESOURCE?

PS - it looks like the config file for ssd_mobilenet_v1_coco is here: https://github.com/tensorflow/models/blob/master/research/object_detection/samples/configs/ssd_mobilenet_v1_coco.config

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 25 (7 by maintainers)

Most upvoted comments

BTW, There is OpenCV’s version of this network scheme.

There are two models for now: actual http://download.tensorflow.org/models/object_detection/ssd_mobilenet_v1_coco_2017_11_08.tar.gz and tested in OpenCV http://download.tensorflow.org/models/object_detection/ssd_mobilenet_v1_coco_11_06_2017.tar.gz . They are the same (mAP = 21 for both) but the last one was reserialized. We manage a graph import using text representation (https://github.com/opencv/opencv_extra/blob/master/testdata/dnn/ssd_mobilenet_v1_coco.pbtxt) with hardcoded names of weights (i.e. FeatureExtractor/MobilenetV1/Conv2d_0/weights) but newer version has obfuscated Const nodes names (i.e. FeatureExtractor/MobilenetV1/Conv2d_0/weights/read/_104__cf__107). Perhabs because of optimize_for_inference tool call.

I think we need to replace all references introduced at https://github.com/opencv/opencv/pull/9750 and https://github.com/opencv/opencv_extra/pull/387 from “TensorFlow Object Detection Model Zoo” to a direct link (http://download.tensorflow.org/models/object_detection/ssd_mobilenet_v1_coco_11_06_2017.tar.gz).

Issue Resolved :

In my case, I was trying to access the .pbtxt file stored in a github repository through my Google Colaboratory. I just needed the file, so instead of cloning the whole repo, I tried to access it using !wget command. I did: https://github.com/<username>/somethingelse/mask_rcnn_inception_v2_coco_2018_01_28.pbtxt. The file seemed to be downloaded, but when I ran cv2.dnn.readNetFromTensorflow, it has thrown me an error saying:

OpenCV Error: Unspecified error (FAILED: ReadProtoFromTextFileTF(param_file, param). Failed to parse GraphDef file: ssd_mobilenet_v1_coco_11_06_2017/graph.pbtxt) in ReadTFNetParamsFromTextFileOrDie, file opencv-3.3.1/modules/dnn/src/tensorflow/tf_io.cpp, line 72 opencv-3.3.1/modules/dnn/src/tensorflow/tf_io.cpp:72: error: (-2) FAILED: ReadProtoFromTextFileTF(param_file, param). Failed to parse GraphDef file: ssd_mobilenet_v1_coco_11_06_2017/graph.pbtxt in function ReadTFNetParamsFromTextFileOrDie.

I realised I should have used the raw file in github to download, as follows: !wget https://raw.githubusercontent.com/---somethingelse as part of link---/mask_rcnn_inception_v2_coco_2018_01_28.pbtxt

Since I did’t use raw, the file downloaded in HTML format where as the expected file was .pbtxt.

So go to the file location in github repository->click on the raw option on top right corner->get the URL of this raw page-> use !wget https://raw.githubusercontent.com/ ---somethingelse as part of link---/mask_rcnn_inception_v2_coco_2018_01_28.pbtxt has helped me resolved the issue.

Hope this helps someone!! 😄

@alalek python version of using ssd_mobilenet_v1_coco_11_06_2017 in opencv 3.3.1 is ok, but I could not use it in C++ version, I didn’t know why The cv::dnn::Net net = cv::dnn::readNetFromTensorflow() and Mat inputBlob = cv::dnn::blobFromImage() are ok, process died in cv::Mat output = net.forward() with no outputs ? Didn’t it support C++ version?