From 067d4aa58d4ea9937b63508468ec5943b76fe48c Mon Sep 17 00:00:00 2001 From: c1aris Date: Tue, 7 Apr 2020 12:54:27 +0800 Subject: [PATCH 1/4] Support empty predictions when visualizing results --- tools/visualize_json_results.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/visualize_json_results.py b/tools/visualize_json_results.py index 5b369a12e1..b8b81ded4f 100755 --- a/tools/visualize_json_results.py +++ b/tools/visualize_json_results.py @@ -22,6 +22,9 @@ def create_instances(predictions, image_size): score = np.asarray([x["score"] for x in predictions]) chosen = (score > args.conf_threshold).nonzero()[0] score = score[chosen] + if score.shape[0] == 0: + return None + bbox = np.asarray([predictions[i]["bbox"] for i in chosen]) bbox = BoxMode.convert(bbox, BoxMode.XYWH_ABS, BoxMode.XYXY_ABS) @@ -80,6 +83,9 @@ def dataset_id_map(ds_id): basename = os.path.basename(dic["file_name"]) predictions = create_instances(pred_by_image[dic["image_id"]], img.shape[:2]) + if predictions is None: + continue + vis = Visualizer(img, metadata) vis_pred = vis.draw_instance_predictions(predictions).get_image() From a79e4ddc9e2399b27b6f39be69659f759e19dcbe Mon Sep 17 00:00:00 2001 From: c1aris Date: Tue, 7 Apr 2020 13:07:35 +0800 Subject: [PATCH 2/4] Return ret instead of None --- tools/visualize_json_results.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tools/visualize_json_results.py b/tools/visualize_json_results.py index b8b81ded4f..43a6d537ef 100755 --- a/tools/visualize_json_results.py +++ b/tools/visualize_json_results.py @@ -23,7 +23,7 @@ def create_instances(predictions, image_size): chosen = (score > args.conf_threshold).nonzero()[0] score = score[chosen] if score.shape[0] == 0: - return None + return ret bbox = np.asarray([predictions[i]["bbox"] for i in chosen]) bbox = BoxMode.convert(bbox, BoxMode.XYWH_ABS, BoxMode.XYXY_ABS) @@ -83,9 +83,6 @@ def dataset_id_map(ds_id): basename = os.path.basename(dic["file_name"]) predictions = create_instances(pred_by_image[dic["image_id"]], img.shape[:2]) - if predictions is None: - continue - vis = Visualizer(img, metadata) vis_pred = vis.draw_instance_predictions(predictions).get_image() From 1938082033eaa123e35db7321f925843b873d198 Mon Sep 17 00:00:00 2001 From: c1aris Date: Tue, 7 Apr 2020 15:11:29 +0800 Subject: [PATCH 3/4] Check the shape of 'chosen' instead of 'score' --- tools/visualize_json_results.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tools/visualize_json_results.py b/tools/visualize_json_results.py index 43a6d537ef..4a6a6f3021 100755 --- a/tools/visualize_json_results.py +++ b/tools/visualize_json_results.py @@ -21,10 +21,9 @@ def create_instances(predictions, image_size): score = np.asarray([x["score"] for x in predictions]) chosen = (score > args.conf_threshold).nonzero()[0] + if chosen.shape[0] == 0: + return None score = score[chosen] - if score.shape[0] == 0: - return ret - bbox = np.asarray([predictions[i]["bbox"] for i in chosen]) bbox = BoxMode.convert(bbox, BoxMode.XYWH_ABS, BoxMode.XYXY_ABS) From 7e33bc85a4c8c26f7da527f63676dfd92666c577 Mon Sep 17 00:00:00 2001 From: c1aris Date: Tue, 7 Apr 2020 15:20:56 +0800 Subject: [PATCH 4/4] Reshape 'bbox' before converting --- tools/visualize_json_results.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tools/visualize_json_results.py b/tools/visualize_json_results.py index 4a6a6f3021..d11ecb9038 100755 --- a/tools/visualize_json_results.py +++ b/tools/visualize_json_results.py @@ -21,10 +21,8 @@ def create_instances(predictions, image_size): score = np.asarray([x["score"] for x in predictions]) chosen = (score > args.conf_threshold).nonzero()[0] - if chosen.shape[0] == 0: - return None score = score[chosen] - bbox = np.asarray([predictions[i]["bbox"] for i in chosen]) + bbox = np.asarray([predictions[i]["bbox"] for i in chosen]).reshape(-1, 4) bbox = BoxMode.convert(bbox, BoxMode.XYWH_ABS, BoxMode.XYXY_ABS) labels = np.asarray([dataset_id_map(predictions[i]["category_id"]) for i in chosen])