已经存在如下的datasets数据集分布:
datasets
├─images
│ ├─test
│ ├─train
│ └─val
├─labels
├─test
├─train
└─val
运行完之后,在datasets文件夹下生成3个txt文件:train.txt、val.txt、test.txt。
例如,test.txt中文件内容为:
import os
from tqdm import tqdm
if __name__ == '__main__':
rootdir = 'G:/A_lwd_paper/linetrash_datasets_new/A_data_samewithautol911'
rootimagesdir = os.path.join(rootdir, 'images')
rootlabelsdir = os.path.join(rootdir, 'labels')
assert os.path.exists(rootimagesdir), f'{rootimagesdir} not exists.'
assert os.path.exists(rootlabelsdir), f'{rootlabelsdir} not exists.'
imagesets = ['train', 'val', 'test'] # 将images/train val test中的图像的绝对地址分别写入txt中
for sets in imagesets:
imagesdir = os.path.join(rootimagesdir, sets)
with open(os.path.join(rootdir, f'{sets}.txt'), 'w') as f:
filelist = os.listdir(imagesdir)
for images in tqdm(filelist):
f.write(os.path.join(imagesdir, images) + '\n')