yoloV5半自动化标注

目录

前言:

修改:

反推XML信息:

结语:


前言:

        之前自己傻不愣登写了一个半自动的标注,后来发现V5自带一个,现在来看看具体操作。

修改:

在detect.py中有两个参数 --save-txt 和 --nosave

 --save-txt  default=True 表述预测时保存label的 txt文件,会在runs/exp下生成一个labels

--nosave    default=Fause表述对预测的图片进行保存 True则是不保存

 lables里的内容为标签以及信息内容

 

反推XML信息:

  创建一个returnxml.py我们根据txt信息反推xml信息

# 将 txt 标签 文件转换为 xml 标签文件, 修改dict中的类,以及xml  txt 和jpg 路径。

from xml.dom.minidom import Document
import os
import cv2

# 'person','head','helmet','lifejacket'
def makexml(txtPath,xmlPath,picPath): #读取txt路径,xml保存路径,数据集图片所在路径
        dict = {'0': "worter",       #字典对类型进行转换,自己的标签的类。
                '1': "open",

               }
        files = os.listdir(txtPath)
        for i, name in enumerate(files):
          xmlBuilder = Document()
          annotation = xmlBuilder.createElement("annotation")  # 创建annotation标签
          xmlBuilder.appendChild(annotation)
          txtFile=open(txtPath+name)
          txtList = txtFile.readlines()
          img = cv2.imread(picPath+name[0:-4]+".jpg")
          Pheight,Pwidth,Pdepth=img.shape
          for i in txtList:
             oneline = i.strip().split(" ")

             folder = xmlBuilder.createElement("folder")#folder标签
             folderContent = xmlBuilder.createTextNode("VOC2007")
             folder.appendChild(folderContent)
             annotation.appendChild(folder)

             filename = xmlBuilder.createElement("filename")#filename标签
             filenameContent = xmlBuilder.createTextNode(name[0:-4]+".jpg")   # 图片后缀
             filename.appendChild(filenameContent)
             annotation.appendChild(filename)

             size = xmlBuilder.createElement("size")  # size标签
             width = xmlBuilder.createElement("width")  # size子标签width
             widthContent = xmlBuilder.createTextNode(str(Pwidth))
             width.appendChild(widthContent)
             size.appendChild(width)
             height = xmlBuilder.createElement("height")  # size子标签height
             heightContent = xmlBuilder.createTextNode(str(Pheight))
             height.appendChild(heightContent)
             size.appendChild(height)
             depth = xmlBuilder.createElement("depth")  # size子标签depth
             depthContent = xmlBuilder.createTextNode(str(Pdepth))
             depth.appendChild(depthContent)
             size.appendChild(depth)
             annotation.appendChild(size)

             object = xmlBuilder.createElement("object")
             picname = xmlBuilder.createElement("name")
             nameContent = xmlBuilder.createTextNode(dict[oneline[0]])
             picname.appendChild(nameContent)
             object.appendChild(picname)
             pose = xmlBuilder.createElement("pose")
             poseContent = xmlBuilder.createTextNode("Unspecified")
             pose.appendChild(poseContent)
             object.appendChild(pose)
             truncated = xmlBuilder.createElement("truncated")
             truncatedContent = xmlBuilder.createTextNode("0")
             truncated.appendChild(truncatedContent)
             object.appendChild(truncated)
             difficult = xmlBuilder.createElement("difficult")
             difficultContent = xmlBuilder.createTextNode("0")
             difficult.appendChild(difficultContent)
             object.appendChild(difficult)
             bndbox = xmlBuilder.createElement("bndbox")
             xmin = xmlBuilder.createElement("xmin")
             mathData=int(((float(oneline[1]))*Pwidth+1)-(float(oneline[3]))*0.5*Pwidth)
             xminContent = xmlBuilder.createTextNode(str(mathData))
             xmin.appendChild(xminContent)
             bndbox.appendChild(xmin)
             ymin = xmlBuilder.createElement("ymin")
             mathData = int(((float(oneline[2]))*Pheight+1)-(float(oneline[4]))*0.5*Pheight)
             yminContent = xmlBuilder.createTextNode(str(mathData))
             ymin.appendChild(yminContent)
             bndbox.appendChild(ymin)
             xmax = xmlBuilder.createElement("xmax")
             mathData = int(((float(oneline[1]))*Pwidth+1)+(float(oneline[3]))*0.5*Pwidth)
             xmaxContent = xmlBuilder.createTextNode(str(mathData))
             xmax.appendChild(xmaxContent)
             bndbox.appendChild(xmax)
             ymax = xmlBuilder.createElement("ymax")
             mathData = int(((float(oneline[2]))*Pheight+1)+(float(oneline[4]))*0.5*Pheight)
             ymaxContent = xmlBuilder.createTextNode(str(mathData))
             ymax.appendChild(ymaxContent)
             bndbox.appendChild(ymax)
             object.appendChild(bndbox)

             annotation.appendChild(object)

          f = open(xmlPath+name[0:-4]+".xml", 'w')
          xmlBuilder.writexml(f, indent='\t', newl='\n', addindent='\t', encoding='utf-8')
          f.close()

makexml("./detect/exp3\labels/",               # txt文件夹
        "./output_xml/",                 # xml文件夹
        r"./aa/")                          # 图片数据文件夹


最后打开lebelimage去查看和调整框的位置,最后的流程就正常加入数据集训练调整

结语:

        半自动化标注是基于模型有一定效果后进行,对我们的人工标注节省了很多时间,是一个十分友好的工具,希望大家不再被标注困扰。 

感谢作者:yolov5实现半自动化标注/预标注 & txt to xml_yolo txtto_国服最强貂蝉的博客-CSDN博客

 (如有侵权请联系作者进行删除)

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论
【资源说明】 python开发基于Opencv的CCM神经分割半自动化标注工具源码+项目使用说明.zip 1.准备数据集 在./sample文件夹中存放了一些CCM的图像,大小为384x484,其中感兴趣的区域为384x384。 2.边缘检测 ```python from qqlabel import EdgeDetect detection = EdgeDetect(f'./sample/image_0.jpg') detection.detect() detection.show() ``` - 导入EdgeDetect类并在实例化时传入图片路径。 - 使用detect方法执行边缘检测 - 使用show方法展示识别结果 3.转换标注格式 ```python from qqlabel import EdgeDetect, Convert detection = EdgeDetect(f'./sample/image_0.jpg') detection.detect() detection.save(f'./results/image/result_0.png') data = detection.output() convert = Convert(data) convert.create() convert.save(f'./results/json/result_0.json') ``` - 使用detect对象的save方法储存轮廓检测后的图片 - 使用output方法输出用于转换标注的数据 - 导入Convert类并在实例化时传入output输出的数据 - 使用create方法创建并完成用于标注的数据格式 - 使用convert对象的save方法储存Labelme可打开的json文件。 4.手动修正 使用Labelme打开输出的json文件并且手动修正。 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载使用,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可直接用于毕设、课设、作业等。 欢迎下载,沟通交流,互相学习,共同进步!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

芝士是只猫

开源使得世界变得更美丽

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值