当前位置: 首页> 财经> 股票 > ps素材网_重庆门户网站排名_百度官网app_百度热门

ps素材网_重庆门户网站排名_百度官网app_百度热门

时间:2025/8/27 16:41:13来源:https://blog.csdn.net/HanWenKing/article/details/142654252 浏览次数:0次
ps素材网_重庆门户网站排名_百度官网app_百度热门

介绍

在目标检测中,有些时候会遇到标注好的类别不想要了的情况,这时我们可以运行下面的代码来批量删除不需要的类别节省时间。

代码实现:


import argparseimport xml.etree.ElementTree as ET
import osclasses = ['thin_smoke']def GetImgNameByEveryDir(file_dir, videoProperty):FileNameWithPath, FileName, FileDir = [], [], []for root, dirs, files in os.walk(file_dir):for file in files:if os.path.splitext(file)[1] in videoProperty:FileNameWithPath.append(os.path.join(root, file))  # 保存图片路径FileName.append(file)  # 保存图片名称FileDir.append(root[len(file_dir):])  # 保存图片所在文件夹return FileName, FileNameWithPath, FileDirdef GetBoxInfo(xmlfile):try:tree = ET.parse(xmlfile)root = tree.getroot()size = root.find('size')w = int(size.find('width').text)h = int(size.find('height').text)except:return False, 0else:tree = ET.parse(xmlfile)root = tree.getroot()size = root.find('size')w = int(size.find('width').text)h = int(size.find('height').text)for obj in root.findall('object'):print(xmlfile, obj.find('name').text, obj)if obj.find('name').text == 'fulll':obj.find('name').text = "full"print('-' * 66)tree.write(xmlfile)return 1def Process(ProcessDir):xmlDirs = ProcessDir  # + 'Labels/'FileName1, FileNameWithPath1, FileDir1 = GetImgNameByEveryDir(xmlDirs, '.xml')for k in range(len(FileName1)):annfile = xmlDirs + FileName1[k][:-4] + '.xml'result = GetBoxInfo(annfile)if __name__ == '__main__':parser = argparse.ArgumentParser()parser.add_argument('--ProcessDir', type=str, default='/home/build/smoke_ori/VOCdevkit/VOC2007/Annotations/')args = parser.parse_args()ProcessDir = args.ProcessDirProcess(ProcessDir)
关键字:ps素材网_重庆门户网站排名_百度官网app_百度热门

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: