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

add decode #481

Merged
merged 2 commits into from Feb 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion mmpose/models/detectors/top_down.py
Expand Up @@ -178,7 +178,7 @@ def forward_test(self, img, img_metas, return_heatmap=False, **kwargs):

if self.with_keypoint:
keypoint_result = self.keypoint_head.decode_keypoints(
img_metas, output_heatmap, [img_width, img_height])
img_metas, output_heatmap, img_size=[img_width, img_height])
result.update(keypoint_result)

if not return_heatmap:
Expand Down
19 changes: 19 additions & 0 deletions mmpose/models/keypoint_heads/fc_head.py
Expand Up @@ -115,6 +115,25 @@ def inference_model(self, x, flip_pairs=None):
output_regression = output.detach().cpu().numpy()
return output_regression

def decode(self, img_metas, output, **kwargs):
innerlee marked this conversation as resolved.
Show resolved Hide resolved
"""Decode the output.

Args:
img_metas (list(dict)): Information about data augmentation
By default this includes:
- "image_file: path to the image file
- "center": center of the bbox
- "scale": scale of the bbox
- "rotation": rotation of the bbox
- "bbox_score": score of bbox
output (np.ndarray[N, K, H, W]): model predicted heatmaps.
kwargs: dict contains 'img_size'.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just add img_size to argument list?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay this is part of interface refactoring

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still not sure about this. Leave it to future revision

"""
return self.decode_keypoints(
img_metas=img_metas,
output_regression=output,
img_size=kwargs['img_size'])

def decode_keypoints(self, img_metas, output_regression, img_size):
"""Decode keypoints from output regression.

Expand Down
19 changes: 17 additions & 2 deletions mmpose/models/keypoint_heads/top_down_base_head.py
Expand Up @@ -36,7 +36,23 @@ def forward(self, **kwargs):
def inference_model(self, **kwargs):
"""Inference function."""

def decode_keypoints(self, img_metas, output_heatmap, img_size):
def decode(self, img_metas, output, **kwargs):
"""Decode the output.

Args:
img_metas (list(dict)): Information about data augmentation
By default this includes:
- "image_file: path to the image file
- "center": center of the bbox
- "scale": scale of the bbox
- "rotation": rotation of the bbox
- "bbox_score": score of bbox
output (np.ndarray[N, K, H, W]): model predicted heatmaps.
"""
return self.decode_keypoints(
img_metas=img_metas, output_heatmap=output)

def decode_keypoints(self, img_metas, output_heatmap, **kwargs):
"""Decode keypoints from heatmaps.

Args:
Expand All @@ -48,7 +64,6 @@ def decode_keypoints(self, img_metas, output_heatmap, img_size):
- "rotation": rotation of the bbox
- "bbox_score": score of bbox
output_heatmap (np.ndarray[N, K, H, W]): model predicted heatmaps.
img_size (tuple(img_width, img_height)): model input image size.
"""
batch_size = len(img_metas)

Expand Down