Skip to content

Add API usage calls to utils #5077

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 3 commits into from
Dec 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions torchvision/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}")

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down