Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to import Tensorflow's MobileNet into Opencv dnn?


I'm retraining Mobilenet using tensorflow's script with following command:

python tensorflow/examples/image_retraining/ \
    --image_dir ~/trainingData/ \
    --learning_rate=0.001 \
    --testing_percentage=20 \
    --validation_percentage=20 \
    --train_batch_size=32 \
    --validation_batch_size=-1 \
    --eval_step_interval=100 \
    --architecture mobilenet_1.0_224

This returns a output_graph.pb which i'm trying to import into opencv. I'm following the steps in a previous answers (, However this isn't working yet.

  1. Run the script. From the graph I know the input_names and output_names arguments are respectively input and final_result.

  2. Generate a text_graph.pbtxt.

  3. Remove unimplemented layers in opencv, e.g. Flatten etc. However MobileNet doesn't have any Flatten layers

After doing this, I'm still not able to import the model in Opencv and I receive following Error message:

cv2.error: C:\projects\opencv-python\opencv\modules\dnn\src\tensorflow\tf_importer.cpp:571: error: (-2) More than one input is Const op in function cv::dnn::experimental_dnn_v3::`anonymous-namespace'::TFImporter::getConstBlob

Any suggestions? I saw there was a SSD_MobileNet example, but I'm not interested in detections and I'm not sure how much the graph is similar.