How to import Tensorflow's MobileNet into Opencv dnn?
Hi,
I'm retraining Mobilenet using tensorflow's retrain.py script with following command:
python tensorflow/examples/image_retraining/retrain.py \
--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 \
--how_many_training_steps=400\
--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 (http://answers.opencv.org/question/18...), However this isn't working yet.
Run the
optimize_for_inference.py
script. From the graph I know the input_names and output_names arguments are respectively input and final_result.Generate a
text_graph.pbtxt
.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.
Here is a link to the
output_graph.pb
: https://drive.google.com/file/d/1F-p-...@MennoK, looks like it's because of unfused batch normalization layers. They compute weights in runtime using nodes over Const
tensors
. Can you try to run a graph transformation toolto fold constant ops as described at https://github.com/opencv/opencv/pull... ? We'll work on that issue to reduce such kind of intermediate steps by including most common subgraphs into OpenCV (like flatten, dropout and batch normalization).@dkurt After 3 days of trying, I'm still not able to build the graph transformation tool on Windows 10. Do you have any roadmap on including the flatten, dropout, etc. subgraphs?