python - OpenCV-Tensorflow模型导入错误

标签 python opencv tensorflow

我将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/

相关文章:

python - 在 Python 中用交替颜色填充轮廓

opencv - 确定 OpenCV 中像素的平均距离(到图像的中心)

python - 警告 : The calling iterator did not fully read the dataset being cached. 为了避免数据集的意外截断

tensorflow - 转换 Mozilla DeepSpeech 模型以在 tensorflow.js 环境中使用

python - VideoCapture() opencv python pyinstaller 打不开

tensorflow - Anaconda 安装的 Tensorflow 缺少 contrib 框架中的 'audio_ops'

python - 创建namedtuple时避免输入两次名称

php - 一秒钟内有非常多的查询。

python - 对于 __init__ 中的非配置数据来说 **kwargs 是一个不错的选择吗?

c - OpenCV cvFindContours 只查找一个轮廓