Skip to content

Fix IndexError on draw_segmentation_masks and draw_bounding_boxes #5857

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

Merged
merged 11 commits into from
May 23, 2022

Conversation

oxabz
Copy link
Contributor

@oxabz oxabz commented Apr 21, 2022

Closes #5818

@facebook-github-bot
Copy link

Hi @oxabz!

Thank you for your pull request and welcome to our community.

Action Required

In 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.

Process

In 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 CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@oxabz oxabz changed the title Fix IndexError on draw_segmentation_masks and `` Fix IndexError on draw_segmentation_masks and draw_bounding_boxes Apr 21, 2022
@oxabz oxabz changed the title Fix IndexError on draw_segmentation_masks and draw_bounding_boxes WIP: Fix IndexError on draw_segmentation_masks and draw_bounding_boxes Apr 21, 2022
@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

Copy link
Contributor

@oke-aditya oke-aditya left a comment

Choose a reason for hiding this comment

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

Small comment. Also can you add tests in test_utils.py ?

@@ -206,6 +206,10 @@ def draw_bounding_boxes(

num_boxes = boxes.shape[0]

if num_boxes == 0:
warnings.warn("boxes doesn't contain any box. No box was drawn")
return image.to(torch.uint8)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you don't ned to do this as the image dtype is unit8 in the input.

@@ -306,6 +310,12 @@ def draw_segmentation_masks(
if colors is not None and num_masks > len(colors):
raise ValueError(f"There are more masks ({num_masks}) than colors ({len(colors)})")

out_dtype = torch.uint8
Copy link
Contributor

Choose a reason for hiding this comment

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

Same. No need of this, only uint8 images are allowed

@datumbox datumbox requested a review from NicolasHug April 22, 2022 10:07
Copy link
Contributor

@oke-aditya oke-aditya left a comment

Choose a reason for hiding this comment

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

Looks great. cc @NicolasHug for a look :)

@@ -4,6 +4,8 @@
import tempfile
from io import BytesIO

import warnings
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
import warnings

@NicolasHug
Copy link
Member

Hi @oxabz , thanks for the PR. Is it still WIP or is it ready for reviews?

@oxabz oxabz changed the title WIP: Fix IndexError on draw_segmentation_masks and draw_bounding_boxes Fix IndexError on draw_segmentation_masks and draw_bounding_boxes May 2, 2022
Copy link
Member

@NicolasHug NicolasHug left a comment

Choose a reason for hiding this comment

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

Looks great, thanks a lot both of you @oxabz @oke-aditya

I'll merge when green

@NicolasHug
Copy link
Member

linux unittest are passing , merging. (MacOS and ONNX notoriously toasted ATM).
Thanks again!

@NicolasHug NicolasHug merged commit 5486b76 into pytorch:main May 23, 2022
@github-actions
Copy link

Hey @NicolasHug!

You merged this PR, but no labels were added. The list of valid labels is available at https://github.com/pytorch/vision/blob/main/.github/process_commit.py

facebook-github-bot pushed a commit that referenced this pull request Jun 1, 2022
…ation_masks and draw_bounding_boxes (#5857)

Summary:
* Fixing the IndexError in draw_segmentation_masks

* fixing the bug on draw_bounding_boxes

* Changing fstring to normal string

* Removing unecessary conversion

* Adding test for the change

* Adding a test for draw seqmentation mask

* Fixing small mistake

* Fixing an error in the tests

* removing useless imports

* ufmt

Reviewed By: NicolasHug

Differential Revision: D36760928

fbshipit-source-id: c9acb7854f9f6068d79155aa6975b6224c926cef

Co-authored-by: LEGRAND Matthieu <[email protected]>
Co-authored-by: Nicolas Hug <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

draw_segmentation_masks throws IndexError when given [0, H, W] in mask
4 participants