问题
I am trying EAST text detector in pycharm but there is an error at line.
(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'
CODE:
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]
set the new width and height and then determine the ratio in change for both the width and height
(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"]
construct a blob from the image and then perform a forward pass of the model to obtain the two output layer sets
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)
ERROR at this line
(scores, geometry) = net.forward(layerNames)
回答1:
You are not resizing to a multiple of 32.
Important: The EAST text requires that your input image dimensions be multiples of 32, so if you choose to adjust your --width and --height values, make sure they are multiples of 32!
回答2:
Change this line
(newW, newH) = (375, 500)
to
(newW, newH) = (320,320)
回答3:
I'm getting the same error in OpenCV 4.1.1. I'm trying to run this. My image is 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))
But when I run it I get the following error:
[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'
来源:https://stackoverflow.com/questions/55963892/error-with-net-forward-in-opencv-east-text-detector-in-pycharm