Skip to content

Commit

Permalink
[Fix] Fix keypoint_scores in visualization (open-mmlab#1671)
Browse files Browse the repository at this point in the history
* refine demo and visualization

* refine topdown face demo

* resolve comments

* fix keypoint and skeleton transparency

Co-authored-by: lupeng <penglu2097@gmail.com>
  • Loading branch information
2 people authored and ly015 committed Oct 14, 2022
1 parent f26a885 commit 460f24b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
9 changes: 7 additions & 2 deletions demo/topdown_demo_with_mmdet.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def visualize_img(args, img_path, detector, pose_estimator, visualizer,
(pred_instance.bboxes, pred_instance.scores[:, None]), axis=1)
bboxes = bboxes[np.logical_and(pred_instance.labels == args.det_cat_id,
pred_instance.scores > args.bbox_thr)]
bboxes = bboxes[nms(bboxes, 0.3)][:, :4]
bboxes = bboxes[nms(bboxes, args.nms_thr)][:, :4]

# predict keypoints
register_mmpose_modules()
Expand Down Expand Up @@ -98,13 +98,18 @@ def main():
type=float,
default=0.3,
help='Bounding box score threshold')
parser.add_argument(
'--nms-thr',
type=float,
default=0.3,
help='IoU threshold for bounding box NMS')
parser.add_argument(
'--kpt-thr', type=float, default=0.3, help='Keypoint score threshold')
parser.add_argument(
'--draw-heatmap',
action='store_true',
default=False,
help='whether to draw output heatmap')
help='Whether to draw output heatmap')
parser.add_argument(
'--radius',
type=int,
Expand Down
9 changes: 7 additions & 2 deletions demo/topdown_face_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def visualize_img(args, img_path, pose_estimator, visualizer, show_interval):
bboxes = process_face_det_results(face_det_results)

bboxes = np.concatenate((bboxes, np.ones((bboxes.shape[0], 1))), axis=1)
bboxes = bboxes[nms(bboxes, 0.3)][:, :4]
bboxes = bboxes[nms(bboxes, args.nms_thr)][:, :4]

# predict keypoints
pose_results = inference_topdown(pose_estimator, img_path, bboxes)
Expand Down Expand Up @@ -97,13 +97,18 @@ def main():
'Default not saving the visualization images.')
parser.add_argument(
'--device', default='cuda:0', help='Device used for inference')
parser.add_argument(
'--nms-thr',
type=float,
default=0.3,
help='IoU threshold for bounding box NMS')
parser.add_argument(
'--kpt-thr', type=float, default=0.3, help='Keypoint score threshold')
parser.add_argument(
'--draw-heatmap',
action='store_true',
default=False,
help='whether to draw output heatmap')
help='Whether to draw output heatmap')
parser.add_argument(
'--radius',
type=int,
Expand Down
14 changes: 8 additions & 6 deletions mmpose/visualization/local_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ def _draw_instances_kpts(self,
keypoints = instances.get('transformed_keypoints',
instances.keypoints)

if 'scores' in instances and self.show_keypoint_weight:
scores = instances.scores
if 'keypoint_scores' in instances:
scores = instances.keypoint_scores
else:
scores = [np.ones(len(kpts)) for kpts in keypoints]

Expand Down Expand Up @@ -265,7 +265,9 @@ def _draw_instances_kpts(self,
color = kpt_color[kid]
if not isinstance(color, str):
color = tuple(int(c) for c in color)
transparency = max(0, min(1, score[kid])) * self.alpha
transparency = self.alpha
if self.show_keypoint_weight:
transparency *= max(0, min(1, score[kid]))
self.draw_circles(
kpt,
radius=np.array([self.radius]),
Expand Down Expand Up @@ -319,9 +321,9 @@ def _draw_instances_kpts(self,
(int(mX), int(mY)),
(int(length / 2), int(stickwidth)), int(angle),
0, 360, 1)
transparency = max(
0, min(1, 0.5 * (score[sk[0]] +
score[sk[1]]))) * self.alpha
transparency = self.alpha
transparency *= max(
0, min(1, 0.5 * (score[sk[0]] + score[sk[1]])))
self.draw_polygons(
polygons,
edge_colors=color,
Expand Down

0 comments on commit 460f24b

Please sign in to comment.