-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmyreid.py
57 lines (48 loc) · 2.13 KB
/
myreid.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
from __future__ import absolute_import
from __future__ import print_function
from __future__ import division
import sys
import os
import os.path as osp
import torchreid
from torchreid.data import ImageDataset
class NewDataset(ImageDataset):
dataset_dir = 'skicapture'
def __init__(self, root='', **kwargs):
self.root = osp.abspath(osp.expanduser(root))
self.dataset_dir = osp.join(self.root, self.dataset_dir)
root_path = '/home/dell/wlr/deep_sort_yolov3-master/output'
query_path = os.path.join(root_path, 'query')
gallery_path = os.path.join(root_path, 'gallery')
# All you need to do here is to generate three lists,
# which are train, query and gallery.
# Each list contains tuples of (img_path, pid, camid),
# where
# - img_path (str): absolute path to an image.
# - pid (int): person ID, e.g. 0, 1.
# - camid (int): camera ID, e.g. 0, 1.
# Note that
# - pid and camid should be 0-based.
# - query and gallery should share the same pid scope (e.g.
# pid=0 in query refers to the same person as pid=0 in gallery).
# - train, query and gallery share the same camid scope (e.g.
# camid=0 in train refers to the same camera as camid=0
# in query/gallery).
train = []
query = []
gallery = []
query_imgs = os.listdir(query_path)
for img in query_imgs:
img_path = os.path.join(query_path, img)
query.append((img_path, 0, 0))
gallery_imgs = os.listdir(gallery_path)
idxs = []
for img in gallery_imgs:
if int(img.split('_')[0]) not in idxs:
idxs.append(int(img.split('_')[0]))
print(idxs)
for i, img in enumerate(gallery_imgs):
img_path = os.path.join(gallery_path, img)
gallery.append((img_path, idxs.index(int(img.split('_')[0])), 1))
train.append((img_path, idxs.index(int(img.split('_')[0])), 1))
super(NewDataset, self).__init__(train, query, gallery, **kwargs)