-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[Feature] Add visibility prediction head #2417
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
[Feature] Add visibility prediction head #2417
Conversation
for index in range(len(pose_pred_instances)): | ||
pose_pred_instances[index].keypoint_visibility = batch_vis_np[ | ||
index] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why has a loop been utilized here? BTW, the visibility representation in 'pred_instances' is denoted by 'keypoint_scores'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why has a loop been utilized here? BTW, the visibility representation in 'pred_instances' is denoted by 'keypoint_scores'
Thanks for your advise. I will rewrite this part soon, sorry for the bad code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry, my tone may have led to a misunderstanding. I was just unclear whether 'pose_pred_instances' is a tuple or InstanceData, so I wanted to ask if there is a possibility of not using a loop. Take it easy~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry, my tone may have led to a misunderstanding. I was just unclear whether 'pose_pred_instances' is a tuple or InstanceData, so I wanted to ask if there is a possibility of not using a loop. Take it easy~
Got it! Sorry for the late reply.
From my perspective, 'pose_pred_instances' is an 'InstanceList'?
mmpose/mmpose/models/heads/base_head.py
Lines 78 to 81 in 2c4a60e
preds = [ InstanceData(keypoints=keypoints, keypoint_scores=scores) for keypoints, scores in zip(batch_keypoints, batch_scores) ]
mmpose/mmpose/models/heads/heatmap_heads/heatmap_head.py
Lines 235 to 241 in 2c4a60e
Returns: Union[InstanceList | Tuple[InstanceList | PixelDataList]]: If ``test_cfg['output_heatmap']==True``, return both pose and heatmap prediction; otherwise only return the pose prediction. The pose prediction is a list of ``InstanceData``, each contains the following fields:
Besides that, I have refined the code. If I still get something wrong, please let me know. Thanks.
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## dev-1.x #2417 +/- ##
===========================================
+ Coverage 80.67% 80.79% +0.12%
===========================================
Files 250 251 +1
Lines 15112 15208 +96
Branches 2618 2632 +14
===========================================
+ Hits 12191 12288 +97
+ Misses 2267 2257 -10
- Partials 654 663 +9
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Sentry. |
4794d2a
to
582f26c
Compare
if not self.use_sigmoid: | ||
batch_vis = torch.sigmoid(batch_vis) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is sigmoid
applied to batch_vis
when use_sigmoid
is False
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the value of visibility prediction should be between 0 and 1? If use_sigmoid
is False
, there won't be sigmoid in vis_forward
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the sigmoid function is always applied to the head outputs, what is the role of the use_sigmoid
argument?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is
sigmoid
applied tobatch_vis
whenuse_sigmoid
isFalse
?
@Ben-Louis When use_sigmoid
is True, a nn.Sigmoid()
will be in the vis_head
, namely, the batch_vis
is between 0~1. Otherwise, we need to do sigmoid manually when use_sigmoid
is False.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using nn.Sigmoid()
and BCELoss
separately is not officially recommended by Pytorch, a better way is to use BCEWithLogitsLoss
and do sigmoid manually when a 0-1 score is needed. So I suggest him to set a use_sigmoid
to keep the flexity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Tau-J, thanks for the clarification. This can indeed be puzzling, perhaps we could add some comments for clarity? Also, focusing on a single recommended practice could be beneficial. BTW, in MMDetection, this parameter is generally integrated in loss modules like mmdet.CrossEntropyLoss
. We might consider refining the BCELoss
module with this parameter, rather than introducing a completely new loss module.
582f26c
to
1ee410a
Compare
Motivation
Enable top-down methods to predict keypoints visibility
Modification
vis_head
in hybrid_heads (mmpose/mmpose/models/heads/hybrid_heads/vis_head.py)flip_visibility
(mmpose/mmpose/models/utils/tta.py)transformed_keypoints_visible
inlabel_mapping_table
(mmpose/mmpose/datasets/transforms/formatting.py)keypoints_visible
inGenerateTarget
(mmpose/mmpose/datasets/transforms/common_transforms.py)add a new loss functionBCEWithLogitsLoss
(mmpose/mmpose/models/losses/classification_loss.py)BCELoss
module: add parameterwith_logits
to decide whether to use BCEWithLogitsLoss (mmpose/mmpose/models/losses/classification_loss.py)vis_head
(mmpose/tests/test_models/test_heads/test_hybrid_heads/test_vis_head.py)BC-breaking (Optional)
Use cases (Optional)
We can use
vis_head
to wrap a keypoints prediction head, getting the keypoints prediction results with keypoints visibility.For example, in config file:
Checklist
Before PR:
After PR: