我将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。
最佳答案
我可以通过以下命令使用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上完美工作
关于python - OpenCV-Tensorflow模型导入错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49404442/