TT100k数据集重新划分数据集

这是下载的TT100k数据集(2021)文件夹的构成,train文件夹包含6105张图片,test文件夹包含3071张图片,other文件夹包含7641张图片。

 由于该数据集很多类别数量很少,样本不太平衡,需要重新划分数据集,只保留图片数超过100的类别,首先需要统计每个类别的数量,过滤掉一些图片重新划分数据集,划分后只有45类

做法可以参考http://TT100K数据集转换成coco格式,并重新划分

然后将coco格式的数据集转成yolo的txt格式,重新划分数据集,train6793,val1949,test996 ,总共9738张 。具体操作可以参考https://blog.csdn.net/qq_37346140/article/details/127122818?spm=1001.2014.3001.5502

 最后根据得到的txt文件将TT100K数据集的图片重新放到不同的文件夹(tarin\test\val)

import os
import shutil
def divide_TrainValTest(source, target):'''创建文件路径:param source: 源文件位置  即标注的yolo_txt文件的目录:param target: 目标文件位置  即你想放置图片的文件目录'''for i in ['train', 'val', 'test']:path = target + '/' + iif not os.path.exists(path):os.makedirs(path)# 遍历目录下的文件名,复制对应的图片到指定目录for root, dirs, files in os.walk(source):for file in files:file_name = os.path.splitext(file)[0]image_path = os.path.join(file_name + '.jpg')# print(files)if 'train' in source:if(os.path.exists('F:\sign_data/tt100k_2021/train/' + image_path)):shutil.copyfile('F:\sign_data/tt100k_2021/train/'+ image_path, target + '/train/' + image_path)elif(os.path.exists('F:\sign_data/tt100k_2021/test/' + image_path)) :shutil.copyfile('F:\sign_data/tt100k_2021/test/'+ image_path, target + '/train/' + image_path)elif(os.path.exists('F:\sign_data/tt100k_2021/other/' + image_path)):shutil.copyfile('F:\sign_data/tt100k_2021/other/'+ image_path, target + '/train/' + image_path)else:print(image_path)passelif 'val' in source:if (os.path.exists('F:\sign_data/tt100k_2021/train/' + image_path)):shutil.copyfile('F:\sign_data/tt100k_2021/train/'+ image_path, target + '/val/' + image_path)elif (os.path.exists('F:\sign_data/tt100k_2021/test/' + image_path)):shutil.copyfile('F:\sign_data/tt100k_2021/test/'+ image_path, target + '/val/' + image_path)elif (os.path.exists('F:\sign_data/tt100k_2021/other/' + image_path)):shutil.copyfile('F:\sign_data/tt100k_2021/other/'+ image_path, target + '/val/' + image_path)else:print(image_path)passelif 'test' in source:if (os.path.exists('F:\sign_data/tt100k_2021/train/' + image_path)):shutil.copyfile('F:\sign_data/tt100k_2021/train/'+ image_path, target + '/test/' + image_path)elif (os.path.exists('F:\sign_data/tt100k_2021/test/' + image_path)):shutil.copyfile('F:\sign_data/tt100k_2021/test/'+ image_path, target + '/test/' + image_path)elif (os.path.exists('F:\sign_data/tt100k_2021/other/' + image_path)):shutil.copyfile('F:\sign_data/tt100k_2021/other/'+ image_path, target + '/test/' + image_path)else:print(image_path)pass# divide_TrainValTest("F:\sign_data/tt100k_2021/train", "F:\sign_data/tt100k_2021/imgs")
divide_TrainValTest("F:/sign_data/tt100k_2021/annotations/train", "F:/sign_data/tt100k_2021/imgs")divide_TrainValTest("F:/sign_data/tt100k_2021/annotations/val", "F:/sign_data/tt100k_2021/imgs")
divide_TrainValTest("F:/sign_data/tt100k_2021/annotations/test", "F:/sign_data/tt100k_2021/imgs")


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部