-
Notifications
You must be signed in to change notification settings - Fork 7.1k
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
NicolasHug
merged 11 commits into
pytorch:main
from
oxabz:fix-draw-seg-mask-index-error
May 23, 2022
+26
−0
Merged
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b00b522
Fixing the IndexError in draw_segmentation_masks
oxabz 6e695ad
fixing the bug on draw_bounding_boxes
b51cbb2
Changing fstring to normal string
a1b91cb
Removing unecessary conversion
d9e4ee1
Adding test for the change
7adff47
Adding a test for draw seqmentation mask
462ba93
Fixing small mistake
32a12b5
Fixing an error in the tests
f527d4e
removing useless imports
82c11c4
Merge branch 'main' into fix-draw-seg-mask-index-error
NicolasHug 0467907
ufmt
NicolasHug File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
||
if labels is None: | ||
labels: Union[List[str], List[None]] = [None] * num_boxes # type: ignore[no-redef] | ||
elif len(labels) != num_boxes: | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same. No need of this, only uint8 images are allowed |
||
|
||
if num_masks == 0: | ||
warnings.warn("masks doesn't contain any mask. No mask was drawn") | ||
return image.to(out_dtype) | ||
|
||
if colors is None: | ||
colors = _generate_color_palette(num_masks) | ||
|
||
|
@@ -316,8 +326,6 @@ def draw_segmentation_masks( | |
if isinstance(colors[0], tuple) and len(colors[0]) != 3: | ||
raise ValueError("It seems that you passed a tuple of colors instead of a list of colors") | ||
|
||
out_dtype = torch.uint8 | ||
|
||
colors_ = [] | ||
for color in colors: | ||
if isinstance(color, str): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 you don't ned to do this as the image dtype is unit8 in the input.