File args_util.py changed (mode: 100644) (index d790b68..69122ee) |
... |
... |
def meow_parse(): |
128 |
128 |
arg = parser.parse_args() |
arg = parser.parse_args() |
129 |
129 |
return arg |
return arg |
130 |
130 |
|
|
|
131 |
|
|
131 |
132 |
def sanity_check_dataloader_parse(): |
def sanity_check_dataloader_parse(): |
132 |
133 |
parser = argparse.ArgumentParser(description='Dataloader') |
parser = argparse.ArgumentParser(description='Dataloader') |
133 |
134 |
parser.add_argument('--input', action="store", type=str, default=HardCodeVariable().SHANGHAITECH_PATH_PART_A) |
parser.add_argument('--input', action="store", type=str, default=HardCodeVariable().SHANGHAITECH_PATH_PART_A) |
|
... |
... |
def sanity_check_dataloader_parse(): |
136 |
137 |
return arg |
return arg |
137 |
138 |
|
|
138 |
139 |
|
|
|
140 |
|
def train_test_split_parse(): |
|
141 |
|
parser = argparse.ArgumentParser(description='Dataloader') |
|
142 |
|
parser.add_argument('--input', action="store", type=str, default=HardCodeVariable().SHANGHAITECH_PATH_PART_A) |
|
143 |
|
arg = parser.parse_args() |
|
144 |
|
return arg |
|
145 |
|
|
|
146 |
|
|
139 |
147 |
def real_args_parse(): |
def real_args_parse(): |
140 |
148 |
""" |
""" |
141 |
149 |
this is not dummy |
this is not dummy |
File dataset_script/sht_train_validate_spllit.py added (mode: 100644) (index 0000000..d2f811e) |
|
1 |
|
from sklearn.model_selection import train_test_split |
|
2 |
|
import glob |
|
3 |
|
import os |
|
4 |
|
from shutil import copyfile |
|
5 |
|
from args_util import train_test_split_parse |
|
6 |
|
|
|
7 |
|
|
|
8 |
|
def copy_data(image_list, dest_path): |
|
9 |
|
for image_path in image_list: |
|
10 |
|
gt_path = image_path.replace('.jpg', '.h5').replace('images', 'ground-truth-h5') |
|
11 |
|
gt_mat_path = image_path.replace('.jpg', '.mat').replace('images', 'ground-truth').replace('IMG', 'GT_IMG') |
|
12 |
|
|
|
13 |
|
# dest |
|
14 |
|
dest_image_path = image_path.replace(DATA_PATH, dest_path) |
|
15 |
|
dest_gt_path = gt_path.replace(DATA_PATH, dest_path) |
|
16 |
|
dest_gt_mat_path = gt_mat_path.replace(DATA_PATH, dest_path) |
|
17 |
|
|
|
18 |
|
copyfile(image_path, dest_image_path) |
|
19 |
|
copyfile(gt_path, dest_gt_path) |
|
20 |
|
copyfile(gt_mat_path, dest_gt_mat_path) |
|
21 |
|
print("copy ", image_path, dest_image_path) |
|
22 |
|
|
|
23 |
|
|
|
24 |
|
if __name__ == "__main__": |
|
25 |
|
|
|
26 |
|
# should contain 3 sub-folder: image, ground-truth, ground-truth-h5 |
|
27 |
|
# hey, no trailing slash |
|
28 |
|
DATA_PATH = "/data/shanghaitech_with_people_density_map/ShanghaiTech/part_A/train_data" |
|
29 |
|
|
|
30 |
|
args = train_test_split_parse() |
|
31 |
|
DATA_PATH = args.input |
|
32 |
|
|
|
33 |
|
# get list of sample |
|
34 |
|
image_list = glob.glob(os.path.join(DATA_PATH, "images", "*.jpg")) |
|
35 |
|
|
|
36 |
|
train_image_list, validate_image_list = train_test_split(image_list, test_size=0.2, random_state=19051890) |
|
37 |
|
|
|
38 |
|
print("train count ", len(train_image_list)) |
|
39 |
|
print("validate count ", len(validate_image_list)) |
|
40 |
|
|
|
41 |
|
|
|
42 |
|
# remove last slash |
|
43 |
|
if DATA_PATH[-1] == "/": |
|
44 |
|
DATA_PATH = DATA_PATH[:-1] |
|
45 |
|
|
|
46 |
|
# make train, validate path |
|
47 |
|
train_path = DATA_PATH + "_train_split" |
|
48 |
|
validate_path = DATA_PATH + "_validate_split" |
|
49 |
|
|
|
50 |
|
# make dir |
|
51 |
|
os.makedirs(os.path.join(train_path, "images"), exist_ok=True) |
|
52 |
|
os.makedirs(os.path.join(train_path, "ground-truth-h5"), exist_ok=True) |
|
53 |
|
os.makedirs(os.path.join(train_path, "ground-truth"), exist_ok=True) |
|
54 |
|
|
|
55 |
|
os.makedirs(os.path.join(validate_path, "images"), exist_ok=True) |
|
56 |
|
os.makedirs(os.path.join(validate_path, "ground-truth-h5"), exist_ok=True) |
|
57 |
|
os.makedirs(os.path.join(validate_path, "ground-truth"), exist_ok=True) |
|
58 |
|
|
|
59 |
|
copy_data(train_image_list, train_path) |
|
60 |
|
copy_data(validate_image_list, validate_path) |
|
61 |
|
|