由PASCAL VOC的trainval.txt生成test.txt

2022-09-02 21:20:01 浏览数 (1)

代码语言:javascript复制
import os

rootann = 'D:datasetVOCdevkitVOCdevkitVOC2012Annotations'
roottrainval = 'D:datasetVOCdevkitVOCdevkitVOC2012ImageSetsMain\trainval.txt'
roottest = 'D:datasetVOCdevkitVOCdevkitVOC2012ImageSetsMain\test.txt'
file_names = os.listdir(rootann)
alls = []
for file_name in file_names:
    file_name = file_name[:-4]
    # print(file_name)
    alls.append(file_name)

with open(roottrainval) as f:
    trainvals = f.readlines()

trainandvals = []
for trainval in trainvals:
    trainandvals.append(trainval[:-1])
# print(trainandvals)

with open(roottest,'w') as f:
    for all in alls:
        if all not in trainandvals:
            f.write(all 'n')
txt

0 人点赞