-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmake_dataset.py
52 lines (38 loc) · 1.76 KB
/
make_dataset.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
import os
import sys
import logging
import argparse
from utils import dataset
def main(dataset_dir, subset):
if not os.path.exists(dataset_dir):
raise OSError('Directory {} does not exist'.format(dataset))
if subset == 'Shanghai_A':
for split in ['train_data', 'test_data']:
section_dir = os.path.join(dataset_dir, 'part_A_final', split)
save_dir = os.path.join(section_dir, 'densities')
# Save dir is where all density maps are going to be saved
if not os.path.exists(save_dir):
logging.info('Creating {} directory'.format(save_dir))
os.mkdir(save_dir)
data_loader = dataset.Shanghai_A(section_dir, save_dir)
data_loader.create_groundtruth()
elif subset == 'Shanghai_B':
for split in ['train_data', 'test_data']:
section_dir = os.path.join(dataset_dir, 'part_B_final', split)
save_dir = os.path.join(section_dir, 'densities')
# Save dir is where all density maps are going to be saved
if not os.path.exists(save_dir):
logging.info('Creating {} directory'.format(save_dir))
os.mkdir(save_dir)
data_loader = dataset.Shanghai_B(section_dir, save_dir)
data_loader.create_groundtruth()
else:
raise ValueError('Subset not available for the moment')
def parse_arguments(argv):
parser = argparse.ArgumentParser()
parser.add_argument('dataset_dir', type=str, help='Path to dataset directory')
parser.add_argument('subset', type=str, help='Shanghai_A or Shanghai_B for the moment')
return vars(parser.parse_args())
if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)
main(**parse_arguments(sys.argv[1:]))