File dataset_script/jhucrowd_density_map.py changed (mode: 100644) (index 1f75743..a6b63ef) |
... |
... |
def t_single_density_map(): |
84 |
84 |
print(out) |
print(out) |
85 |
85 |
|
|
86 |
86 |
|
|
87 |
|
def print_density_map(density_path, density_img_out): |
|
|
87 |
|
def t_count(density_path, label_path): |
|
88 |
|
gt_file = h5py.File(density_path, 'r') |
|
89 |
|
target = np.asarray(gt_file['density']) |
|
90 |
|
density_count = target.sum() |
|
91 |
|
label_count = len(load_density_label(label_path)) |
|
92 |
|
print("density count ", density_count) |
|
93 |
|
print("label count ", label_count) |
|
94 |
|
print("diff ", density_count - label_count) |
|
95 |
|
print("diff percentage ", (density_count - label_count)/ label_count * 100) |
|
96 |
|
|
|
97 |
|
|
|
98 |
|
def t_print_density_map(density_path, density_img_out): |
88 |
99 |
gt_file = h5py.File(density_path, 'r') |
gt_file = h5py.File(density_path, 'r') |
89 |
100 |
target = np.asarray(gt_file['density']) |
target = np.asarray(gt_file['density']) |
90 |
101 |
save_density_map(target, density_img_out) |
save_density_map(target, density_img_out) |
91 |
102 |
print("done print ", density_img_out) |
print("done print ", density_img_out) |
92 |
103 |
|
|
|
104 |
|
|
|
105 |
|
def full_flow_jhucrowd(root_path): |
|
106 |
|
ROOT = root_path |
|
107 |
|
images_folder = os.path.join(ROOT, "images") |
|
108 |
|
gt_path_folder = os.path.join(ROOT, "gt") |
|
109 |
|
density_path_folder = os.path.join(ROOT, "ground-truth-h5") |
|
110 |
|
img_list = os.listdir(path=images_folder) |
|
111 |
|
os.makedirs(density_path_folder, exist_ok=True) |
|
112 |
|
for img_name in img_list[:3]: |
|
113 |
|
name = img_name.split(".")[0] |
|
114 |
|
density_name = name + ".h5" |
|
115 |
|
gt_name = name + ".txt" |
|
116 |
|
img_path = os.path.join(images_folder, img_name) |
|
117 |
|
gt_path = os.path.join(gt_path_folder, gt_name) |
|
118 |
|
density_path = os.path.join(density_path_folder, density_name) |
|
119 |
|
out = generate_density_map(img_path, gt_path, density_path) |
|
120 |
|
print(out) |
|
121 |
|
print("done") |
|
122 |
|
|
|
123 |
|
|
93 |
124 |
if __name__ == "__main__": |
if __name__ == "__main__": |
|
125 |
|
# full_flow_jhucrowd("/data/jhu_crowd_v2.0/val") |
|
126 |
|
# t_count("/data/jhu_crowd_v2.0/val/unittest/0003.h5", "/data/jhu_crowd_v2.0/val/gt/0003.txt") |
94 |
127 |
# t_single_density_map() |
# t_single_density_map() |
95 |
|
print_density_map("/data/jhu_crowd_v2.0/val/unittest/0003.h5", "/data/jhu_crowd_v2.0/val/unittest/0003.png") |
|
|
128 |
|
|
|
129 |
|
t_print_density_map("/data/jhu_crowd_v2.0/val/ground-truth-h5/3556.h5", "/data/jhu_crowd_v2.0/val/ground-truth-h5/3556.png") |
|
130 |
|
t_print_density_map("/data/jhu_crowd_v2.0/val/ground-truth-h5/1632.h5", |
|
131 |
|
"/data/jhu_crowd_v2.0/val/ground-truth-h5/1632.png") |
96 |
132 |
|
|
97 |
133 |
# ROOT = "/data/jhu_crowd_v2.0/val" |
# ROOT = "/data/jhu_crowd_v2.0/val" |
98 |
134 |
# images_folder = os.path.join(ROOT, "images") |
# images_folder = os.path.join(ROOT, "images") |