| import numpy as np |
|
|
| from d_cube.vis_util import plot_hist |
| from d_cube import D3 |
|
|
|
|
| def vis_num_instance(cat_obj_count): |
| |
|
|
| |
| total_instances_per_image = np.sum(cat_obj_count, axis=0) |
|
|
| |
| |
| |
| |
| |
|
|
| |
| |
| |
| plot_hist( |
| total_instances_per_image, |
| bins=max(total_instances_per_image) - min(total_instances_per_image) + 1, |
| save_path="vis_fig/instance_dist_hist.pdf", |
| ) |
|
|
|
|
| def vis_num_category(cat_obj_count): |
| |
|
|
| |
| num_categories_per_image = np.sum(cat_obj_count > 0, axis=0) |
|
|
| |
| |
| |
| |
| |
|
|
| |
| |
| |
| plot_hist( |
| num_categories_per_image, |
| bins=max(num_categories_per_image) - min(num_categories_per_image) + 1, |
| save_path="vis_fig/category_dist_hist.pdf", |
| ) |
|
|
|
|
| def vis_num_img_per_cat(cat_obj_count): |
| num_img_per_cat = np.sum(cat_obj_count > 0, axis=1) |
| plot_hist( |
| num_img_per_cat, |
| bins=20, |
| save_path="vis_fig/nimg_pcat_hist.pdf", |
| x="Num. of images", |
| ) |
|
|
|
|
| def vis_num_box_per_cat(cat_obj_count): |
| num_box_per_cat = np.sum(cat_obj_count, axis=1) |
| plot_hist( |
| num_box_per_cat, |
| bins=20, |
| save_path="vis_fig/nbox_pcat_hist.pdf", |
| x="Num. of instances", |
| ) |
|
|
|
|
| def vis_num_box_per_cat_per_img(cat_obj_count): |
| img_obj_count = cat_obj_count.reshape(-1) |
| plot_hist( |
| img_obj_count[img_obj_count > 0], |
| bins=max(img_obj_count) - min(img_obj_count) + 1, |
| save_path="vis_fig/nbox_pcat_pimg_hist.pdf", |
| x="Num. of instances on a image", |
| ) |
|
|
|
|
| if __name__ == "__main__": |
| IMG_ROOT = None |
| PKL_ANNO_PATH = None |
| assert IMG_ROOT is not None, "Please set IMG_ROOT in the script first" |
| assert PKL_ANNO_PATH is not None, "Please set PKL_ANNO_PATH in the script first" |
| d3 = D3(IMG_ROOT, PKL_ANNO_PATH) |
|
|
| cat_obj_count = d3.bbox_num_analyze() |
| vis_num_instance(cat_obj_count) |
| vis_num_category(cat_obj_count) |
| vis_num_img_per_cat(cat_obj_count) |
| vis_num_box_per_cat(cat_obj_count) |
| vis_num_box_per_cat_per_img(cat_obj_count) |
|
|
| d3.stat_description(with_rev=False) |
| d3.stat_description(with_rev=True) |
| d3.stat_description(with_rev=False, inter_group=True) |
| d3.stat_description(with_rev=True, inter_group=True) |
|
|