嗨,我对 dbn.predict 的工作方式感到困惑我已经使用 canny 然后 otsu 阈值在图像中检测到一个数字并将其调整为 28x28 等但是当我将它传递给 dbn.predict 时出现以下错误
ValueError:数组未对齐点积。请求形状为 (1, 28) 和 (784, 300) 的数组的点积
这是相同的代码,在此先感谢
(cnts, _) = cv2.findContours(edged.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
# sort the contours by their x-axis position, ensuring
# that we read the numbers from left to right
cnts = sorted([(c, cv2.boundingRect(c)[0]) for c in cnts], key = lambda x: x[1])
# loop over the contours
for (c, _) in cnts:
# compute the bounding box for the rectangle
(x, y, w, h) = cv2.boundingRect(c)
# if the width is at least 7 pixels and the height
# is at least 20 pixels, the contour is likely a digit
if w >= 7*scaler and h >= 25*scaler:
# crop the ROI and then threshold the grayscale
# ROI to reveal the digit
roi = gray[y:y + h, x:x + w]
thresh = roi.copy()
T = mahotas.thresholding.otsu(roi)
thresh[thresh > T] = 255
thresh = cv2.bitwise_not(thresh)
#thresh = dataset.deskew(thresh, 28)
#thresh = dataset.center_extent(thresh, (28, 28))
#print thresh.size
#cv2.imshow("Thresh", thresh)
# Resize the image
roi = cv2.resize(thresh, (28, 28), interpolation=cv2.INTER_AREA)
roi = cv2.dilate(roi, (3, 3))
print roi.size
cv2.imshow("ROI", roi)
cv2.waitKey(0)
# Calculate the HOG features
roi_hog_fd = hog(roi, orientations=9, pixels_per_cell=(28, 28), cells_per_block=(1, 1), visualise=False)
nbr = clf.predict(np.array([roi_hog_fd], 'float64'))
pred = dbn.predict(np.atleast_2d(roi/255))