tensorflow - 是否可以为图像具有文本数据的单个类训练 YOLO(任何版本)。(找到方程的区域)
问题描述
我想知道是否可以在文本数据上训练 YOLO(任何版本,特别是具有准确性而不是速度的版本)。我要做的是在文本图像中找到存在任何方程的区域。
例如,我想在这张图像中找到 2 个感兴趣的灰色区域,以便我可以勾勒并最终分别裁剪方程。
我问这个问题是因为: 首先我还没有找到将 YOLO 用于文本数据的地方。 其次,我们如何定制与 (416,416) 不同的低分辨率,因为所有图像都是裁剪或水平的,主要是 (W=2H) 格式。
我已经为文本数据实现了 YOLO-V3 版本,但使用的是基本上用于 CPU 的 OpenCv。我想从头开始训练模型。
请帮忙。任何 Keras、Tensorflow 或 PyTorch 都可以。
这是我用于在 OpenCv 中实现的代码。
net = cv2.dnn.readNet(PATH+"yolov3.weights", PATH+"yolov3.cfg") # build the model. NOTE: This will only use CPU
layer_names = net.getLayerNames() # get all the layer names from the network 254 layers in the network
output_layers = [layer_names[i[0] - 1] for i in net.getUnconnectedOutLayers()] # output layer is the
# 3 output layers in otal
blob = cv2.dnn.blobFromImage(image=img, scalefactor=0.00392, size=(416,416), mean=(0, 0, 0), swapRB=True,)
# output as numpy array of (1,3,416,416). If you need to change the shape, change it in the config file too
# swap BGR to RGB, scale it to a threshold, resize, subtract it from the mean of 0 for all the RGB values
net.setInput(blob)
outs = net.forward(output_layers) # list of 3 elements for each channel
class_ids = [] # id of classes
confidences = [] # to store all the confidence score of objects present in bounding boxes if 0, no object is present
boxes = [] # to store all the boxes
for out in outs: # get all channels one by one
for detection in out: # get detection one by one
scores = detection[5:] # prob of 80 elements if the object(s) is/are inside the box and if yes, with what prob
class_id = np.argmax(scores) # Which class is dominating inside the list
confidence = scores[class_id]
if confidence > 0.1: # consider only those boxes which have a prob of having an object > 0.55
# grid coordinates
center_x = int(detection[0] * width) # centre X of grid
center_y = int(detection[1] * height) # Center Y of grid
w = int(detection[2] * width) # width
h = int(detection[3] * height) # height
# Rectangle coordinates
x = int(center_x - w / 2)
y = int(center_y - h / 2)
boxes.append([x, y, w, h]) # get all the bounding boxes
confidences.append(float(confidence)) # get all the confidence score
class_ids.append(class_id) # get all the clas ids
解决方案
作为对象检测器Yolo
只能用于特定的文本检测,而不是用于检测图像中可能存在的任何文本。
例如Yolo
,可以训练以进行基于文本的徽标检测,如下所示:
我想在这张图片中找到 2 个感兴趣的灰色区域,以便我可以勾勒并最终分别裁剪方程。
您的问题陈述谈到检测图像中存在的任何方程(数学公式),因此不能Yolo
单独使用。我认为mathpix与您的用例相似。他们将使用OCR
( Optical Character Recognition
) 系统训练并针对他们的用例进行微调。
最终要做类似的事情mathpix
,OCR
为您的用例定制的系统是您所需要的。不会有任何现成的解决方案。你必须建造一个。
建议的方法:
注意:无法使用 Tesseract,因为它是经过训练的预训练模型,可以阅读任何字符。您可以参考第二篇论文来训练 tesseract 以适应您的用例。
要了解有关 OCR 的信息,您可以在此处阅读。
编辑:
所以想法是建立自己的 OCR 来检测构成方程式/数学公式的东西,而不是检测每个字符。您需要有标记方程式的数据集。基本上你会寻找带有数学符号的区域(比如求和、积分等)。
一些训练自己的 OCR 的教程:
因此,想法是您遵循这些教程来了解如何
OCR
针对任何用例进行训练和构建,然后阅读我上面提到的研究论文以及我上面给出的一些基本想法,以针对您的用例构建 OCR。
推荐阅读
- reactjs - NextJs Index.html 文件未在公用文件夹中生成
- javascript - 验证字符串时间范围
- python - 如何使用 ForeignKeyConstraint 和复合外键与 SQLAlchemy 级联删除?
- salesforce-commerce-cloud - 无法访问网站某一部分的 URL 或 pdict 值
- r - 刻面的每个箱线图上的不同坐标比例并保留异常值(ggplot)
- typescript - 将具有新属性的模型推送到 MongoDB
- reactjs - 无法在下一个 js 中运行 swiperjs。未找到模块:包路径 ./swiper.scss 未从包中导出
- android - 生成的带有 CI/CD 集成的 apk 在真正的 android 设备中崩溃
- java - 如何为 java AmazonS3 客户端设置端点?
- python - Python:如何将绘图上的 X 标签设置为重复范围?