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
c34a9145
Unverified
Commit
c34a9145
authored
Dec 10, 2021
by
Zhiqiang Wang
Committed by
GitHub
Dec 09, 2021
Browse files
Add API usage calls to utils (#5077)
* Add API usage calls to utils * Update to the new api
parent
1b14829c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
0 deletions
+5
-0
torchvision/utils.py
torchvision/utils.py
+5
-0
No files found.
torchvision/utils.py
View file @
c34a9145
...
...
@@ -42,6 +42,7 @@ def make_grid(
Returns:
grid (Tensor): the tensor containing grid of images.
"""
_log_api_usage_once
(
"utils"
,
"make_grid"
)
if
not
(
torch
.
is_tensor
(
tensor
)
or
(
isinstance
(
tensor
,
list
)
and
all
(
torch
.
is_tensor
(
t
)
for
t
in
tensor
))):
raise
TypeError
(
f
"tensor or list of tensors expected, got
{
type
(
tensor
)
}
"
)
...
...
@@ -130,6 +131,7 @@ def save_image(
**kwargs: Other arguments are documented in ``make_grid``.
"""
_log_api_usage_once
(
"utils"
,
"save_image"
)
grid
=
make_grid
(
tensor
,
**
kwargs
)
# Add 0.5 after unnormalizing to [0, 255] to round to nearest integer
ndarr
=
grid
.
mul
(
255
).
add_
(
0.5
).
clamp_
(
0
,
255
).
permute
(
1
,
2
,
0
).
to
(
"cpu"
,
torch
.
uint8
).
numpy
()
...
...
@@ -174,6 +176,7 @@ def draw_bounding_boxes(
img (Tensor[C, H, W]): Image Tensor of dtype uint8 with bounding boxes plotted.
"""
_log_api_usage_once
(
"utils"
,
"draw_bounding_boxes"
)
if
not
isinstance
(
image
,
torch
.
Tensor
):
raise
TypeError
(
f
"Tensor expected, got
{
type
(
image
)
}
"
)
elif
image
.
dtype
!=
torch
.
uint8
:
...
...
@@ -252,6 +255,7 @@ def draw_segmentation_masks(
img (Tensor[C, H, W]): Image Tensor, with segmentation masks drawn on top.
"""
_log_api_usage_once
(
"utils"
,
"draw_segmentation_masks"
)
if
not
isinstance
(
image
,
torch
.
Tensor
):
raise
TypeError
(
f
"The image must be a tensor, got
{
type
(
image
)
}
"
)
elif
image
.
dtype
!=
torch
.
uint8
:
...
...
@@ -329,6 +333,7 @@ def draw_keypoints(
img (Tensor[C, H, W]): Image Tensor of dtype uint8 with keypoints drawn.
"""
_log_api_usage_once
(
"utils"
,
"draw_keypoints"
)
if
not
isinstance
(
image
,
torch
.
Tensor
):
raise
TypeError
(
f
"The image must be a tensor, got
{
type
(
image
)
}
"
)
elif
image
.
dtype
!=
torch
.
uint8
:
...
...
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