文本检测训练结果评测
1. 评测链接地址参照:http://rrc.cvc.uab.es/?ch=4&com=mymethods&task=1
2. 将测试的输出结果压缩为zip包,代码如下:
import os
import xml.etree.ElementTree as ET
import numpy as np
import zipfile
from functools import reduce
#src_dir = '/home/hhh/data/labelData_6w/ImageSets/lit.txt'
src_dir = '/home/hhh/data/labelData_6w/ImageSets/test_complex.txt'
eval_dir = "/home/hhh/code/EAST/output_complex"
dst_dir = "/home/hhh/data/labelData_6w/Annotations_det/complex"
# generate zip file
eval_output='/home/hhh/complex_submit.zip'
gt_output = '/home/hhh/complex_gt.zip'
def polygon_area(poly):
'''
compute area of a polygon
:param poly:
:return:
'''
edge = [
(poly[1][0] - poly[0][0]) * (poly[1][1] + poly[0][1]),
(poly[2][0] - poly[1][0]) * (poly[2][1] + poly[1][1]),
(poly[3][0] - poly[2][0]) * (poly[3][1] + poly[2][1]),
(poly[0][0] - poly[3][0]) * (poly[0][1] + poly[3][1])
]
return np.sum(edge)/2.
if __name__ == "__main__":
if not os.path.exists(dst_dir):
os.makedirs(dst_dir)
with open(src_dir, 'r') as f:
xml_list = [os.path.join('/home/data/vocData/labelData_6w/Annotations', ff.strip() + '.xml') for ff in f.readlines()]
for xmlfile in xml_list:
pre, back = os.path.splitext(os.path.basename(xmlfile))
tree = ET.parse(xmlfile)
root = tree.getroot()
with open(os.path.join(dst_dir, pre+".txt"), "w") as f:
for obj in root.iter('object'):
box = obj.find('bndbox')
x1 = int(box.find('x1').text)
y1 = int(box.find('y1').text)
x4 = int(box.find('x2').text)
y4 = int(box.find('y2').text)
x3 = int(box.find('x3').text)
y3 = int(box.find('y3').text)
x2 = int(box.find('x4').text)
y2 = int(box.find('y4').text)
label = obj.find('class').text
if label is None:
label = '###'
if '\n' in label:
label = reduce(lambda x,y:x+y, label.split('\n'))
text_poly = np.array([[x1, y1], [x2, y2], [x3, y3], [x4, y4]])
area = polygon_area(text_poly)
if area > 0:
print('gt poly in wrong direction')
poly = text_poly[(0, 3, 2, 1), :]
(x1, y1), (x2, y2), (x3, y3), (x4, y4) = poly.tolist()
line = str(x1)+','+str(y1)+','+str(x2)+','+str(y2)+','+str(x3)+','+str(y3)+','+str(x4)+','+str(y4)+','+ label +'\n'
f.write(line)
# zip submit file
arch = zipfile.ZipFile(eval_output,'w')
files = [os.path.join(eval_dir,f) for f in os.listdir(eval_dir) if f.endswith('.txt')]
for txtfile in files:
with open(txtfile, 'r') as f:
s=''
for line in f.readlines():
x1, y1, x2, y2, x3, y3, x4, y4 = list(map(int,line.strip().split(',')))
text_poly = np.array([[x1, y1], [x2, y2], [x3, y3], [x4, y4]])
area = polygon_area(text_poly)
if area > 0:
print('submit poly in wrong direction')
poly = text_poly[(0, 3, 2, 1), :]
(x1, y1), (x2, y2), (x3, y3), (x4, y4) = poly.tolist()
newline = str(x1)+','+str(y1)+','+str(x2)+','+str(y2)+','+str(x3)+','+str(y3)+','+str(x4)+','+str(y4)+'\n'
s += newline
arch.writestr(os.path.basename(txtfile), s)
# zip gt file
arch2 = zipfile.ZipFile(gt_output,'w')
names = [f.split('/')[-1] for f in files]
for text in [os.path.join(dst_dir,f) for f in os.listdir(dst_dir) if f.endswith('.txt')]:
if text.split('/')[-1] in names:
with open(text, 'r') as f:
s=''
for line in f.readlines():
x1, y1, x2, y2, x3, y3, x4, y4 = list(map(int,line.strip().split(',')[0:8]))
if len(line.split(',')) == 9:
label = line.strip().split(',')[-1]
else:
lable = reduce(lambda x,y:x+y,line.strip().split(',')[8:])
newline = str(x1)+','+str(y1)+','+str(x2)+','+str(y2)+','+str(x3)+','+str(y3)+','+str(x4)+','+str(y4)+',' + label +'\n'
s += newline
arch2.writestr(os.path.basename(text),s)
3. 将压缩包转换测试所需要的格式,代码如下
import zipfile
import os
import numpy as np
src_gt_path = '/home/hhh/complex_gt.zip'
src_submit_path = '/home/hhh/complex_submit.zip'
dst_gt_path = '/home/hhh/tmp/complex_gt_result.zip'
dst_submit_path = '/home/hhh/tmp/complex_submit_result.zip'
try:
archive=zipfile.ZipFile(src_gt_path, mode='r', allowZip64=True)
arc=zipfile.ZipFile(src_submit_path, mode='r', allowZip64=True)
except :
raise Exception('Error loading the ZIP archive.')
if len(archive.namelist()) != len(arc.namelist()):
raise Exception('number of file in zipfile is equal.')
print('convert gt data ...')
name_dict = {}
idx=1
zip_gt_result = zipfile.ZipFile(dst_gt_path, mode='w')
for name in archive.namelist():
f = archive.open(name, 'r')
name_dict[name] = idx
s = ''
for data in f.readlines():
#print(str(data, encoding='utf-8'))
s += str(data, encoding='utf-8')
zip_gt_result.writestr('gt_img_' + str(idx) + '.txt', s)
idx = idx + 1
print('convert submit data ...')
zip_submit_result = zipfile.ZipFile(dst_submit_path, mode='w')
for name in arc.namelist():
#print(name)
ff = arc.open(name, 'r')
s2 = ''
for data in ff.readlines():
#print(str(data, encoding='utf-8'))
s2 += str(data,encoding='utf-8')
zip_submit_result.writestr('res_img_' + str(name_dict[name]) + '.txt', s2)
4. 最后,生成完需要的压缩包格式后进行测试,执行下面代码得到结果
python script.py -g=../tmp/complex_gt_result.zip -s=../tmp/complex_submit_result.zip -o=../tmp
文本检测训练结果评测相关推荐
- PaddleOCR 文本检测训练+推理模型转换教程
GitHub - PaddlePaddle/PaddleOCR at release/2.1 一.环境准备 pip3 install --upgrade pip如果您的机器安装的是CUDA9或CUDA ...
- CVPR 2022 | 阿里华科提出:针对场景文本检测的视觉语言模型预训练
点击下方卡片,关注"CVer"公众号 AI/CV重磅干货,第一时间送达 点击进入-> CV 微信技术交流群 转载自:CSIG文档图像分析与识别专委会 本文简要介绍了发表于CV ...
- paddleocr文本检测模型的训练
1.环境的安装和开源项目的下载 首先我个人建议,玩深度学习的话,不管是工作还是学习,最起码要配一个有GPU的电脑.我个人有着血淋淋的教训,我本人是电气工程的一名学生,本科期间一点深度学习和机器学习的基 ...
- (二)目标检测模型的评测与训练技巧
转载自知乎:https://zhuanlan.zhihu.com/p/34142321 关于作者: @李家丞同济大学数学系本科在读,现为格灵深瞳算法部实习生. -------------------- ...
- 深度学习开源数据集——自动驾驶、目标检测、人脸识别、文本检测、图像分类
前言 在深度学习中,如果没有数据集,就无法训练模型,所以数据是根本,下面列出几个常用数据集. 想要更多数据集,可以去这个地址:https://www.cvmart.net/dataSets或https ...
- 格物钛数据平台国内外经典开源数据汇总(自动驾驶、目标检测、人脸识别、人体姿态估计、文本检测、NLP、医疗)
本文整理了国内外经典的开源数据,包含了目标检测.自动驾驶.人脸识别.自然语言处理.文本检测.医疗等方向,具体如下. 一.自动驾驶领域数据集 KITTI数据集 KITTI数据集由德国卡尔斯鲁厄理工学院和 ...
- 连通域最小外接矩形算法原理_基于分割的文本检测算法之PSENet/PAN/DBNet
1. 文本检测难点 文本内包含文本,艺术字体,任意方向 ,曲线文字 ,多语言,其他环境因素等是文本检测中的难点 2. 分割 问题1: 语义分割模型是对pixel进行分类,所以理论上讲,可以检测不规则的 ...
- mfc倾斜文本输入_文本检测知识梳理(持续更新)
最近在做作业批改场景的OCR相关算法研发工作,打算梳理一下文本检测的相关知识,也欢迎大家留言讨论. 目前主流的基于深度学习的目标检测方法大体分为两类:one-stage和two-stage: 1.Tw ...
- 人工智能学习--文本检测实践
注释:文本检测 和 文本识别是两回事. 可能现在已经有 end-to-end的深度神经网络可以将文本检测和识别一起实现,这个要去搜相关的sci论文. 文本检测,是从一张图片中找到文字区域,并用矩形框标 ...
最新文章
- spring单元测试
- VC++ 给选项卡控件添加不同图标
- 自由自在意式手工冰淇淋,健康时尚的美味零食
- shell 安装java_Shell脚本实现在Linux系统中自动安装JDK
- axios如何在nodejs项目里封装_【面经】jq 中 ajax 和 axios 区别,瀑布流布局,添加删除事件...
- 基于SIMD的AVS整数反变换算法设计与优化
- c字段和属性的区别_如何将唯一属性类字段设置为不允许重复?
- 马斯克刚骂了激光雷达,这篇用纯视觉代替激光雷达的名校论文「力挺」了他...
- C++11新特性——auto和decltype
- 归并排序java详解
- 乒乓球单循环赛_乒乓球单循环比赛规则
- 1 access中iif函数中的_在Access查询中使用IIF、Switch、Choose函数
- Java接口与实现类的转换
- 复习330+天,我总结了一份对大多数人都适用的复习经验
- 在Excel中输入身份证号码的方法或批量改为文本格式
- 目前人工智能的主要研究方向都有哪些?
- 【python数据分析(24)】Matplotlib库基本图形绘制(1)(线形图、柱状图、堆叠图、面积图、填图、饼图)
- 刘强东牛津大学经典演讲:我人生的4个关键抉择,都是怎么做的?
- kali工具熟悉——情报分析
- 《Java程序性能优化》