75 has_train_dir = os.path.isdir(self.
train_dir)
76 has_query_dir = os.path.isdir(self.
query_dir)
80 valid = (has_train_dir & has_gallery_dir & has_query_dir &
81 has_used_id_file & has_used_im_file)
110 pattern = re.compile(
r'([-\d]+)_c(\d+)')
111 all_pids, all_cids = {}, {}
114 fpaths.extend(glob(os.path.join(path, ext)))
115 fpaths = sorted(fpaths)
117 fname = os.path.basename(fpath)
118 pid, cid = map(int, pattern.search(fname).groups())
119 if pid == -1:
continue
121 if pid
not in all_pids:
122 all_pids[pid] = len(all_pids)
124 if pid
not in all_pids:
126 if cid
not in all_cids:
130 ret.append((fpath, pid, cid))
134 pattern = re.compile(
r'([-\d]+)_c(\d+)')
137 fpaths.extend(glob(os.path.join(path, ext)))
138 fpaths = sorted(fpaths)
140 pid_container = set()
142 pid, _ = map(int, pattern.search(fpath).groups())
143 if pid == -1:
continue
144 pid_container.add(pid)
149 lines = f.readlines()
150 ids = [int(line.strip())
for line
in lines
if line.strip()]
151 if not len(ids) == int(len(pid_container) * self.
split_ratio):
154 print(f
"Loading split info with [mode={self.split_mode}]"
155 f
" from {self.used_id_files}")
158 choose_ids = np.random.choice(list(pid_container), num, replace=
False)
159 ids = sorted(choose_ids)
162 f.write(f
'{iidd:d} \n')
163 print(f
"Saving split info to {self.used_id_files}")
165 pid2label = {pid: label
for label, pid
in enumerate(ids)}
166 all_pids, all_cids = [], []
170 pid, camid = map(int, pattern.search(fpath).groups())
171 if pid == -1:
continue
173 if not pid
in ids:
continue
174 if relabel: pid = pid2label[pid]
175 if not pid
in all_pids: all_pids.append(pid)
176 if not camid
in all_cids: all_cids.append(camid)
177 dataset.append((fpath, pid, camid))
179 return sorted(dataset)
182 pattern = re.compile(
r'([-\d]+)_c(\d+)')
185 fpaths.extend(glob(os.path.join(path, ext)))
186 fpaths = sorted(fpaths)
191 lines = f.readlines()
195 name, pid, camid = line.strip().split(
'; ')
196 dataset.append([name, int(pid), int(camid)])
197 print(f
"Loading split data with [mode={self.split_mode}]"
198 f
" from {self.used_im_files}")
203 pid, _ = map(int, pattern.search(fpath).groups())
204 if pid == -1:
continue
206 pid_dict[pid].append(os.path.basename(fpath))
208 pid_dict[pid] = [os.path.basename(fpath)]
209 pid2label = {pid: label
for label, pid
in enumerate(sorted(pid_dict.keys()))}
210 for key, value
in pid_dict.items():
211 num = int(max(np.round(len(value) * self.
split_ratio), 1))
212 chooses = np.random.choice(value, num, replace=
False)
214 if relabel: pid = pid2label[pid]
215 for choose
in chooses:
217 _, camid = map(int, pattern.search(name).groups())
218 dataset.append([name, pid, camid -1])
221 f.write(f
"{item[0]:s}; {item[1]:d}; {item[2]:d} \n")
222 print(f
"Saving split info to {self.used_im_files}")
224 all_pids, all_cids = [], []
226 item[0] = os.path.join(path, item[0])
227 if not item[1]
in all_pids: all_pids.append(item[1])
228 if not item[2]
in all_cids: all_cids.append(item[2])
235 end = int(remain * len(dataset))
236 nd.extend(dataset[:end])
239 return sorted(dataset)