这里纯属是一个数据集标签的格式转换,所有直接上代码:

# -*- coding: utf-8 -*-
"""
Created on Wed Apr  4 15:10:06 2018@author: kuangyongjian
"""
#!/usr/bin/python
# -*- coding: UTF-8 -*-
# 文件名:txt_to_xml.pyfrom xml.dom.minidom import Document
import os
import relist = os.listdir("F:/za/Model/pedestrain/INRIAPerson/Train/annotations")for oldfilename in list:if str(".txt") not in oldfilename:continueprint (oldfilename)oldfilename = "F:/za/Model/pedestrain/INRIAPerson/Train/annotations/" + oldfilenamefileindex = re.findall('\d+', oldfilename)print (fileindex)print (str(int(fileindex[0])))newfilename = "00" + str(int(fileindex[0])) + ".xml"#print newfilename#raw_input(unicode('按回车键退出...','utf-8').encode('gbk'))f = open(oldfilename, "r")print ('processing:' + f.name)doc = Document()annotation = doc.createElement('annotation')doc.appendChild(annotation)folder = doc.createElement('folder')folder.appendChild(doc.createTextNode('VOC2007'))annotation.appendChild(folder)filename = doc.createElement('filename')filename.appendChild(doc.createTextNode("00" + str(int(fileindex[0])) + ".jpg"))annotation.appendChild(filename)source = doc.createElement('source')annotation.appendChild(source)database = doc.createElement('database')database.appendChild(doc.createTextNode('PASperson Database'))source.appendChild(database)annotation1 = doc.createElement('annotation')annotation1.appendChild(doc.createTextNode('PASperson'))source.appendChild(annotation1)fr = f.readlines()  # 调用文件的 readline()方法一次读取for line in fr:if str(line).__contains__("size"):sizes = []sizes = re.findall('\d+', line)size = doc.createElement('size')annotation.appendChild(size)width = doc.createElement('width')width.appendChild(doc.createTextNode(sizes[0]))size.appendChild(width)height = doc.createElement('height')height.appendChild(doc.createTextNode(sizes[1]))size.appendChild(height)depth = doc.createElement('depth')depth.appendChild(doc.createTextNode(sizes[2]))size.appendChild(depth)segmented = doc.createElement('segmented')segmented.appendChild(doc.createTextNode('0'))annotation.appendChild(segmented)if (str(line).__contains__('Objects')):nums = re.findall('\d+', line)breakfor index in range(1, int(nums[0])+1):for line in fr:if str(line).__contains__("Bounding box for object " + str(index)):coordinate = re.findall('\d+', line)object = doc.createElement('object')annotation.appendChild(object)name = doc.createElement('name')name.appendChild(doc.createTextNode('person'))object.appendChild(name)pose = doc.createElement('pose')pose.appendChild(doc.createTextNode('Unspecified'))object.appendChild(pose)truncated = doc.createElement('truncated')truncated.appendChild(doc.createTextNode('0'))object.appendChild(truncated)difficult = doc.createElement('difficult')difficult.appendChild(doc.createTextNode('0'))object.appendChild(difficult)bndbox = doc.createElement('bndbox')object.appendChild(bndbox)#数字中包含序号,下标应从1开始xmin = doc.createElement('xmin')xmin.appendChild(doc.createTextNode(coordinate[1]))bndbox.appendChild(xmin)ymin = doc.createElement('ymin')ymin.appendChild(doc.createTextNode(coordinate[2]))bndbox.appendChild(ymin)xmax = doc.createElement('xmax')xmax.appendChild(doc.createTextNode(coordinate[3]))bndbox.appendChild(xmax)ymax = doc.createElement('ymax')ymax.appendChild(doc.createTextNode(coordinate[4]))bndbox.appendChild(ymax)f.close()f = open(newfilename, 'w')f.write(doc.toprettyxml(indent=""))f.close()print (str(fileindex) + " compelete")print ('process compelete')

