Python pycharm中OpenCV EAST文本检测器中的net.forward()出错

Python pycharm中OpenCV EAST文本检测器中的net.forward()出错,python,opencv,deep-learning,Python,Opencv,Deep Learning,我正在pycharm中尝试EAST文本检测器,但第行出现错误。 (分数、几何)=净向前(层名称) 代码: 设置新的宽度和高度,然后确定变化的比率 无论是宽度还是高度 (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 =

我正在pycharm中尝试EAST文本检测器,但第行出现错误。
(分数、几何)=净向前(层名称)

代码:

设置新的宽度和高度,然后确定变化的比率 无论是宽度还是高度

(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)
这一行有错误 你不是

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

换行

(newW, newH) = (375, 500)


我在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'
[INFO]正在加载东部文本检测器。。。
---------------------------------------------------------------------------
错误回溯(最近一次呼叫上次)
在里面
15开始=时间。时间()
16净设置输入(blob)
--->17(分数、几何)=净向前(层名称)
18结束=时间。时间()
19
错误:OpenCV(4.1.1)/io/OpenCV/modules/dnn/src/layers/concat_layer。cpp:95:错误:(-201:输入数组大小不正确)函数“getMemoryShapes”中ConcatLayer的形状不一致

在终端中简单运行此命令:

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

当大小相同时,不会发生此错误;但是,当大小更改时,例如从320x320更改为640x640,则确实会发生这种情况。 这个问题与将大小调整为32的倍数无关

640x640是32的两倍,但仍会出现错误


320x320:正常
,然后
640x640:ConcatLayer的形状不一致

我想建议,如果您的图像是正常图像,EAST是可以的,但是如果我们首先应用于输入图像,然后使用tesseract,那么它将产生更好的ocr结果。您是否找到了导致此错误的任何信息?
(newW, newH) = (320,320)
# 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'
python text_detection.py --image images/car_wash.png --east frozen_east_text_detection.pb