首页 > 编程知识 正文

voc数据集类别,制作自己的voc数据集

时间:2023-05-04 08:51:16 阅读:18551 作者:3282

1 .从VOC到yolo明理的哈士奇/pimportxml.etree.elementtreeasetimportpickleimportosfromosimportlistdir, getcwdfromos.pathimportjoinnt ' test ' ] classes=[ ' aeroplane ',' bicycle ',' bird ',' boat ',' bottle ',' bus ' sofa '、' train '、' tvmonitor' ] # voc的20个类别defconvert(size,box ) : dw=1./size [0] DH=1./size [1] dw=w*dwy=y*DHh=h*DHreturn(x,y,w, h ) defconvert_annotation(image_id ) : in _ file=open ('./model/dataset/VOC dev kit/VOC 2007/annotation labels/test/%s.txt ) % ) image_id )并填写' w ' ) #转换后的yolov5, 标签文件的路径tree=et.parse(in_file ) root=tree.getroot ) ) size=root.find ) ) w=ize ) ) ize ) h . textifclsnotinclassesorint (difficult )==1: continue cls _ id=classes.index (cls ) XMLbox=obj.find ) ' BnDbood b=(float(XMLbox.find(XMIN ).text )、float (XML box.find ) XMAX ).text )、float (XML box.find )、ymax )。 float(XMLbox.find(ymax ).text ) ) bb=convert ) ) w,h ),b ) out_file.write ) str ) cls_id ) '.n ' # 转换后的标签保存文件路径image _ ids=open (./model/dataset/VOC dev kit/VOC 2007/imagesets/main/% s.txt () image _ SST ) %s.txt'% ) image_set )、' w ' ) for image _ idin image _ ids 3360 # list _ file.write n ' % (image _ id ) ) conver 只需转换路径

2 .从2.yolo向voc过渡荷花/pimportosimportglobfrompilimportimagevoc _ annotations=' VOC _ test/annotations/' yolo _ ttations ' yolo _ txt ' img _ path=' yolo _ test/images/' labels=[ ' aeroplane '、' bicycle '、' bird '、' boat '和' botbot ] ' sofa ',' train ', ' tvmonitor' ] # label for datasets#图像存储位置src_img_dir=img_path # 的txt文件存储位置src _ txt _ dir=yolo _ txt src _ XML _ dir=VOC _ annotations img _ lists=glob.glob (src _ img _ dir e(item ) ) img _ names=[ ] foriteminimg _ basename temp2=OS.path.splitext (item ) img_names.append ) temp1 打开height=im.size#txt文件gt=open(src_txt_dir'/'img'.txt ' ).read (.split lines ) ) print ) ifgt n ' ) XML_file.write (filename ' str (img ).jpg''/filename(n ' ) XML _ file.write ) size n ' ) XML n ' ) XML_file.write (height ' str (height )/height(n ' ) XML _ file.write ) depth3/depth n ' ) XML n ' ) # writetheregionofimageonxmlfileforimg _ each _ labeling t : SPT=img _ each _ label.split ()其中txt中包含逗号‘print (f e.write )/name(str ) labels(int ) SPT ) ) 652 n ' ) XML _ file.write (pose unspecified/posen ' ) n ' ) XML_frite ) ) truncated ) n ) XML_frite n ' ) XML_file.write(bndbox(n ' ) center _ x=round (float (spprite ) height=round (浮动(SPT [4].strip ) ) height ) xmin=str (int (center _ x-bbox _ width/2 ) ) yming xmax=2 ) ) ymax=str ) int(center_ybbox_height/2 ) ) XML_file.write ) ) x n ' ) XML _ file.write (ymin ' n ' ) XML_file n ' ) XML_file.write(/bndbox(n ) ) XML _ file.write (/objectn ) ) XML _ file.write (/

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。