-
Notifications
You must be signed in to change notification settings - Fork 7k
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
SanitizeBoundingBox
based on minimum area
#7735
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/vision/7735
Note: Links to docs will display an error until the docs builds have been completed. ❌ 16 New Failures, 14 Unrelated FailuresAs of commit 73212ca with merge base f7d9e75 (): NEW FAILURES - The following jobs have failed:
FLAKY - The following jobs failed but were likely due to flakiness present on trunk:
BROKEN TRUNK - The following job failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
Hi @antoinebrl! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
Thanks for the PR @antoinebrl , I'm curious about the applications where you found this feature useful? |
Hi @NicolasHug. Filtering by either size and/or area allows for more control when selecting bounding boxes with different aspect ratios. The smallest edge of a rectangle can be smaller than the sides of a square but the rectangle can occupy more space. |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Isn't passing |
If you have square bounding boxes this would be equivalent indeed. However, if there are rectangles with one side ~3-4x longer than the other one, they cover a much larger area than squares with the same small edge. One might want to drop the small squares and keep the rectangles. This effect can be accentuated when resizing images without keeping the aspect ratio. |
To be clear, taking |
Here is "proof" of Nicolas statement above
Assume
With => |
Thanks for the sketch @antoinebrl! Here is a snippet to play with it: import math
import torch
from torchvision import datapoints
import torchvision.transforms.v2 as transforms
from torchvision.utils import draw_bounding_boxes
from torchvision.ops import box_area
from torchvision.transforms.v2 import functional as F
def draw(bounding_boxes, *, name):
image = torch.zeros((3, *bounding_boxes.spatial_size), dtype=torch.uint8)
annotated_image = draw_bounding_boxes(image, bounding_boxes, colors=["red", "green", "blue"])
F.to_image_pil(annotated_image).save(f"{name}.png")
input = datapoints.BoundingBox(
[
[20, 20, 360, 80], # large rectangle
[40, 40, 380, 60], # small rectangle
[30, 30, 70, 70], # black square
],
format=datapoints.BoundingBoxFormat.XYXY,
spatial_size=(100, 400),
)
draw(input, name="input")
areas = box_area(input)
square_area = int(areas[2])
transform = transforms.SanitizeBoundingBox(min_size=math.sqrt(square_area) + 1, labels_getter=None)
draw(transform(input), name="output_min_size")
transform = transforms.SanitizeBoundingBox(min_area=square_area + 1, labels_getter=None)
draw(transform(input), name="output_min_area") You are right that just |
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 see, thanks for clarifying @antoinebrl . This is indeed not equivalent.
I wonder if we should just accept a filter callable (in addition to min_size
which I think we should keep) so that users can pass arbitrary filters. @pmeier ?
Didn't mean to approve just now, sorry (brain fart)
IMO |
I'm not convinced TBH. How do we justify |
Alright, let's go with |
Summary: Co-authored-by: Nicolas Hug <contact@nicolas-hug.com> Reviewed By: vmoens Differential Revision: D58283864 fbshipit-source-id: d598aa25d3d581b1af0f35d082fc050b353488ba
During transformations, bounding boxes can be filtered based on minimum size and area.
cc @vfdev-5