Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Fix keypoint_scores in visualization #1671

Merged
merged 4 commits into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -225,8 +225,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:
Ben-Louis marked this conversation as resolved.
Show resolved Hide resolved
scores = instances.keypoint_scores
else:
scores = [np.ones(len(kpts)) for kpts in keypoints]

Expand Down Expand Up @@ -259,7 +259,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 @@ -313,9 +315,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