防止尺寸过小的分类框影响训练,在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文件
本文介绍了一种在YOLO格式的标注文件中过滤掉小尺寸目标框的方法,以提高模型训练质量。通过设定不同类别目标框的最小尺寸阈值,可以有效避免因小尺寸框导致的训练干扰。
968

被折叠的 条评论
为什么被折叠?



