【发布时间】:2021-03-28 13:57:43
【问题描述】:
首先,感谢您花时间阅读我的问题。
我正在尝试预测边界框中的文本。不知何故,盒子和模型之间似乎没有任何联系。
我使用 EAST 文本检测来创建边界框,并使用 Keras 训练了一个 CNN 模型。现在我正在使用 opencv 通过我的网络摄像头检索输入。 readNet EAST 模型和 load_model 我训练的 CNN。
我用白色背景上的黑色文字训练我的模型。
当我尝试将两者连接起来时,它会在视频捕获中创建正确的框,但是它没有提供正确的预测类。
这是我的代码的最后一部分:
# loop over the bounding boxes
for (startX, startY, endX, endY) in boxes:
# scale the bounding box coordinates based on the respective
# ratios
startX = int(startX * rW)
startY = int(startY * rH)
endX = int(endX * rW)
endY = int(endY * rH)
orig_res =cv2.resize(orig,(200,200))
orig_res = orig_res.reshape(1,200,200,3)
prediction = model.predict(orig_res)
max_prediction = np.argmax(prediction[0])
my_prediction = myList[max_prediction]
cv2.putText(orig,str(my_prediction), (startX, startY),
cv2.FONT_HERSHEY_SIMPLEX, 1.2, (0, 0, 255), 3)
# draw the bounding box on the image
cv2.rectangle(orig, (startX, startY), (endX, endY), (0, 255, 0), 2)
# show the output image
cv2.imshow("Detect_text", orig)
myList 代表不同单词的文件夹名称。这些是模型应该预测的名称。正如您在此屏幕截图中看到的,它不会预测“100%”..
这是数据集外观的选择:
有人可以为此提供解决方案吗?非常感谢!
【问题讨论】:
-
您确定用于训练模型和文件夹名称的标签是对齐的吗?我的意思是您确定模型的标签 0 对应于
myList中的第一项。如果您可以提供有关如何创建myList的代码以及有关如何创建图像数据生成器的代码,这可能有助于调试 -
嗨 Alka,这是创建 myList myList = os.listdir(folder) 的代码
-
在此之后,我使用了生成器中的文件夹路径 class_mode='categorical'
-
你使用
flow_from_directory方法了吗? -
是的,我首先使用 ImageDataGenerator,然后使用 flow_from_directory 创建了一个训练集和验证集
标签: python conv-neural-network ocr text-recognition east-text-detector