-
Notifications
You must be signed in to change notification settings - Fork 72
/
data_manager.py
81 lines (69 loc) · 2.8 KB
/
data_manager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from __future__ import print_function, absolute_import
import os
import numpy as np
import random
def process_query_sysu(data_path, mode = 'all', relabel=False):
if mode== 'all':
ir_cameras = ['cam3','cam6']
elif mode =='indoor':
ir_cameras = ['cam3','cam6']
file_path = os.path.join(data_path,'exp/test_id.txt')
files_rgb = []
files_ir = []
with open(file_path, 'r') as file:
ids = file.read().splitlines()
ids = [int(y) for y in ids[0].split(',')]
ids = ["%04d" % x for x in ids]
for id in sorted(ids):
for cam in ir_cameras:
img_dir = os.path.join(data_path,cam,id)
if os.path.isdir(img_dir):
new_files = sorted([img_dir+'/'+i for i in os.listdir(img_dir)])
files_ir.extend(new_files)
query_img = []
query_id = []
query_cam = []
for img_path in files_ir:
camid, pid = int(img_path[-15]), int(img_path[-13:-9])
query_img.append(img_path)
query_id.append(pid)
query_cam.append(camid)
return query_img, np.array(query_id), np.array(query_cam)
def process_gallery_sysu(data_path, mode = 'all', trial = 0, relabel=False):
random.seed(trial)
if mode== 'all':
rgb_cameras = ['cam1','cam2','cam4','cam5']
elif mode =='indoor':
rgb_cameras = ['cam1','cam2']
file_path = os.path.join(data_path,'exp/test_id.txt')
files_rgb = []
with open(file_path, 'r') as file:
ids = file.read().splitlines()
ids = [int(y) for y in ids[0].split(',')]
ids = ["%04d" % x for x in ids]
for id in sorted(ids):
for cam in rgb_cameras:
img_dir = os.path.join(data_path,cam,id)
if os.path.isdir(img_dir):
new_files = sorted([img_dir+'/'+i for i in os.listdir(img_dir)])
files_rgb.append(random.choice(new_files))
gall_img = []
gall_id = []
gall_cam = []
for img_path in files_rgb:
camid, pid = int(img_path[-15]), int(img_path[-13:-9])
gall_img.append(img_path)
gall_id.append(pid)
gall_cam.append(camid)
return gall_img, np.array(gall_id), np.array(gall_cam)
def process_test_regdb(img_dir, trial = 1, modal = 'visible'):
if modal=='visible':
input_data_path = img_dir + 'idx/test_visible_{}'.format(trial) + '.txt'
elif modal=='thermal':
input_data_path = img_dir + 'idx/test_thermal_{}'.format(trial) + '.txt'
with open(input_data_path) as f:
data_file_list = open(input_data_path, 'rt').read().splitlines()
# Get full list of image and labels
file_image = [img_dir + '/' + s.split(' ')[0] for s in data_file_list]
file_label = [int(s.split(' ')[1]) for s in data_file_list]
return file_image, np.array(file_label)