小编Irf*_* S.的帖子

将 Tensorflow Frozen 推理图加载到 OpenCV DNN 时出错

我使用 Tensorflow API 训练了一个对象检测模型,并遵循基于 Roboflow 的 Google Colaboratory 笔记本的示例。 https://colab.research.google.com/drive/1wTMIrJhYsQdq_u7ROOkf0Lu_fsX5Mu8a

到目前为止一切顺利,我已经成功地将训练好的模型提取为推理图,再次遵循相同的笔记本:

import re
import numpy as np

output_directory = './fine_tuned_model'

lst = os.listdir(model_dir)
lst = [l for l in lst if 'model.ckpt-' in l and '.meta' in l]
steps=np.array([int(re.findall('\d+', l)[0]) for l in lst])
last_model = lst[steps.argmax()].replace('.meta', '')

last_model_path = os.path.join(model_dir, last_model)
print(last_model_path)
!python /content/models/research/object_detection/export_inference_graph.py \
    --input_type=image_tensor \
    --pipeline_config_path={pipeline_fname} \
    --output_directory={output_directory} \
    --trained_checkpoint_prefix={last_model_path}
Run Code Online (Sandbox Code Playgroud)

这给了我一个frozen_inference_graph.pb文件,我可以用它来在 OpenCV DNN 中制作我的对象检测程序。另外,按照此示例/sf/answers/3993868651/,我准备了模型和管道配置的 .pbtxt 文件作为该cv2.dnn.readNetFromTensorflow函数的第二个参数。这是足以重现我遇到的错误的代码:

model = cv2.dnn.readNetFromTensorflow('models/trained/frozen_inference_graph.pb', 
                                      'models/trained/output.pbtxt')
Run Code Online (Sandbox Code Playgroud)

当我使用预训练的 …

python opencv tensorflow google-colaboratory roboflow

5
推荐指数
1
解决办法
2402
查看次数