相思资源网 Design By www.200059.com
常用目标检测模型基本都是读取的PASCAL VOC格式的标签,下面代码用于生成VOC格式的代码,根据需要修改即可:
from lxml import etree, objectify def gen_txt(filename, h, w, c): E = objectify.ElementMaker(annotate=False) anno_tree = E.annotation( E.folder('VOC_OPEN_IMAGE'), E.filename(filename), E.source( E.database('The VOC2007 Database'), E.annotation('PASCAL VOC2007'), E.image('flickr'), E.flickrid("341012865") ), E.size( E.width(w), E.height(h), E.depth(c) ), E.segmented(0), E.object( E.name('1'), E.pose('left'), E.truncated('1'), E.difficult('0'), E.bndbox( E.xmin('0'), E.ymin('0'), E.xmax('0'), E.ymax('0') ) ), ) etree.ElementTree(anno_tree).write('ann/'+filename[:-4]+".xml", pretty_print=True)
补充知识: python对PASCAL VOC标注数据进行统计
用于统计训练数据中的类别,以及所有目标的个数:
# coding:utf-8 import xml.etree.cElementTree as ET import os from collections import Counter import shutil # Counter({'towCounter({'tower': 3074, 'windpower': 2014, 'thermalpower': 689, 'hydropower': 261, 'transformer': 225}) # total_num: 6263 def count(pathdir,despath): category = [] path = pathdir + '/XML/' for index,xml in enumerate(os.listdir(path)): # print(str(index) + ' xml: '+ xml) root = ET.parse(os.path.join(path, xml)) objects = root.findall('object') # ==================select images which has a special object============= for obj in objects: obj_label = obj.find('name').text if obj_label == 'transformer': print(xml) imgfile = pathdir + 'JPEG/' + xml.replace('xml', 'jpg') img_despath = despath + xml.replace('xml', 'jpg') # if not os.path.exists(img_despath): shutil.copyfile(imgfile, img_despath) # ==================select images which has a special object============= category += [ob.find('name').text for ob in objects] print(Counter(category)) total_num = sum([value for key, value in Counter(category).items()]) print('total_num:',total_num) if __name__ == '__main__': # pathdirs = list(set(os.listdir('./')) ^ set(['tools','count.py'])) # print(pathdirs) # for pathdir in pathdirs: pathdir = '/summer/Desktop/power_traindata/' despath = '/transformer/' count(pathdir,despath)
以上这篇Python 生成VOC格式的标签实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
标签:
Python,VOC格式,标签
相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com
暂无Python 生成VOC格式的标签实例的评论...
P70系列延期,华为新旗舰将在下月发布
3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。
而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?
根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。