Python如何生成VOC格式-創(chuàng)新互聯(lián)

這篇文章主要介紹Python如何生成VOC格式,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!

創(chuàng)新互聯(lián)建站-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設、高性價比臨邑網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式臨邑網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設找我們,業(yè)務覆蓋臨邑地區(qū)。費用合理售后完善,十年實體公司更值得信賴。

常用目標檢測模型基本都是讀取的PASCAL VOC格式的標簽,下面代碼用于生成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)

補充知識: python對PASCAL VOC標注數(shù)據(jù)進行統(tǒng)計

用于統(tǒng)計訓練數(shù)據(jù)中的類別,以及所有目標的個數(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)容對大家有幫助,更多相關知識,歡迎關注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

文章標題:Python如何生成VOC格式-創(chuàng)新互聯(lián)
轉載來于:http://muchs.cn/article18/coedgp.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供響應式網(wǎng)站網(wǎng)站導航、搜索引擎優(yōu)化、營銷型網(wǎng)站建設、標簽優(yōu)化、網(wǎng)站排名

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

成都seo排名網(wǎng)站優(yōu)化