zoukankan      html  css  js  c++  java
  • 数据集

    # 删除无关的XML文件和jpg文件
    #所有的类型
    # 需要识别的类型包括 bicycle,bus,car,person
    import os
    import re
    import shutil
    items=['aeroplane','bird','boat','bottle','cat','chair','cow','diningtable','dog','horse','motorbike','pottedplant','sheep','sofa','train','tvmonitor']
    years=['VOC2007','VOC2012']
    
    for item in items:
        pattern=r'[sS]*<name>'+item+'</name>[sS]*'
        for year in years:
        #     imagedir=os.listdir('./VOCdevkit/'+year+'/JPEGImages')
            xmldirs=os.listdir('./VOCdevkit/'+year+'/Annotations')
            for xmldir in xmldirs:
                f=open('./VOCdevkit/'+year+'/Annotations/'+xmldir)
                xmlhasperson=False
                lines=f.readlines()
                for line in lines:
                    if re.match(pattern, line,flags=0):
                        xmlhasperson=True
                f.close()
                if xmlhasperson:
                    os.remove('./VOCdevkit/'+year+'/Annotations/'+xmldir)
                    os.remove('./VOCdevkit/'+year+'/JPEGImages/'+xmldir[:-4]+'.jpg')
    
        #             person_list.append(xmldir[:-4])
        #             shutil.copyfile('./VOCdevkit/'+year+'/Annotations/'+xmldir,'./result/VOCdevkit/'+year+'/Annotations/'+xmldir) 
        #             shutil.copyfile('./VOCdevkit/'+year+'/JPEGImages/'+xmldir[:-4]+'.jpg','./result/VOCdevkit/'+year+'/JPEGImages/'+xmldir[:-4]+'.jpg') 
                
            
  • 相关阅读:
    回答自己的提问
    <构建之法>13——17章的读后感
    <构建之法>10,11,12章的读后感
    <构建之法>8,9,10章的读后感
    作业5.2
    【作业报告】作业5 四则运算 测试与封装 5.1 改进版
    作业 5.1
    阅读
    做汉堡
    阅读《构建之法》
  • 原文地址:https://www.cnblogs.com/zhoulixue/p/6776080.html
Copyright © 2011-2022 走看看