Safemotion Lib
Loading...
Searching...
No Matches
msmt17.py
Go to the documentation of this file.
1# encoding: utf-8
2"""
3@author: l1aoxingyu
4@contact: sherlockliao01@gmail.com
5"""
6
7import sys
8import os
9import os.path as osp
10
11from .bases import ImageDataset
12from ..datasets import DATASET_REGISTRY
13
18TRAIN_DIR_KEY = 'train_dir'
19TEST_DIR_KEY = 'test_dir'
20VERSION_DICT = {
21 'MSMT17_V1': {
22 TRAIN_DIR_KEY: 'train',
23 TEST_DIR_KEY: 'test',
24 },
25 'MSMT17_V2': {
26 TRAIN_DIR_KEY: 'mask_train_v2',
27 TEST_DIR_KEY: 'mask_test_v2',
28 }
29}
30
31
32@DATASET_REGISTRY.register()
34 """MSMT17.
35 Reference:
36 Wei et al. Person Transfer GAN to Bridge Domain Gap for Person Re-Identification. CVPR 2018.
37 URL: `<http://www.pkuvmc.com/publications/msmt17.html>`_
38
39 Dataset statistics:
40 - identities: 4101.
41 - images: 32621 (train) + 11659 (query) + 82161 (gallery).
42 - cameras: 15.
43 """
44 dataset_dir = '/workspace/LUPerson/fast-reid/datasets/'
45 dataset_url = None
46 dataset_name = 'msmt17'
47
48 def __init__(self, root='datasets', **kwargs):
50
51 has_main_dir = False
52 for main_dir in VERSION_DICT:
53 if osp.exists(osp.join(self.dataset_dirdataset_dir, main_dir)):
54 train_dir = VERSION_DICT[main_dir][TRAIN_DIR_KEY]
55 test_dir = VERSION_DICT[main_dir][TEST_DIR_KEY]
56 has_main_dir = True
57 break
58 assert has_main_dir, 'Dataset folder not found'
59
60 self.train_dir = osp.join(self.dataset_dirdataset_dir, main_dir, train_dir)
61 self.test_dir = osp.join(self.dataset_dirdataset_dir, main_dir, test_dir)
62 self.list_train_path = osp.join(self.dataset_dirdataset_dir, main_dir, 'list_train.txt')
63 self.list_val_path = osp.join(self.dataset_dirdataset_dir, main_dir, 'list_val.txt')
64 self.list_query_path = osp.join(self.dataset_dirdataset_dir, main_dir, 'list_query.txt')
65 self.list_gallery_path = osp.join(self.dataset_dirdataset_dir, main_dir, 'list_gallery.txt')
66
67 required_files = [
69 self.train_dir,
70 self.test_dir
71 ]
72 self.check_before_run(required_files)
73
74 train = self.process_dir(self.train_dir, self.list_train_path)
75 val = self.process_dir(self.train_dir, self.list_val_path)
76 query = self.process_dir(self.test_dir, self.list_query_path, is_train=False)
77 gallery = self.process_dir(self.test_dir, self.list_gallery_path, is_train=False)
78
79 num_train_pids = self.get_num_pids(train)
80 query_tmp = []
81 for img_path, pid, camid in query:
82 query_tmp.append((img_path, pid+num_train_pids, camid))
83 del query
84 query = query_tmp
85
86 gallery_temp = []
87 for img_path, pid, camid in gallery:
88 gallery_temp.append((img_path, pid+num_train_pids, camid))
89 del gallery
90 gallery = gallery_temp
91
92 # Note: to fairly compare with published methods on the conventional ReID setting,
93 # do not add val images to the training set.
94 if 'combineall' in kwargs and kwargs['combineall']:
95 train += val
96 super(MSMT17, self).__init__(train, query, gallery, **kwargs)
97
98 def process_dir(self, dir_path, list_path, is_train=True):
99 with open(list_path, 'r') as txt:
100 lines = txt.readlines()
101
102 data = []
103
104 for img_idx, img_info in enumerate(lines):
105 img_path, pid = img_info.split(' ')
106 pid = int(pid) # no need to relabel
107 camid = int(img_path.split('_')[2]) - 1 # index starts from 0
108 img_path = osp.join(dir_path, img_path)
109 if is_train:
110 pid = self.dataset_name + "_" + str(pid)
111 camid = self.dataset_name + "_" + str(camid)
112 data.append((img_path, pid, camid))
113
114 return data
check_before_run(self, required_files)
Definition bases.py:113
process_dir(self, dir_path, list_path, is_train=True)
Definition msmt17.py:98
__init__(self, root='datasets', **kwargs)
Definition msmt17.py:48