-
-
Notifications
You must be signed in to change notification settings - Fork 980
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
Support instance masks (N,H,W) #2856
Conversation
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.
Meanwhile, what we did for the boxes is to merge them all into one tensor, which is
kornia/kornia/geometry/boxes.py
Lines 20 to 33 in 46a5e40
def _merge_box_list(boxes: list[torch.Tensor], method: str = "pad") -> tuple[torch.Tensor, list[int]]: | |
r"""Merge a list of boxes into one tensor.""" | |
if not all(box.shape[-2:] == torch.Size([4, 2]) and box.dim() == 3 for box in boxes): | |
raise TypeError(f"Input boxes must be a list of (N, 4, 2) shaped. Got: {[box.shape for box in boxes]}.") | |
if method == "pad": | |
max_N = max(box.shape[0] for box in boxes) | |
stats = [max_N - box.shape[0] for box in boxes] | |
output = torch.nn.utils.rnn.pad_sequence(boxes, batch_first=True) | |
else: | |
raise NotImplementedError(f"`{method}` is not implemented.") | |
return output, stats | |
Not sure if we should do the same to the masks. Can anyone benchmark on which approach runs faster? Iteration or batching?
Merging a list of tensors into tensors will not work for instance segmentation. This is because each image will have a different number of objects and so different number of masks. Because of this, they cannot be batched. This is how it would look like:
Refer to #2417 for a proper example of this use case. |
I meant that N_max = max(N1, ..., Nb)
padding = [N_max - N1, ..., N_max - Nb]
padded_masks = (B, N_max, H, W)
... # After augmentation
Unpad (B, N_max, H, W) => Mask ([(N1, H, W), (N2, H, W) ... (Nb, H, W)]) The current change is fine in this PR I think. We should benchmark the iterative and batching strategies to see how those methods perform. Maybe a |
* Fix for shape error in transform_masks * Iterate over batch_prob in transform_list * Run ruff * Revert prev changes * Update test case
Changes
Fixes #2855 related to #941
Type of change
Checklist