Citypersons数据集转VOC标准格式(YOLO 目标检测txt格式)
CItyscapes城市数据集包含一组不同的立体视频序列中记录来自50个不同城市的街景,高质量的进行像素级的注释。数据集下载地址(需要申请注册,通过申请才能下载)[https://www.cityscapes-dataset.com]
该数据集用于常语义分割,包含以下类别:
提供百度云链接地址:链接: https://pan.baidu.com/s/108_NgFheDIpnQRrwz5uhmw 提取码: dhr8
#cityperson数据集是cityscapes数据集的子集,cityperson的标注文件只标注了其中Human的类别,如上图。该标注文件下载地址为:
下载地址:https://bitbucket.org/shanshanzhang/citypersons/get/ae6814faa761.zip
提取cityscapes中标注好的类别为VOC的标准格式(JPEGImages和Annotations,txt的代码就不写了,参考博主其他博客)
#! /usr/bin/python
# -*- coding:UTF-8 -*-
import os, sys
import glob
from PIL import Image
import shutil
from scipy.io import loadmat
#img_Lists = glob.glob(src_img_dir + '\*.png')# citypersons图像的标注位置
src_anno_dir = loadmat(r'c:\Users\rockhuang\Desktop\anno_train.mat')# cityscapes图像的存储位置
src_img_dir = r"g:\dataset\cityscapes\leftImg8bit\train\\"#保存为VOC 数据集的原图和xml标注路径
new_img= r"g:\dataset\cityscapes\JPEGImages"
new_xml=r"g:\dataset\cityscapes\Annotations"if not os.path.isdir(new_img):os.makedirs(new_img)if not os.path.isdir(new_xml):os.makedirs(new_xml) a=src_anno_dir['anno_train_aligned'][0]#处理标注文件for i in range(len(a)):img_name=a[i][0][0][1][0] #frankfurt_000000_000294_leftImg8bit.png dir_name=img_name.split('_')[0]img=src_img_dir+dir_name+"\\"+img_nameshutil.copy(img, new_img+"\\"+img_name)img=Image.open(img)width, height = img.sizeposition=a[i][0][0][2]print(position)#sys.exit()xml_name=img_name.split('.')[0]xml_file = open((new_xml + '\\' + xml_name + '.xml'), 'w')xml_file.write('<annotation>\n')xml_file.write(' <folder>citysperson</folder>\n')xml_file.write(' <filename>' + str(img_name)+ '</filename>\n')xml_file.write(' <size>\n')xml_file.write(' <width>' + str(width) + '</width>\n')xml_file.write(' <height>' + str(height) + '</height>\n')xml_file.write(' <depth>3</depth>\n')xml_file.write(' </size>\n')for j in range(len(position)):category_location=position[j] #[ 1 947 406 17 40 24000 950 407 14 39]category=category_location[0] # class_label =0: ignore regions 1: pedestrians 2: riders 3: sitting persons 4: other persons 5: group of peopleif category == 0:continue
# if #if category == 1 or category ==2 or category ==3 category ==4 or category ==5:else:x=category_location[1] #class_label==1 or 2: x1,y1,w,h是与全身对齐的边界框;y=category_location[2]w=category_location[3]h=category_location[4]xml_file.write(' <object>\n')xml_file.write(' <name>' + 'person' + '</name>\n')xml_file.write(' <pose>Unspecified</pose>\n')xml_file.write(' <truncated>0</truncated>\n')xml_file.write(' <difficult>0</difficult>\n')xml_file.write(' <bndbox>\n')xml_file.write(' <xmin>' + str(x) + '</xmin>\n')xml_file.write(' <ymin>' + str(y) + '</ymin>\n')xml_file.write(' <xmax>' + str(x+w) + '</xmax>\n')xml_file.write(' <ymax>' + str(y+h) + '</ymax>\n')xml_file.write(' </bndbox>\n')xml_file.write(' </object>\n')xml_file.write('</annotation>\n')
YOLO训练VOC格式数据集,源代码中附有voc_labels.py如下,自己转下归一化的txt就OK了
import xml.etree.ElementTree as ET
import pickle
import os
from os import listdir, getcwd
from os.path import joinsets=[ ('2007', 'train'), ('2007', 'val'), ('2007', 'test')]classes = ["car", "person","rider"]#parser = ET.XMLParser("utf-8")
#tree = ET.fromstring(xmlstring, parser=parser)def convert(size, box):dw = 1./(size[0])dh = 1./(size[1])x = (box[0] + box[1])/2.0 - 1y = (box[2] + box[3])/2.0 - 1w = box[1] - box[0]h = box[3] - box[2]x = x*dww = w*dwy = y*dhh = h*dhreturn (x,y,w,h)def convert_annotation(year, image_id):in_file = open('VOCdevkit/VOC%s/Annotations/%s.xml'%(year, image_id))out_file = open('VOCdevkit/VOC%s/labels/%s.txt'%(year, image_id), 'w')#parser = ET.XMLParser(encoding="utf-8")# tree = ET.fromstring(in_file, parser=True)print in_filetree=ET.parse(in_file)# print in_fileroot = tree.getroot()size = root.find('size')w = int(size.find('width').text)h = int(size.find('height').text)for obj in root.iter('object'):difficult = obj.find('difficult').textcls = obj.find('name').textif cls not in classes or int(difficult)==1:continuecls_id = classes.index(cls)xmlbox = obj.find('bndbox')b = (float(xmlbox.find('xmin').text), float(xmlbox.find('xmax').text), float(xmlbox.find('ymin').text), float(xmlbox.find('ymax').text))bb = convert((w,h), b)out_file.write(str(cls_id) + " " + " ".join([str(a) for a in bb]) + '\n')wd = getcwd()for year, image_set in sets:if not os.path.exists('VOCdevkit/VOC%s/labels/'%(year)):os.makedirs('VOCdevkit/VOC%s/labels/'%(year))image_ids = open('VOCdevkit/VOC%s/ImageSets/Main/%s.txt'%(year, image_set)).read().strip().split()list_file = open('%s_%s.txt'%(year, image_set), 'w')for image_id in image_ids:list_file.write('%s/VOCdevkit/VOC%s/JPEGImages/%s.jpg\n'%(wd, year, image_id))convert_annotation(year, image_id)list_file.close()#os.system("cat 2007_train.txt 2007_val.txt > train.txt")
#os.system("cat 2007_train.txt 2007_val.txt 2007_test.txt 2012_train.txt 2012_val.txt > train.all.txt")
Citypersons数据集转VOC标准格式(YOLO 目标检测txt格式)相关推荐
- 【自制数据集自动标注】yolo目标检测 voc格式 单调无遮挡背景单个物体自制数据集自动标注
垃圾分类目标检测数据集准备 数据集背景: 参加全国大学生工程训练综合能力竞赛智能生活垃圾分类赛道时深感采集制作数据集过分彰显"有多少人工,就有多少智能"的惨痛,为了不辛苦麻烦身边小 ...
- [数据集][VOC]高质量的目标检测数据集合集(持续更新)
[1][数据集名称]数据集VOC正版消防灭火器数据集VOC格式-5156张 [数据集信息]数据集格式:Pascal VOC格式(仅包含jpg图片和对应的xml) 图数量(jpg文件个数 xml文件个数 ...
- python解析xml+得到pascal voc xml格式用于目标检测+美化xml
1.python解析xml img_path='./data/001.tif'xml_path='./xml/001.xml'img=cv2.imread(img_path)# cv2.imshow( ...
- 瞬间洞察万物:YOLO目标检测算法的黑科技全揭秘
目录 简介与背景知识: 数据集准备: 模型选择和预训练: 模型构建和训练: 目标检测与推断: 性能优化与改进: 实例应用和扩展: yolo各版本: 总结: 简介与背景知识: YOLO(You On ...
- 目标检测实战:4种YOLO目标检测的C++和Python两种版本实现
点击上方"3D视觉工坊",选择"星标" 干货第一时间送达 作者丨nihate 审稿丨邓富城 编辑丨极市平台 导读 本文作者使用C++编写一套基于OpenCV的Y ...
- 项目设计:基于YOLO目标检测算法的安全帽/口罩/汽车/行人/交通标志...检测
本文将详细介绍YOLO目标检测算法,该算法支持各种目标检测,包括:安全帽.汽车.造价.交通标志......等. 其他毕业设计题目推荐参考: 毕业设计:电子/通信/计算机/物联网专业毕业设计选题参考( ...
- 【深度学习】目标检测实战:4种YOLO目标检测的C++和Python两种版本实现
作者丨nihate 审稿丨邓富城 编辑丨极市平台 导读 本文作者使用C++编写一套基于OpenCV的YOLO目标检测,包含了经典的YOLOv3,YOLOv4,Yolo-Fastest和YOLObile ...
- python实现目标识别眼镜_用Python快速实现YOLO目标检测
文章也同步更新到微信公众号:R语言和Python学堂想获取本文完整代码和数据的下载链接,可关注微信公众号"R语言和Python学堂",并回复发文日期"20181223&q ...
- 基于flask的YOLO目标检测web服务及接口
这个小项目是基于flask微型目标检测服务.使用的是YOLOv3版本,使用的是在coco数据集上已经训练好的参数.整个目录结构如下(我运行的环境是window10,pycharm): 其中: cfg是 ...
最新文章
- 【翻译】停止学习框架(Stop Learning Frameworks)
- DockerFile和DockerCompose使用总结
- 管理系统模板c语言,管理系统c语言
- thinkphp3 php jwt,thinkphp框架使用JWTtoken的方法详解
- Linux下实现Raid 5软阵列
- IIS搭建站点错误系列
- win32开发(mdi应用)
- JavaScript-switch语句
- 如何在JavaScript中获取字符串数组的字符串?
- Tosca 一不小心,我把那一排模块全关闭了,怎么打开
- php编程 之php基础 表单
- 单片机原理及应用复习
- 数领科技|做工业设计可能会用到哪些软件?
- Bootstrap中tooltip插件使用 | 爱骇客
- 人工智能权威网站推荐
- 手机的红外线功能有可能淘汰
- 文本相似度:A Survey of Text Similarity Approaches
- 月薪20k+的Android面试都问些什么?完整PDF
- 对待Petya勒索病毒的解决办法
- 入手评测 华硕灵耀Pro16和联想YOGA 16s哪个好