How to run ssd_resnet_50_fpn_coco network from Tensorflow's Object Detection API in cv2?

Viewed 149

I have been using tensorflow's 1.x Object Detection API to train custom object detection models. I like to run these models using cv2, since I already have cv2 available in the inference environment. The particular model that I'm struggling with is the ssd_resnet_50_fpn_coco, which can be found in the model zoo.

To run inference on a model from tensorflow's object detection API using cv2 I need two files, a frozen_inference_graph.pb and a graph.pbtxt as described here, on openCV's wiki page.
The frozen_inference_graph.pb can be created using the API's exportation script, which takes in three checkpoint files (.ckpt) and a configuration file (.config). The graph.pbtxt can be created using the tf_text_graph_ssd.py script provided here.

when I run the tf_text_graph_ssd.py script, pointed at the frozen_inference_graph.pb from the model zoo I get an error:

Traceback (most recent call last):
  File "tf_text_graph_ssd.py", line 15, in <module>
    from tf_text_graph_common import *
ModuleNotFoundError: No module named 'tf_text_graph_common'

I fix this by copying the tf_text_graph_common.py script to the execution folder, as suggested here. This makes the script run and produce a working graph.pbtxt.

Now this works just fine if I use one of the pre-trained frozen_inference_graph.pb file from tensorflow's model zoo, to generate the graph.pbtxt file. However, if I use tensorflow's exportation script on the corresponding .ckpt files provided in the model zoo, to create a frozen_inference_graph.pb, then the tf_text_graph_ssd.py script fails with the following error:

Levels: [3-7]
Anchor scale: 4.000000
Scales per octave: 2
Aspect ratios: [1.0, 2.0, 0.5]
Number of classes: 90
Number of layers: 5
box predictor: weight_shared_convolutional
Input image size: 640x640
Traceback (most recent call last):
  File "tf_text_graph_ssd.py", line 413, in <module>
    createSSDGraph(args.input, args.config, args.output)
  File "tf_text_graph_ssd.py", line 235, in createSSDGraph
    assert(graph_def.node[0].op == 'Placeholder')
AssertionError
  

When I search for the error I find this closed github page.
I would really like to get this to work, so any help is greatly appreciated

My installation:
kubuntu 20.04
python 3.6.10
tensorflow 1.15.5
libprotoc 3.6.1
opencv-python 4.5.3.56

tensorflow object detection API commit: b6bb00b4e0e59dfcd2b4b6d307275d3fca14a933 (latest master Mon Sep 6 10:41:53 2021)

0 Answers
Related