Safemotion Lib
Loading...
Searching...
No Matches
market1501.py
Go to the documentation of this file.
1# encoding: utf-8
2"""
3@author: sherlock
4@contact: sherlockliao01@gmail.com
5"""
6
7import glob
8import os.path as osp
9import re
10import warnings
11
12from .bases import ImageDataset
13from ..datasets import DATASET_REGISTRY
14
15
16@DATASET_REGISTRY.register()
18 """Market1501.
19
20 Reference:
21 Zheng et al. Scalable Person Re-identification: A Benchmark. ICCV 2015.
22
23 URL: `<http://www.liangzheng.org/Project/project_reid.html>`_
24
25 Dataset statistics:
26 - identities: 1501 (+1 for background).
27 - images: 12936 (train) + 3368 (query) + 15913 (gallery).
28 """
29 _junk_pids = [0, -1]
30 dataset_dir = '/media/safemotion/HDD2/SM_Dataset/action_2022/action_cctv_img/'
31 # dataset_dir = ''
32 dataset_url = 'http://188.138.127.15:81/Datasets/Market-1501-v15.09.15.zip'
33 # dataset_name = "Market1501"
34 dataset_name = "market1501"
35
36 def __init__(self, root='/media/safemotion/HDD2/SM_Dataset/action_2022/action_cctv_img/', market1501_500k=False, **kwargs):
37 # self.root = osp.abspath(osp.expanduser(root))
38 self.root = root
40 print(f'self.dataset_dir = {self.dataset_dir}')
41
42 # allow alternative directory structure
44 # data_dir = osp.join(self.data_dir, 'Market1501')
45 data_dir = osp.join(self.data_dir, 'Market_Merged_pid_fillup')
46 print(f'data_dir = {data_dir}')
47 if osp.isdir(data_dir):
48 self.data_dir = data_dir
49 else:
50 warnings.warn('The current data structure is deprecated. Please '
51 'put data folders such as "bounding_box_train" under '
52 '"Market-1501-v15.09.15".')
53
54 self.train_dir = osp.join(self.data_dir, 'bounding_box_train')
55 self.query_dir = osp.join(self.data_dir, 'query')
56 self.gallery_dir = osp.join(self.data_dir, 'bounding_box_test')
57 self.extra_gallery_dir = osp.join(self.data_dir, 'images')
58 self.market1501_500k = market1501_500k
59
60 required_files = [
61 self.data_dir,
62 self.train_dir,
63 self.query_dir,
64 self.gallery_dir,
65 ]
66 if self.market1501_500k:
67 required_files.append(self.extra_gallery_dir)
68 self.check_before_run(required_files)
69
70 train = self.process_dir(self.train_dir)
71 query = self.process_dir(self.query_dir, is_train=False)
72 gallery = self.process_dir(self.gallery_dir, is_train=False)
73 if self.market1501_500k:
74 gallery += self.process_dir(self.extra_gallery_dir, is_train=False)
75
76 super(Market1501, self).__init__(train, query, gallery, **kwargs)
77
78 def process_dir(self, dir_path, is_train=True):
79 img_paths = glob.glob(osp.join(dir_path, '*.jpg'))
80 pattern = re.compile(r'([-\d]+)_c([-\d]+)')
81
82 data = []
83 for img_path in img_paths:
84 pid, camid = map(int, pattern.search(img_path).groups())
85 if pid == -1:
86 continue # junk images are just ignored
87 assert 0 <= pid <= 1501 # pid == 0 means background
88 assert 1 <= camid <= 100
89 camid -= 1 # index starts from 0
90 if is_train:
91 pid = self.dataset_name + "_" + str(pid)
92 camid = self.dataset_name + "_" + str(camid)
93 data.append((img_path, pid, camid))
94
95 return data
check_before_run(self, required_files)
Definition bases.py:113
__init__(self, root='/media/safemotion/HDD2/SM_Dataset/action_2022/action_cctv_img/', market1501_500k=False, **kwargs)
Definition market1501.py:36
process_dir(self, dir_path, is_train=True)
Definition market1501.py:78