我使用ssd_mobilenet_v1_coco模型和OpenCV进行对象检测。
cvNet = cv.dnn.readNetFromTensorflow('frozen_inference_graph.pb', 'graph.pbtxt')
使用原始graph.pbtxt时可以。 但是当我使用tf_text_graph_ssd创建pbtxt文件时 https://github.com/opencv/opencv/blob/master/samples/dnn/tf_text_graph_ssd.py
python tf_text_graph_ssd.py --input frozen_inference_graph.pb --output pbtxt/frozen_inference_graph.pbtxt
然后:
cvNet = cv.dnn.readNetFromTensorflow('frozen_inference_graph.pb', 'pbtxt/frozen_inference_graph.pbtxt')
它给出错误:
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
将pb转换为pbtxt时有什么问题?
我的目标是使用图像再训练创建自定义模型并在OpenCV上使用它。 https://www.tensorflow.org/tutorials/image_retraining
所以我有一个自定义模型,但没有pbtxt文件。
首先,我尝试为示例ssd_mobilenet_v1_coco模型创建pbtxt。
答案 0 :(得分:1)
我可以使用tf_text_graph_ssd.py通过以下命令创建pbtxt文件。
python tf_text_graph_ssd.py --input=C:\Users\Hp\Desktop\anas\Robomy\tfLearn\cell_inference_graph\frozen_inference_graph.pb --output=C:\Users\Hp\Desktop\anas\Robomy\tfLearn\cell_inference_graph\ssd_mobilenet_v1_balls_2018_05_20.pbtxt --config C:\Users\Hp\Desktop\anas\Robomy\tfLearn\data\ssd_mobilenet_v2_coco.config
此pbtxt在opencv上完美运行
答案 1 :(得分:0)
您还必须指定配置文件。我考虑如果您已经使用tensorflow API完成了转移学习,那么您将找到一个名为pipeline.config的文件以及Frozen_inference_graph.pb文件。将该文件与语法一起用作--configpipeline.config。应该可以解决问题。