Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
vision
Commits
850491eb
"vscode:/vscode.git/clone" did not exist on "bd4647d1db12e88c58446505f5a8e4ab068978e2"
Unverified
Commit
850491eb
authored
Jun 23, 2021
by
Sepehr Sameni
Committed by
GitHub
Jun 23, 2021
Browse files
Support single color in utils.draw_bounding_boxes (#4075)
parent
eb1b9827
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
4 deletions
+19
-4
test/test_utils.py
test/test_utils.py
+12
-0
torchvision/utils.py
torchvision/utils.py
+7
-4
No files found.
test/test_utils.py
View file @
850491eb
...
@@ -113,6 +113,18 @@ def test_draw_boxes():
...
@@ -113,6 +113,18 @@ def test_draw_boxes():
assert_equal
(
img
,
img_cp
)
assert_equal
(
img
,
img_cp
)
@
pytest
.
mark
.
parametrize
(
'colors'
,
[
None
,
[
'red'
,
'blue'
,
'#FF00FF'
,
(
1
,
34
,
122
)],
'red'
,
'#FF00FF'
,
(
1
,
34
,
122
)
])
def
test_draw_boxes_colors
(
colors
):
img
=
torch
.
full
((
3
,
100
,
100
),
0
,
dtype
=
torch
.
uint8
)
utils
.
draw_bounding_boxes
(
img
,
boxes
,
fill
=
False
,
width
=
7
,
colors
=
colors
)
def
test_draw_boxes_vanilla
():
def
test_draw_boxes_vanilla
():
img
=
torch
.
full
((
3
,
100
,
100
),
0
,
dtype
=
torch
.
uint8
)
img
=
torch
.
full
((
3
,
100
,
100
),
0
,
dtype
=
torch
.
uint8
)
img_cp
=
img
.
clone
()
img_cp
=
img
.
clone
()
...
...
torchvision/utils.py
View file @
850491eb
...
@@ -141,7 +141,7 @@ def draw_bounding_boxes(
...
@@ -141,7 +141,7 @@ def draw_bounding_boxes(
image
:
torch
.
Tensor
,
image
:
torch
.
Tensor
,
boxes
:
torch
.
Tensor
,
boxes
:
torch
.
Tensor
,
labels
:
Optional
[
List
[
str
]]
=
None
,
labels
:
Optional
[
List
[
str
]]
=
None
,
colors
:
Optional
[
List
[
Union
[
str
,
Tuple
[
int
,
int
,
int
]]]]
=
None
,
colors
:
Optional
[
Union
[
List
[
Union
[
str
,
Tuple
[
int
,
int
,
int
]]]
,
str
,
Tuple
[
int
,
int
,
int
]]
]
=
None
,
fill
:
Optional
[
bool
]
=
False
,
fill
:
Optional
[
bool
]
=
False
,
width
:
int
=
1
,
width
:
int
=
1
,
font
:
Optional
[
str
]
=
None
,
font
:
Optional
[
str
]
=
None
,
...
@@ -159,8 +159,9 @@ def draw_bounding_boxes(
...
@@ -159,8 +159,9 @@ def draw_bounding_boxes(
the boxes are absolute coordinates with respect to the image. In other words: `0 <= xmin < xmax < W` and
the boxes are absolute coordinates with respect to the image. In other words: `0 <= xmin < xmax < W` and
`0 <= ymin < ymax < H`.
`0 <= ymin < ymax < H`.
labels (List[str]): List containing the labels of bounding boxes.
labels (List[str]): List containing the labels of bounding boxes.
colors (List[Union[str, Tuple[int, int, int]]]): List containing the colors of bounding boxes. The colors can
colors (Union[List[Union[str, Tuple[int, int, int]]], str, Tuple[int, int, int]]): List containing the colors
be represented as `str` or `Tuple[int, int, int]`.
or a single color for all of the bounding boxes. The colors can be represented as `str` or
`Tuple[int, int, int]`.
fill (bool): If `True` fills the bounding box with specified color.
fill (bool): If `True` fills the bounding box with specified color.
width (int): Width of bounding box.
width (int): Width of bounding box.
font (str): A filename containing a TrueType font. If the file is not found in this filename, the loader may
font (str): A filename containing a TrueType font. If the file is not found in this filename, the loader may
...
@@ -200,8 +201,10 @@ def draw_bounding_boxes(
...
@@ -200,8 +201,10 @@ def draw_bounding_boxes(
for
i
,
bbox
in
enumerate
(
img_boxes
):
for
i
,
bbox
in
enumerate
(
img_boxes
):
if
colors
is
None
:
if
colors
is
None
:
color
=
None
color
=
None
el
se
:
el
if
isinstance
(
colors
,
list
)
:
color
=
colors
[
i
]
color
=
colors
[
i
]
else
:
color
=
colors
if
fill
:
if
fill
:
if
color
is
None
:
if
color
is
None
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment