深度学习目标检测常用工具型代码:对训练数据的trainval.txt进行数据清洗
使用Kaggle等平台的数据集进行深度学习模型的实战训练 #生活技巧# #学习技巧# #深度学习技巧#
这个用于ODAI(航空数据目标检测)比赛当中,这个数据集像素大小从800*800-4000*4000不等,所以需要进行原始数据的裁剪,在裁剪过后有一部分数据里面什么目标都没有,要把这一部分去除,使得高效训练!
"""
如果你的训练图片太大,需要对图片进行裁剪,那么就会有很大一部分裁剪的图片里没有标签,
已经制作好了trainval.txt,将里面对应的没有标签的索引拿掉,不用做训练,即
所以需要进行清洗数据的操作,即把null的标签对应的裁剪后数据和nul的label删掉。
"""
import os
rootdir = '/media/ygx/Elements/VOCdevkit2007/trainsplit/1'
rootdir = rootdir.decode('gbk')
x = u'统计文件大小.csv'
f = open(os.path.join(rootdir,x), "w+")
null=[]
for dirname in os.listdir(rootdir):
Dir = os.path.join(rootdir, dirname)
count = 0
if (os.path.isdir(Dir)):
for r, ds, files in os.walk(Dir):
for file in files:
size = os.path.getsize(os.path.join(r, file))
count += size
(filename,extension) = os.path.splitext(file)
if size == 0:
null.append(filename)
if ((count/1024.0/1024.0) < 1024):
f.write(Dir.encode("gbk") +','+ '%.2f'% (count/1024.0/1024.0)+'MB' + '\n')
else:
f.write(Dir.encode("gbk") + ',' + '%.2f' % (count / 1024.0 / 1024.0/1024.0) + 'GB' + '\n')
else:
continue
f.close()
def GetFileFromThisRootDir(dir,ext = None):
allfiles = []
needExtFilter = (ext != None)
for root,dirs,files in os.walk(dir):
for filespath in files:
filepath = os.path.join(root, filespath)
extension = os.path.splitext(filepath)[1][1:]
if needExtFilter and extension in ext:
allfiles.append(filepath)
elif not needExtFilter:
allfiles.append(filepath)
return allfiles
allfiles = GetFileFromThisRootDir('/media/ygx/Elements/VOCdevkit2007/VOC2007/ImageSets/Main/train_and_test_子类')
for files in allfiles:
filename = os.path.basename(files)
newfile = '/media/ygx/Elements/VOCdevkit2007/VOC2007/ImageSets/train_and_test_子类_clear/'+filename
with open(files,'r') as r:
lines = r.readlines()
with open(newfile,'w') as w:
for line in lines:
if (line[:-1] not in null):
w.write(line)
else:
print '1'
网址:深度学习目标检测常用工具型代码:对训练数据的trainval.txt进行数据清洗 https://www.yuejiaxmz.com/news/view/124671
相关内容
基于深度学习的生活垃圾检测与分类系统(网页版+YOLOv8/v7/v6/v5代码+训练数据集)智能生活垃圾检测与分类系统(UI界面+YOLOv5+训练数据集)
数据挖掘:数据清洗——数据噪声处理
构建厨房灶火监控与提醒系统:基于NanoDet的深度学习目标检测解决方案
【时间序列管理秘籍】:xts数据包基础及深度解析
【深度学习】深度学习语音识别算法的详细解析
【Matlab学习手记】BP神经网络数据预测
目标检测算法: 对Faster RCNN论文的理解与实践
大数据驱动的智能家居:未来的生活方式
在深度学习中,特征分解是如何提高大规模数据处理的模型效率和精度的?请参考《深度学习》中文版相关章节给出详细的解释。