From 56cbf2661e8958e0f34800dcd6861572a627b8de Mon Sep 17 00:00:00 2001 From: Zhiqiang Wang Date: Thu, 9 Dec 2021 19:06:45 +0800 Subject: [PATCH 1/2] Add API usage calls to utils --- torchvision/utils.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/torchvision/utils.py b/torchvision/utils.py index f45b1271cb6..0aa1cba862b 100644 --- a/torchvision/utils.py +++ b/torchvision/utils.py @@ -42,6 +42,7 @@ def make_grid( Returns: grid (Tensor): the tensor containing grid of images. """ + _log_api_usage_once("torchvision.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("torchvision.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("torchvision.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("torchvision.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("torchvision.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: From 69dbd21c860272327d7ac2246c973f5689b9625a Mon Sep 17 00:00:00 2001 From: Zhiqiang Wang Date: Fri, 10 Dec 2021 03:28:04 +0800 Subject: [PATCH 2/2] Update to the new api --- torchvision/utils.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/torchvision/utils.py b/torchvision/utils.py index 0aa1cba862b..3a17a46e26e 100644 --- a/torchvision/utils.py +++ b/torchvision/utils.py @@ -42,7 +42,7 @@ def make_grid( Returns: grid (Tensor): the tensor containing grid of images. """ - _log_api_usage_once("torchvision.utils.make_grid") + _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)}") @@ -131,7 +131,7 @@ def save_image( **kwargs: Other arguments are documented in ``make_grid``. """ - _log_api_usage_once("torchvision.utils.save_image") + _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() @@ -176,7 +176,7 @@ def draw_bounding_boxes( img (Tensor[C, H, W]): Image Tensor of dtype uint8 with bounding boxes plotted. """ - _log_api_usage_once("torchvision.utils.draw_bounding_boxes") + _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: @@ -255,7 +255,7 @@ def draw_segmentation_masks( img (Tensor[C, H, W]): Image Tensor, with segmentation masks drawn on top. """ - _log_api_usage_once("torchvision.utils.draw_segmentation_masks") + _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: @@ -333,7 +333,7 @@ def draw_keypoints( img (Tensor[C, H, W]): Image Tensor of dtype uint8 with keypoints drawn. """ - _log_api_usage_once("torchvision.utils.draw_keypoints") + _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: