Ask Your Question

Revision history [back]

retrained tensorflow model with Dnn.readNetFromTensorflow

Hello,

I have retrained MobileNet v2 following the tutorial on https://www.tensorflow.org/hub/tutorials/image_retraining using the retrain.py script at https://raw.githubusercontent.com/tensorflow/hub/master/examples/image_retraining/retrain.py. Retraining on the flower data set works fine and I get the graph as pb file. I then try to generate the text graph using the tf_text_graph_ssd.py script. I adapted the ssd_mobilenet_v2_coco.config from https://github.com/tensorflow/models/blob/master/research/object_detection/samples/configs/ssd_mobilenet_v2_coco.config to match the number of classes (num_classes: 5) and the fixed shape resizer to 224X224. Executing tf_text_graph_ssd.py script with the adapted config results in an assertion error (assert(num_matched_layers == num_layers)), however a pbtxt file is genrated. Loading this pbtxt together with the retrained pb via readNetFromTensorflow results in the error (-215:Assertion failed) const_layers.insert(std::make_pair(name, li)).second in function 'cv::dnn::dnn4_v20181221::`anonymous-namespace'::addConstNodes'

Does anyone here have experience in using retrained tensorflow models in OpenCV? I would need a workflow to use various retrained models within a image processing pipeline based on OpenCV.

Thanks in advance!

Kind regards, Stefan

click to hide/show revision 2
retagged

updated 2019-05-08 09:08:30 -0600

berak gravatar image

retrained tensorflow model with Dnn.readNetFromTensorflow

Hello,

I have retrained MobileNet v2 following the tutorial on https://www.tensorflow.org/hub/tutorials/image_retraining using the retrain.py script at https://raw.githubusercontent.com/tensorflow/hub/master/examples/image_retraining/retrain.py. Retraining on the flower data set works fine and I get the graph as pb file. I then try to generate the text graph using the tf_text_graph_ssd.py script. I adapted the ssd_mobilenet_v2_coco.config from https://github.com/tensorflow/models/blob/master/research/object_detection/samples/configs/ssd_mobilenet_v2_coco.config to match the number of classes (num_classes: 5) and the fixed shape resizer to 224X224. Executing tf_text_graph_ssd.py script with the adapted config results in an assertion error (assert(num_matched_layers == num_layers)), however a pbtxt file is genrated. Loading this pbtxt together with the retrained pb via readNetFromTensorflow results in the error (-215:Assertion failed) const_layers.insert(std::make_pair(name, li)).second in function 'cv::dnn::dnn4_v20181221::`anonymous-namespace'::addConstNodes'

Does anyone here have experience in using retrained tensorflow models in OpenCV? I would need a workflow to use various retrained models within a image processing pipeline based on OpenCV.

Thanks in advance!

Kind regards, Stefan