這篇文章主要介紹Python如何生成VOC格式,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
常用目標(biāo)檢測模型基本都是讀取的PASCAL VOC格式的標(biāo)簽,下面代碼用于生成VOC格式的代碼,根據(jù)需要修改即可:
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)
補(bǔ)充知識(shí): python對(duì)PASCAL VOC標(biāo)注數(shù)據(jù)進(jìn)行統(tǒng)計(jì)
用于統(tǒng)計(jì)訓(xùn)練數(shù)據(jù)中的類別,以及所有目標(biāo)的個(gè)數(shù):
# 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格式”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
文章標(biāo)題:Python如何生成VOC格式-創(chuàng)新互聯(lián)
轉(zhuǎn)載來于:http://aaarwkj.com/article18/coedgp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站、網(wǎng)站導(dǎo)航、搜索引擎優(yōu)化、營銷型網(wǎng)站建設(shè)、標(biāo)簽優(yōu)化、網(wǎng)站排名
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容