下面展示一些 内联代码片
。
// 处理跨镜头下的人骑车图片
import os
from shutil import copyfile
import random
download_path = '../veri'
save_path = download_path + '/pytorch_4_5test/' # save position
if not os.path.isdir(save_path):
os.mkdir(save_path)
query_path = download_path + '/cam_4_5' # file position
query = save_path + 'query/'
gallery = save_path + 'gallery/'
if not os.path.isdir(query):
os.mkdir(query)
if not os.path.isdir(gallery):
os.mkdir(gallery)
i = 141 # modify id
for root, dirs, files in os.walk(query_path, topdown=True):
k = 0
random.shuffle(files)
for name in files:
k += 1
tmp = []
if not name[-3:] == 'jpg':
continue
ID = str(i).zfill(6)
tmp.append(ID)
file_name = name.split('_')
cs = ''
if file_name[0] == 'cam4': # modify camera
cs = 'c4s3' # camera and scene
if file_name[0] == 'cam5': # modify camera
cs = 'c5s2' # camera and scene
tmp.append(cs)
number = random.randint(10000, 190000)
number = str(number).zfill(4)
tmp.append(number)
frames = file_name[-1].split('.')[0]
tmp.append(frames)
string = '_'
new_path = '_'.join(map(str, tmp))
jpg = '.jpg'
new_path = ''.join([new_path, jpg])
oldir = os.path.join(root, name)
oldir = oldir.split('\\')
oldir = '/'.join(map(str, oldir))
print(oldir)
print(save_path)
# train environment
# newdir = save_path + new_path
# copyfile(oldir, newdir)
# test environment
if k <= 10:
newdir = query + new_path
copyfile(oldir, newdir)
else:
newdir = gallery + new_path
copyfile(oldir, newdir)
i += 1
// 处理单镜头下的人骑车图片
import os
from shutil import copyfile
import random
download_path = '../veri'
save_path = download_path + '/Distractors_train/' # save position
if not os.path.isdir(save_path):
os.mkdir(save_path)
query_path = download_path + '/Distractors' # file position
i = 2322 # modify id
for root, dirs, files in os.walk(query_path, topdown=True):
k = 0
random.shuffle(files)
for name in files:
k += 1
tmp = []
if not name[-3:] == 'jpg':
continue
ID = str(i).zfill(6)
tmp.append(ID)
file_name = name.split('_')
cs = ''
if file_name[0] == 'cam1': # modify camera
cs = 'c1s2' # camera and scene
if file_name[0] == 'cam2': # modify camera
cs = 'c2s1' # camera and scene
if file_name[0] == 'cam3': # modify camera
cs = 'c3s3' # camera and scene
if file_name[0] == 'cam4': # modify camera
cs = 'c4s2' # camera and scene
if file_name[0] == 'cam5': # modify camera
cs = 'c5s3' # camera and scene
if file_name[0] == 'cam6': # modify camera
cs = 'c6s1' # camera and scene
tmp.append(cs)
number = random.randint(10000, 190000)
number = str(number).zfill(4)
tmp.append(number)
frames = file_name[-1].split('.')[0]
tmp.append(frames)
string = '_'
new_path = '_'.join(map(str, tmp))
jpg = '.jpg'
new_path = ''.join([new_path, jpg])
oldir = os.path.join(root, name)
oldir = oldir.split('\\')
oldir = '/'.join(map(str, oldir))
print(oldir)
print(save_path)
# print(root)
# print(files)
newdir = save_path + new_path
copyfile(oldir, newdir)
i += 1