INRIA DataSet数据集label转换为VOC2007数据集形式相关推荐

  1. BDD 100K数据集label转换为yolo训练格式

    提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 BDD 100K数据集label转换为yolo训练格式 前言 数据集介绍: 代码如下: 补充说明: 总结 前言 因为最近要做车辆,行人 ...

  2. voc数据集格式转换为coco数据集格式+修改xml格式文件

    voc数据集格式转换为coco格式+修改xml格式文件中部分内容 voc数据集格式→coco数据集格式 修改xml格式文件中部分内容 voc数据集格式→coco数据集格式 下面这份代码只需修改文件所在 ...

  3. 分割数据集label转换为目标检测boundingbox

    实现功能 将分割的label图转换为目标检测boundingbox标注文件(VOC格式). 注: 1.分割样本里一张图片只有同一类别的多个目标. 2.转换为boundingbox标注通过连通域实现,所 ...

  4. (详细版Win10+Pycharm)YOLOX——训练自己的VOC2007数据集,以NWPU VHR-10 dataset为例

    目录 一.搭建YOLOX环境 二.训练自己的VOC数据集 1.打开Pycharm配置Anaconda已创建好的yolo_x虚拟环境 2.在Pycharm中设置Git环境 3.修改配置文件 (1)修改Y ...

  5. 将车辆数据集kitti转换为VOC格式(车辆检测)

    Kitti数据集的下载只需要一个图片集(12G)和标注文件即可(data_object_image_2.zip.data_object_label_2.zip). 下载地址:http://datase ...

  6. 【深度学习】制作VOC2007数据集用于Faster-RCNN训练

    制作VOC2007数据集用于Faster-RCNN训练:VOC2007格式是faster-RCNN中官方给出的用于训练的数据集,把它下载下来用frcnn/tool里的训练程序跑一跑就可以得到自己的训练 ...

  7. Ubuntu 16.04下Caffe-SSD的应用(八)——处理标注好的VOC2007数据集

    前言 前面已经演示了如何把图像文件标注成VOC2007数据集,标注完成之后,就要把数据转换成caffe支持的数据格式lmdb. 处理数据 1.在caffe_ssd/data/下新建一个叫VOCdevk ...

  8. Dataset:数据集集合(CV方向数据集)-常见的计算机视觉图像数据集大集合包括表面缺陷检测数据集(持续更新)

    Dataset:数据集集合(CV方向数据集)-常见的计算机视觉图像数据集大集合包括表面缺陷检测数据集(建议收藏,持续更新) 目录 CV常用数据集平台集合 Mendeley Data CAISA-Web ...

  9. caffe学习(七):使用py-faster-rcnn来训练voc2007数据集(Ubuntu)

    准备数据集 1.下载数据集: 输入指令: wget http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtrainval_06-Nov-2007.tar ...

最新文章

  1. 第三章| 3.1文件处理
  2. 基于三层BP神经网络的人脸识别
  3. Nestjs 微服务
  4. shell之sed 记录
  5. 孔兵 库卡机器人_名企零距离 专访库卡首席执行官 孔兵先生
  6. Struts2中使用Session的两种方法
  7. 1.16 静态内部类
  8. MOBIUS:百度凤巢新一代广告召回系统
  9. 浏览器插件:一款解决谷歌浏览器吃内存神器插件,你值得试一试!
  10. 谷歌开源3D舞蹈生成模型FACT,舞姿清奇!
  11. npm run build 报错 versionRequirement: packageConfig.engines.node 'node' of undefined
  12. C语言 strlen 函数 - C语言零基础入门教程
  13. open表和closed表_什么是左外连接?左外连接在工作表查询中的应用
  14. 闭式系统蒸汽管径推荐速度_干货 | 蒸汽管路中,管径和阀门如何选型?
  15. 数值分析复习(六)——常微分方程数值解法
  16. 手机端链接拼多多的商品主图和视频抓取方法
  17. 01电子记账本-微信小程序
  18. 计算机学校排名高中,普通高中排名
  19. socket函数返回Too many open files
  20. 格式工厂找不到qlv文件无法添加qlv文件 怎么办 解决方法

热门文章

  1. “岁月静好,现世安稳
  2. python编写自动化脚本工具_blog/技巧与工具04-python控制鼠标自动化点击脚本.md at master · tigeroses/blog · GitHub...
  3. 基于NLMS 算法的自适应信道均衡附matlab代码
  4. 如何用纯 CSS 创作一个极品飞车 loader
  5. 网站安全狗IIS版 V4.0.15586 发布
  6. 时隔三年再更新!绝对良心工具,免费好用
  7. 【技术分享】Go 工程化-前端性能监控接入层 Layout 设计实践
  8. 从百度音乐和酷狗音乐的分类想到的
  9. 成都奔驰原厂无钥匙舒适进入改装 蔚一车改
  10. 精讲响应式WebClient第4篇-文件上传与下载