当前位置:网站首页>08目标检测数据集半自动化标注
08目标检测数据集半自动化标注
2022-07-15 16:35:00 【为成大道踏平坎坷】
深度学习目标检测通常需要较大的数据规模,但是数据集的标注通常是费时费力但又意义不大的一件事,我们可以先标注三五百张图片,然后训练一个较为初步的模型,然后使用这个模型对未标注的图像进行推理,将推理结果导出为voc格式,再将图片和标注文件使用本地图像标注软件labelimg打开,手动调整边框位置后,标注文件即可作为数据集用于后续的模型训练。
推理
!python /home/aistudio/PaddleDetection/tools/infer.py \
-c /home/aistudio/PaddleDetection/configs/cascade_rcnn/cascade_rcnn_r50_fpn_1x_coco.yml \
--draw_threshold=0.5 \
--infer_dir=img \
--output_dir=toolinfer \
--use_vdl=True \
--save_txt=True \
-o weights=/home/aistudio/output/cascade_rcnn_r50_fpn_1x_coco/model_final
将推理结果保存到txt文件中
推理结果修改为voc格式标注



将产生的推理结果文件移动到指定文件夹中,将对应的坐标信息进行修改对应,生成voc格式的xml标注文件。
转换代码
import os
import cv2
headstr = """\ <annotation> <folder>VOC</folder> <filename>%s</filename> <source> <database>My Database</database> <annotation>VOC</annotation> <image>flickr</image> <flickrid>NULL</flickrid> </source> <owner> <flickrid>NULL</flickrid> <name>company</name> </owner> <size> <width>%d</width> <height>%d</height> <depth>%d</depth> </size> <segmented>0</segmented> """
objstr = """\ <object> <name>%s</name> <pose>Unspecified</pose> <truncated>0</truncated> <difficult>%d</difficult> <bndbox> <xmin>%d</xmin> <ymin>%d</ymin> <xmax>%d</xmax> <ymax>%d</ymax> </bndbox> </object> """
tailstr = '''\ </annotation> '''
def save_annotations(boxes, img, filename):
H = img.shape[0]
W = img.shape[1]
C = img.shape[2]
# H,W,C = img.shape
img_name = filename.split('.')[0] + '.bmp'
head = headstr % (img_name, W, H, C) # 写入头文件
tail = tailstr # 写入尾文件
# 写入boxes
save_path = anno_path + filename.split('.')[0] + '.xml'
f = open(save_path, 'w')
f.write(head)
for box in boxes:
f.write(objstr % (str(box[0]), 0, float(box[2]), float(box[3]), float(box[2]) + float(box[4]), float(box[3]) + float(box[5])))
f.write(tail)
if __name__ == '__main__':
# 设置路径
root_path = './'
total_label_path = root_path + 'txt/' # txt存储的路径
total_img_path = root_path + 'img/' # 图像存储路径
anno_path = root_path + 'Annotations/' # 存储生成的xml标注文件
# 判断当前路径下是否存在Annotations这个文件夹,若不存在,自动创建一个
if not os.path.exists(anno_path):
os.mkdir(anno_path)
# 逐个读取txt标注文件
for filename in os.listdir(total_label_path):
cur_label_path = total_label_path + filename
cur_img_path = total_img_path + filename.split('.')[0] + '.bmp' # 换一下文件名后缀
cur_boxes = []
# 读取当前txt文件中的内容
with open(cur_label_path, 'r') as file:
while True:
line = file.readline().strip() # .strip()用来去掉'\r,\n'
if not line:
break
line_list = [ele for ele in line.split(' ')]
cur_boxes.append(line_list)
# 读取当前图像
cur_img = cv2.imread(cur_img_path)
# 进行xml文档存储
save_annotations(cur_boxes, cur_img, filename)
需要修改的地方:
- txt文件存放的路径
total_label_path - 图像存放的路径
total_img_path - 创建存放voc格式的文件夹
anno_path - 图像文件的后缀名
bmp
注意事项:
- 一般需要三五百张初始标注完成的图像
- 尽量使用高精度的目标检测算法完成预训练
- 根据预测结果与真实目标物的情况,合理选择推理阈值。如果漏检较多,则降低置信度阈值;若误检较多,则提高置信度阈值。
边栏推荐
- SSM integration problems - org apache. ibatis. transaction. TransactionFactory
- 函数与Symbol
- 看完这5个理由,我终于知道FTP被替代的原因
- Huawei's general card identification function enables multiple card bindings with one key
- R语言ggplot2可视化:使用ggpubr包的ggstripchart函数可视化分组点状条带图(dot strip plot)、设置position参数配置不同分组数据点的分离并且是抖动数据点
- 2pc and 3pc of consistency agreement
- Codeforces Round #100 E. New Year Garland & 2021 CCPC Subpermutation
- 物理学\数学中常用的“等号”
- fink.15 DataSet模块 算子大全
- R语言使用epiDisplay包的roc.from.table函数可视化临床诊断表格数据对应的ROC曲线并输出新的诊断表(diagnostic table)、输出灵敏度、1-特异度、AUC值等
猜你喜欢

leetcode:330. Complete the array as required

面对对象

【pytorch】|transforms.FiveCrop

如何在企业工作中应用知识管理,解决企业的问题?

虹科案例|nanoGUNE应用Onyx系统实现石墨烯电学性质的无损表征

Function advanced application

flink.14 DataStream模块 source底层是怎么实现的?

"Immersive" accommodation experience - new bottle of hotel, old wine of B & B

如何將notepad++設置為默認打開方式

函数与Symbol
随机推荐
虹科案例|nanoGUNE应用Onyx系统实现石墨烯电学性质的无损表征
Medical document OCR recognition + knowledge base verification, enabling insurance intelligent claim settlement
Hongke case | nanogue uses Onyx system to realize nondestructive characterization of graphene electrical properties
The INI file configuration should be modified during Jerry's mode [chapter]
R language ggplot2 visualization: use the ggboxplot function of ggpubr package to visualize the box graph, set the add parameter to add the distribution data point graph (dot plot, dot plot) to the bo
dried food! Teach you how to build a highly available architecture
Have you got all the distributed locks we used in those years
R语言ggplot2可视化条形图:通过双色渐变配色颜色主题可视化条形图
R language dplyr package summary_ The at function calculates the count number, mean value and median of multiple data columns (specified by vectors) in the dataframe data, and uses the list function t
MySQL数据库安装&问题
【pytorch】|transforms.FiveCrop
Differences among foreach, for in and for of
How to apply knowledge management in enterprise work to solve enterprise problems?
智能工厂名词解释
流程控制语句
fink. 15 complete set of dataset module operators
【专有名词】
Domain Driven Design Fundamentals
正则表达式
CVXPY——最新版问题