防止尺寸过小的分类框影响训练,在label中(尝试过在img中抹掉但是太麻烦)干掉尺寸不理想的框。

import numpy
import glob
import os

readpath=r'C:\Users\deepw\Desktop\data2yolo\AnnotationFiles'
savepath=r'C:\Users\deepw\Desktop\data2yolo\new'
#指定读取和存储文件的路径

files=glob.glob(r'%s\*.txt' %readpath)  #获取所有txt文件
for path in files:
    filename=os.path.basename(path)[:-4]  #获取文件名
    midlist=[]
    orig=numpy.loadtxt(path)  #读取文件
    for line in orig:  #每一行判断是否为需要删除的框数据
        if line[4]==1:  #人框
            if line[2]<=10 and line[3]<=10:
                continue
        elif line[4]==2:  #车框
            if line[2]<=50 and line[3]<=50:
                continue
        midlist.append(line)
    new=numpy.array(midlist)
    numpy.savetxt(r'%s\%s.txt' %(savepath, filename), new, fmt='%d')  #另存为新的txt文件

 

Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