【问题标题】:Error with net.forward() in OpenCV EAST text detector in pycharmpycharm 中 OpenCV EAST 文本检测器中的 net.forward() 出错
【发布时间】:2019-09-21 15:37:37
【问题描述】:

我正在 pycharm 中尝试 EAST 文本检测器,但出现错误。 (scores, geometry) = net.forward(layerNames)

cv2.error: OpenCV(4.1.0) C:\projects\opencv-python\opencv\modules\dnn\src\layers\concat_layer.cpp:95: error: (-201:Incorrect size of input array) Inconsistent shape for ConcatLayer in function 'cv::dnn::ConcatLayerImpl::getMemoryShapes'

代码:

print("[INFO] loading EAST text detector...")
name = 'Pictures/non crop/maths soln analysis 4_89.jpg'
image = cv2.imread(name, 1)
(H, W) = image.shape[:2]

设置新的宽度和高度,然后确定变化的比例 对于宽度和高度

(newW, newH) = (375, 500)
rW = W / float(newW)
rH = H / float(newH)
# resize the image and grab the new image dimensions
image = cv2.resize(image, (newW, newH))
orig = image.copy()
(H, W) = image.shape[:2]
net = cv2.dnn.readNet("frozen_east_text_detection.pb")
layerNames = [
"feature_fusion/Conv_7/Sigmoid",
"feature_fusion/concat_3"]

从图像中构造一个 blob,然后执行前向传递 模型得到两个输出层集

blob = cv2.dnn.blobFromImage(image, 1.0, (W, H),
(123.68, 116.78, 103.94), swapRB=True, crop=False)
start = time.time()
net.setInput(blob)

此行出错

(scores, geometry) = net.forward(layerNames)

【问题讨论】:

    标签: python opencv deep-learning


    【解决方案1】:

    你不是resizing to a multiple of 32

    重要提示:EAST 文本要求您的输入图像尺寸是 32 的倍数,因此如果您选择调整 --width 和 --height 值,请确保它们是 32 的倍数!

    【讨论】:

      【解决方案2】:

      改变这一行

      (newW, newH) = (375, 500)
      

      (newW, newH) = (320,320)
      

      【讨论】:

        【解决方案3】:

        我在 OpenCV 4.1.1 中遇到了同样的错误。我正在尝试运行它。我的图像是 320x320。

        # define the two output layer names for the EAST detector model that
        # we are interested -- the first is the output probabilities and the
        # second can be used to derive the bounding box coordinates of text
        layerNames = [
            "feature_fusion/Conv_7/Sigmoid",
            "feature_fusion/concat_3"]
        # load the pre-trained EAST text detector
        print("[INFO] loading EAST text detector...")
        net = cv.dnn.readNet(east_network)
        
        # construct a blob from the image and then perform a forward pass of
        # the model to obtain the two output layer sets
        blob = cv.dnn.blobFromImage(image, 1.0, (W, H),
            (123.68, 116.78, 103.94), swapRB=True, crop=False)
        start = time.time()
        net.setInput(blob)
        (scores, geometry) = net.forward(layerNames)
        end = time.time()
        
        # show timing information on text prediction
        print("[INFO] text detection took {:.6f} seconds".format(end - start))
        

        但是当我运行它时,我收到以下错误:

        [INFO] loading EAST text detector...
        
        ---------------------------------------------------------------------------
        error                                     Traceback (most recent call last)
        <ipython-input-11-cb4226399d04> in <module>
             15 start = time.time()
             16 net.setInput(blob)
        ---> 17 (scores, geometry) = net.forward(layerNames)
             18 end = time.time()
             19 
        
        error: OpenCV(4.1.1) /io/opencv/modules/dnn/src/layers/concat_layer.cpp:95: error: (-201:Incorrect size of input array) Inconsistent shape for ConcatLayer in function 'getMemoryShapes'
        

        【讨论】:

        • 如果您的图像是普通图像,我想建议 EAST 没问题,但如果我们首先在输入图像上应用 Binarize 然后使用 tesseract,那么它将产生更好的 ocr 结果。
        【解决方案4】:

        在终端中简单运行这个命令:

        python text_detection.py --image images/car_wash.png --east frozen_east_text_detection.pb
        

        【讨论】:

          【解决方案5】:

          大小相同时,不会出现此错误;但是当尺寸改变时,例如从 320x320 到 640x640,它就会发生。 这个问题与调整为 32 的倍数无关。

          640x640 是 32 的两个倍数,但还是会出现错误。

          320x320: OK,然后是640x640: Inconsistent shape for ConcatLayer

          【讨论】:

          • 你有没有找到任何关于为什么会导致这个错误的信息?
          猜你喜欢
          • 2019-04-25
          • 1970-01-01
          • 2019-09-25
          • 2019-08-30
          • 1970-01-01
          • 2020-04-29
          • 1970-01-01
          • 2019-07-22
          • 2020-11-19
          相关资源
          最近更新 更多