OpenCV - Tensorflow model import error
I use ssd_mobilenet_v1_coco model with OpenCV for object detection.
cvNet = cv.dnn.readNetFromTensorflow('frozen_inference_graph.pb', 'graph.pbtxt')
When using original graph.pbtxt it is OK. But when i create pbtxt file using tf_text_graph_ssd https://github.com/opencv/opencv/blob...
python tf_text_graph_ssd.py --input frozen_inference_graph.pb --output pbtxt/frozen_inference_graph.pbtxt
and then:
cvNet = cv.dnn.readNetFromTensorflow('frozen_inference_graph.pb', 'pbtxt/frozen_inference_graph.pbtxt')
it gives error:
OpenCV Error: Unspecified error (Input layer not found:
FeatureExtractor/MobilenetV1/zeros) in
cv::dnn::experimental_dnn_v3::`anonymous-
namespace'::TFImporter::populateNet, file C:
\projects\opencv-python\opencv\modules\dnn\src\tensorflow\tf_importer.cpp,
line 1061
Traceback (most recent call last):
File "opencv_tensorflow.py", line 3, in <module>
cvNet = cv.dnn.readNetFromTensorflow('frozen_inference_graph.pb',
'pbtxt/frozen_inference_graph.pbtxt')
cv2.error: C:\projects\opencv-
python\opencv\modules\dnn\src\tensorflow\tf_importer.cpp:1061: error: (-2)
Input layer not found: FeatureExtractor/MobilenetV1/zeros in function cv::d
nn::experimental_dnn_v3::`anonymous-namespace'::TFImporter::populateNet
What is the problem when converting pb to pbtxt?
Here my aim is create custom model using image retraining and use it on OpenCV. https://www.tensorflow.org/tutorials/...
So I have a custom model but not pbtxt file.
First i try to create pbtxt for an example ssd_mobilenet_v1_coco model.
@foreign222, which version of TensorFlow did you use? Am I right that you use pre-trained model? From which version of TensorFlow it is?
tensorflow version: 1.6.0 Yes, I use pre-trained ssd_mobilenet_v1_coco_11_06_2017. It is ok when original graph.pbtxt was used. But here my problem is converting pb to pbtxt for pre-trained model.
@foreign222, Have you tried to use an origin
graph.pbtxt
for retrained model?Yes, when use retrained model with origin graph.pbtxt of ssd_mobilenet_v1_coco_11_06_2017 :
@foreign222, does you apply any graph transformations such constants fusion?
@foreign222, BTW it's deprecated version of MobileNet-SSD and I hardly recommend you use reserialized graph. They both have similar accuracy but an old one has a quite strange internal architecture. However if you already have a model we'll try to help you import it.
Ok let's go step by step.
First i retrained a model such that:
And now i have retrained.pb. What is next step?
@foreign222, Hmmm, flower photos? Do you train
image classification
orobject detection
model? Is where any SSD mentions?I want to use this model for object detection (detect bottle types in an image). https://github.com/opencv/opencv/wiki...
Isn't it possible to use tensorflow retrain script for this purpose? So have my custom bottle classifier and then use it for object(bottle) detection?
@foreign222, according to README,
retrain.py is an example script that shows how one can adapt a pretrained network for other classification problems
so I think you need to look at TensorFlow Object Detection API.