【问题标题】:OpenCV DNN assertion failed in getMemoryShapesgetMemoryShapes 中的 OpenCV DNN 断言失败
【发布时间】:2018-01-16 18:21:25
【问题描述】:

我按照他们的指导使用 Tensorflow 的对象检测 API 训练了一个模型。我还生成了用于部署的文件,并正在尝试对图像进行分类。 OpenCV 的 DNN 文件可以使用 readNetFromTensorflow 加载图形而不会出错,但是当我尝试设置网络输入并调用 .forward() 时,它会给出以下错误。我一直在寻找解决这个问题的方法,但是我一直找不到任何东西可以为我指明正确的方向。任何帮助将不胜感激。

[INFO] loading model...
[INFO] starting video stream...
[ INFO:0] Initialize OpenCL runtime...
OpenCV Error: Assertion failed (int(numPriors * _numClasses) == inputs[1][1]) in getMemoryShapes, file /home/pi/opencv/modules/dnn/src/layers/detection_output_layer.cpp, line 202
Traceback (most recent call last):
  File "real_time_object_detection.py", line 68, in <module>
    detections = net.forward()
cv2.error: /home/pi/opencv/modules/dnn/src/layers/detection_output_layer.cpp:202: error: (-215) int(numPriors * _numClasses) == inputs[1][1] in function getMemoryShapes

【问题讨论】:

标签: python-3.x opencv object-detection


【解决方案1】:

我一直面临着完全相同的错误。诀窍是使用此脚本tf_text_graph_ssd 转换您用于训练的pipeline.config

python3 tf_text_graph_ssd.py \
--input=<path to the frozen inference graph> \
--config=<path to the pipeline.config used for training> \
--output=<output file>

然后用 opencv 创建网络

net = cv2.dnn.readNetFromTensorflow(config=<path to generated file>, model=<path to frozen inference graph>)

并推断网络

image = cv2.imread('som image file')
blob = cv2.dnn.blobFromImage(image=image, scalefactor=1.0, size=(300, 300))
net.setInput(blob)
detections = net.forward()

检查size=(300, 300) 元组,这个大小来自pipeline.config 文件

model {
  ssd {
    num_classes: 90
    image_resizer {
      fixed_shape_resizer {
        height: 300
        width: 300
      }
    }
...

也可以查看this topic 了解更多信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-06
    • 2014-02-10
    • 1970-01-01
    • 2012-11-26
    • 2014-11-24
    • 2014-05-28
    • 2020-12-31
    • 2015-09-12
    相关资源
    最近更新 更多