File data_flow.py changed (mode: 100644) (index 2d67c33..19347e3) |
... |
... |
def load_data_shanghaitech_pacnn(img_path, train=True): |
105 |
105 |
return img, (target1, target2, target3) |
return img, (target1, target2, target3) |
106 |
106 |
|
|
107 |
107 |
|
|
|
108 |
|
def load_data_shanghaitech_pacnn_with_perspective(img_path, train=True): |
|
109 |
|
""" |
|
110 |
|
# TODO: TEST this |
|
111 |
|
:param img_path: should contain sub folder images (contain IMG_num.jpg), ground-truth-h5 |
|
112 |
|
:param perspective_path: should contain IMG_num.mat |
|
113 |
|
:param train: |
|
114 |
|
:return: |
|
115 |
|
""" |
|
116 |
|
gt_path = img_path.replace('.jpg', '.h5').replace('images', 'ground-truth-h5') |
|
117 |
|
p_path = img_path.replace(".jpg", ".mat").replace("images", "p_map") |
|
118 |
|
img = Image.open(img_path).convert('RGB') |
|
119 |
|
gt_file = h5py.File(gt_path, 'r') |
|
120 |
|
target = np.asarray(gt_file['density']) |
|
121 |
|
perspective = np.array(h5py.File(p_path, "r")) |
|
122 |
|
|
|
123 |
|
if train: |
|
124 |
|
crop_size = (int(img.size[0] / 2), int(img.size[1] / 2)) |
|
125 |
|
if random.randint(0, 9) <= -1: |
|
126 |
|
|
|
127 |
|
dx = int(random.randint(0, 1) * img.size[0] * 1. / 2) |
|
128 |
|
dy = int(random.randint(0, 1) * img.size[1] * 1. / 2) |
|
129 |
|
else: |
|
130 |
|
dx = int(random.random() * img.size[0] * 1. / 2) |
|
131 |
|
dy = int(random.random() * img.size[1] * 1. / 2) |
|
132 |
|
|
|
133 |
|
img = img.crop((dx, dy, crop_size[0] + dx, crop_size[1] + dy)) |
|
134 |
|
target = target[dy:crop_size[1] + dy, dx:crop_size[0] + dx] |
|
135 |
|
perspective = target[dy:crop_size[1] + dy, dx:crop_size[0] + dx] |
|
136 |
|
if random.random() > 0.8: |
|
137 |
|
target = np.fliplr(target) |
|
138 |
|
img = img.transpose(Image.FLIP_LEFT_RIGHT) |
|
139 |
|
perspective = np.fliplr(perspective) |
|
140 |
|
|
|
141 |
|
target1 = cv2.resize(target, (int(target.shape[1] / 8), int(target.shape[0] / 8)), |
|
142 |
|
interpolation=cv2.INTER_CUBIC) * 64 |
|
143 |
|
target2 = cv2.resize(target, (int(target.shape[1] / 16), int(target.shape[0] / 16)), |
|
144 |
|
interpolation=cv2.INTER_CUBIC) * 256 |
|
145 |
|
target3 = cv2.resize(target, (int(target.shape[1] / 32), int(target.shape[0] / 32)), |
|
146 |
|
interpolation=cv2.INTER_CUBIC) * 1024 |
|
147 |
|
|
|
148 |
|
perspective_s = cv2.resize(perspective, (int(perspective.shape[1] / 16), int(perspective.shape[0] / 16)), |
|
149 |
|
interpolation=cv2.INTER_CUBIC) * 256 |
|
150 |
|
|
|
151 |
|
perspective_m = cv2.resize(perspective, (int(perspective.shape[1] / 8), int(perspective.shape[0] / 8)), |
|
152 |
|
interpolation=cv2.INTER_CUBIC) * 64 |
|
153 |
|
|
|
154 |
|
return img, (target1, target2, target3, perspective_s, perspective_m) |
|
155 |
|
|
108 |
156 |
def load_data_ucf_cc50_pacnn(img_path, train=True): |
def load_data_ucf_cc50_pacnn(img_path, train=True): |
109 |
157 |
""" |
""" |
110 |
158 |
dataloader for UCF-CC-50 dataset |
dataloader for UCF-CC-50 dataset |
File dataset_script/unzip_file.sh changed (mode: 100644) (index c40824f..b389f77) |
... |
... |
mv perspective-shanghaitech.zip data/ |
8 |
8 |
mv shanghaitech-with-people-density-map.zip data/ |
mv shanghaitech-with-people-density-map.zip data/ |
9 |
9 |
cd data/ |
cd data/ |
10 |
10 |
unzip perspective-shanghaitech.zip |
unzip perspective-shanghaitech.zip |
11 |
|
unzip shanghaitech-with-people-density-map.zip data/ |
|
|
11 |
|
unzip shanghaitech-with-people-density-map.zip data/ |
|
12 |
|
cd .. |
|
13 |
|
|
|
14 |
|
# put perspective |
|
15 |
|
mv data/perspective-ShanghaiTech/A/train_pmap/ data/ShanghaiTech/part_A/train_data/pmap/ |
|
16 |
|
mv data/perspective-ShanghaiTech/A/test_pmap/ data/ShanghaiTech/part_A/test_data/pmap/ |
|
17 |
|
mv data/perspective-ShanghaiTech/B/train_pmap/ data/ShanghaiTech/part_B/train_data/pmap/ |
|
18 |
|
mv data/perspective-ShanghaiTech/B/test_pmap/ data/ShanghaiTech/part_B/test_data/pmap/ |