目的是将Test数据集中分割成比例的Gallery和Query
然后要求是Gallery和Query都需要同id下的图片
我写了两段代码
1.先把同id的先放在文件夹中,由于有2542个id就有2542个文件夹
2.在同id的文件夹中按比例随机分配给Gallery和Query
Input:
Output:
1.把同id的先放在一个文件夹中
# 导入对路径操作的库
import sys
import os
from IPython import embed
import shutil
import glob
def mkDir(path,id):
isExists = os.path.exists(os.path.join(path, id))
if not isExists: #判断如果文件不存在,则创建
os.makedirs(os.path.join(path, id))
if __name__ == '__main__':
gallery_path = '/home/jy/xl/workstation/Datasets/Car/Nighttime_Vehicle_ReID/gallery' # 设置创建后文件夹存放的位置
query_path = '/home/jy/xl/workstation/Datasets/Car/Nighttime_Vehicle_ReID/query' # 设置创建后文件夹存放的位置
test_path = '/home/jy/xl/workstation/Datasets/Car/Nighttime_Vehicle_ReID/test' # 图片存放的位置
test_temp_path = '/home/jy/xl/workstation/Datasets/Car/Nighttime_Vehicle_ReID/test_temp'
img_names = os.listdir(test_path)
for img_name in img_names:
str_list = img_name.split("_")
# str_list = img_path.split(