diff --git a/torchvision/datasets/vision.py b/torchvision/datasets/vision.py index cd4399c6c79..fc01798c9e6 100644 --- a/torchvision/datasets/vision.py +++ b/torchvision/datasets/vision.py @@ -35,7 +35,7 @@ def __init__( transform: Optional[Callable] = None, target_transform: Optional[Callable] = None, ) -> None: - _log_api_usage_once("datasets", self.__class__.__name__) + _log_api_usage_once(self.__class__.__qualname__) if isinstance(root, torch._six.string_classes): root = os.path.expanduser(root) self.root = root diff --git a/torchvision/models/alexnet.py b/torchvision/models/alexnet.py index ae36054386f..0f88ecb8a5e 100644 --- a/torchvision/models/alexnet.py +++ b/torchvision/models/alexnet.py @@ -18,7 +18,7 @@ class AlexNet(nn.Module): def __init__(self, num_classes: int = 1000, dropout: float = 0.5) -> None: super().__init__() - _log_api_usage_once("models", self.__class__.__name__) + _log_api_usage_once(self.__class__.__qualname__) self.features = nn.Sequential( nn.Conv2d(3, 64, kernel_size=11, stride=4, padding=2), nn.ReLU(inplace=True), diff --git a/torchvision/models/densenet.py b/torchvision/models/densenet.py index 289c027f94d..6ff63d3f53f 100644 --- a/torchvision/models/densenet.py +++ b/torchvision/models/densenet.py @@ -163,7 +163,7 @@ def __init__( ) -> None: super().__init__() - _log_api_usage_once("models", self.__class__.__name__) + _log_api_usage_once(self.__class__.__qualname__) # First convolution self.features = nn.Sequential( diff --git a/torchvision/models/detection/generalized_rcnn.py b/torchvision/models/detection/generalized_rcnn.py index b92f8637d6d..5537be3a8e6 100644 --- a/torchvision/models/detection/generalized_rcnn.py +++ b/torchvision/models/detection/generalized_rcnn.py @@ -27,7 +27,7 @@ class GeneralizedRCNN(nn.Module): def __init__(self, backbone: nn.Module, rpn: nn.Module, roi_heads: nn.Module, transform: nn.Module) -> None: super().__init__() - _log_api_usage_once("models", self.__class__.__name__) + _log_api_usage_once(self.__class__.__qualname__) self.transform = transform self.backbone = backbone self.rpn = rpn diff --git a/torchvision/models/detection/retinanet.py b/torchvision/models/detection/retinanet.py index d123f5bd6ff..c4b9f9555de 100644 --- a/torchvision/models/detection/retinanet.py +++ b/torchvision/models/detection/retinanet.py @@ -337,7 +337,7 @@ def __init__( topk_candidates=1000, ): super().__init__() - _log_api_usage_once("models", self.__class__.__name__) + _log_api_usage_once(self.__class__.__qualname__) if not hasattr(backbone, "out_channels"): raise ValueError( diff --git a/torchvision/models/detection/ssd.py b/torchvision/models/detection/ssd.py index 5df8138ecef..8052225173b 100644 --- a/torchvision/models/detection/ssd.py +++ b/torchvision/models/detection/ssd.py @@ -182,7 +182,7 @@ def __init__( positive_fraction: float = 0.25, ): super().__init__() - _log_api_usage_once("models", self.__class__.__name__) + _log_api_usage_once(self.__class__.__qualname__) self.backbone = backbone diff --git a/torchvision/models/detection/ssdlite.py b/torchvision/models/detection/ssdlite.py index f434a865763..02d92735f37 100644 --- a/torchvision/models/detection/ssdlite.py +++ b/torchvision/models/detection/ssdlite.py @@ -120,7 +120,7 @@ def __init__( min_depth: int = 16, ): super().__init__() - _log_api_usage_once("models", self.__class__.__name__) + _log_api_usage_once(self.__class__.__qualname__) assert not backbone[c4_pos].use_res_connect self.features = nn.Sequential( diff --git a/torchvision/models/efficientnet.py b/torchvision/models/efficientnet.py index 249e2400f63..e0d0af05af4 100644 --- a/torchvision/models/efficientnet.py +++ b/torchvision/models/efficientnet.py @@ -170,7 +170,7 @@ def __init__( norm_layer (Optional[Callable[..., nn.Module]]): Module specifying the normalization layer to use """ super().__init__() - _log_api_usage_once("models", self.__class__.__name__) + _log_api_usage_once(self.__class__.__qualname__) if not inverted_residual_setting: raise ValueError("The inverted_residual_setting should not be empty") diff --git a/torchvision/models/googlenet.py b/torchvision/models/googlenet.py index 476da0d8a53..f98e2109e27 100644 --- a/torchvision/models/googlenet.py +++ b/torchvision/models/googlenet.py @@ -39,7 +39,7 @@ def __init__( dropout_aux: float = 0.7, ) -> None: super().__init__() - _log_api_usage_once("models", self.__class__.__name__) + _log_api_usage_once(self.__class__.__qualname__) if blocks is None: blocks = [BasicConv2d, Inception, InceptionAux] if init_weights is None: diff --git a/torchvision/models/inception.py b/torchvision/models/inception.py index 85236c6dfb3..35d68beea8b 100644 --- a/torchvision/models/inception.py +++ b/torchvision/models/inception.py @@ -37,7 +37,7 @@ def __init__( dropout: float = 0.5, ) -> None: super().__init__() - _log_api_usage_once("models", self.__class__.__name__) + _log_api_usage_once(self.__class__.__qualname__) if inception_blocks is None: inception_blocks = [BasicConv2d, InceptionA, InceptionB, InceptionC, InceptionD, InceptionE, InceptionAux] if init_weights is None: diff --git a/torchvision/models/mnasnet.py b/torchvision/models/mnasnet.py index bff4e061a72..c657c4fba08 100644 --- a/torchvision/models/mnasnet.py +++ b/torchvision/models/mnasnet.py @@ -98,7 +98,7 @@ class MNASNet(torch.nn.Module): def __init__(self, alpha: float, num_classes: int = 1000, dropout: float = 0.2) -> None: super().__init__() - _log_api_usage_once("models", self.__class__.__name__) + _log_api_usage_once(self.__class__.__qualname__) assert alpha > 0.0 self.alpha = alpha self.num_classes = num_classes diff --git a/torchvision/models/mobilenetv2.py b/torchvision/models/mobilenetv2.py index 1e21f299654..a3a41200ec5 100644 --- a/torchvision/models/mobilenetv2.py +++ b/torchvision/models/mobilenetv2.py @@ -111,7 +111,7 @@ def __init__( """ super().__init__() - _log_api_usage_once("models", self.__class__.__name__) + _log_api_usage_once(self.__class__.__qualname__) if block is None: block = InvertedResidual diff --git a/torchvision/models/mobilenetv3.py b/torchvision/models/mobilenetv3.py index 306fa8d2b49..13bc88a2041 100644 --- a/torchvision/models/mobilenetv3.py +++ b/torchvision/models/mobilenetv3.py @@ -151,7 +151,7 @@ def __init__( dropout (float): The droupout probability """ super().__init__() - _log_api_usage_once("models", self.__class__.__name__) + _log_api_usage_once(self.__class__.__qualname__) if not inverted_residual_setting: raise ValueError("The inverted_residual_setting should not be empty") diff --git a/torchvision/models/optical_flow/raft.py b/torchvision/models/optical_flow/raft.py index 18bf7dbafc3..e466d2fa1f1 100644 --- a/torchvision/models/optical_flow/raft.py +++ b/torchvision/models/optical_flow/raft.py @@ -440,7 +440,7 @@ def __init__(self, *, feature_encoder, context_encoder, corr_block, update_block If ``None`` (default), the flow is upsampled using interpolation. """ super().__init__() - _log_api_usage_once("models", self.__class__.__name__) + _log_api_usage_once(self.__class__.__qualname__) self.feature_encoder = feature_encoder self.context_encoder = context_encoder diff --git a/torchvision/models/regnet.py b/torchvision/models/regnet.py index 417054fe547..a6bf59d3037 100644 --- a/torchvision/models/regnet.py +++ b/torchvision/models/regnet.py @@ -310,7 +310,7 @@ def __init__( activation: Optional[Callable[..., nn.Module]] = None, ) -> None: super().__init__() - _log_api_usage_once("models", self.__class__.__name__) + _log_api_usage_once(self.__class__.__qualname__) if stem_type is None: stem_type = SimpleStemIN diff --git a/torchvision/models/resnet.py b/torchvision/models/resnet.py index d7dd3480ff6..67d1575bbbc 100644 --- a/torchvision/models/resnet.py +++ b/torchvision/models/resnet.py @@ -174,7 +174,7 @@ def __init__( norm_layer: Optional[Callable[..., nn.Module]] = None, ) -> None: super().__init__() - _log_api_usage_once("models", self.__class__.__name__) + _log_api_usage_once(self.__class__.__qualname__) if norm_layer is None: norm_layer = nn.BatchNorm2d self._norm_layer = norm_layer diff --git a/torchvision/models/segmentation/_utils.py b/torchvision/models/segmentation/_utils.py index 209a7a57c26..172bcc379ab 100644 --- a/torchvision/models/segmentation/_utils.py +++ b/torchvision/models/segmentation/_utils.py @@ -13,7 +13,7 @@ class _SimpleSegmentationModel(nn.Module): def __init__(self, backbone: nn.Module, classifier: nn.Module, aux_classifier: Optional[nn.Module] = None) -> None: super().__init__() - _log_api_usage_once("models", self.__class__.__name__) + _log_api_usage_once(self.__class__.__qualname__) self.backbone = backbone self.classifier = classifier self.aux_classifier = aux_classifier diff --git a/torchvision/models/segmentation/lraspp.py b/torchvision/models/segmentation/lraspp.py index 77243822434..9650e550e97 100644 --- a/torchvision/models/segmentation/lraspp.py +++ b/torchvision/models/segmentation/lraspp.py @@ -38,7 +38,7 @@ def __init__( self, backbone: nn.Module, low_channels: int, high_channels: int, num_classes: int, inter_channels: int = 128 ) -> None: super().__init__() - _log_api_usage_once("models", self.__class__.__name__) + _log_api_usage_once(self.__class__.__qualname__) self.backbone = backbone self.classifier = LRASPPHead(low_channels, high_channels, num_classes, inter_channels) diff --git a/torchvision/models/shufflenetv2.py b/torchvision/models/shufflenetv2.py index 9bec542d6f5..9032db7c62f 100644 --- a/torchvision/models/shufflenetv2.py +++ b/torchvision/models/shufflenetv2.py @@ -100,7 +100,7 @@ def __init__( inverted_residual: Callable[..., nn.Module] = InvertedResidual, ) -> None: super().__init__() - _log_api_usage_once("models", self.__class__.__name__) + _log_api_usage_once(self.__class__.__qualname__) if len(stages_repeats) != 3: raise ValueError("expected stages_repeats as list of 3 positive ints") diff --git a/torchvision/models/squeezenet.py b/torchvision/models/squeezenet.py index 6c14c779c0c..8e0cc673e3f 100644 --- a/torchvision/models/squeezenet.py +++ b/torchvision/models/squeezenet.py @@ -36,7 +36,7 @@ def forward(self, x: torch.Tensor) -> torch.Tensor: class SqueezeNet(nn.Module): def __init__(self, version: str = "1_0", num_classes: int = 1000, dropout: float = 0.5) -> None: super().__init__() - _log_api_usage_once("models", self.__class__.__name__) + _log_api_usage_once(self.__class__.__qualname__) self.num_classes = num_classes if version == "1_0": self.features = nn.Sequential( diff --git a/torchvision/models/vgg.py b/torchvision/models/vgg.py index c96bc5e1d8d..baa07e49595 100644 --- a/torchvision/models/vgg.py +++ b/torchvision/models/vgg.py @@ -37,7 +37,7 @@ def __init__( self, features: nn.Module, num_classes: int = 1000, init_weights: bool = True, dropout: float = 0.5 ) -> None: super().__init__() - _log_api_usage_once("models", self.__class__.__name__) + _log_api_usage_once(self.__class__.__qualname__) self.features = features self.avgpool = nn.AdaptiveAvgPool2d((7, 7)) self.classifier = nn.Sequential( diff --git a/torchvision/models/video/resnet.py b/torchvision/models/video/resnet.py index 475608886c6..d91a9154993 100644 --- a/torchvision/models/video/resnet.py +++ b/torchvision/models/video/resnet.py @@ -209,7 +209,7 @@ def __init__( zero_init_residual (bool, optional): Zero init bottleneck residual BN. Defaults to False. """ super().__init__() - _log_api_usage_once("models", self.__class__.__name__) + _log_api_usage_once(self.__class__.__qualname__) self.inplanes = 64 self.stem = stem() diff --git a/torchvision/ops/boxes.py b/torchvision/ops/boxes.py index 537c23480d8..363213eb220 100644 --- a/torchvision/ops/boxes.py +++ b/torchvision/ops/boxes.py @@ -34,7 +34,7 @@ def nms(boxes: Tensor, scores: Tensor, iou_threshold: float) -> Tensor: Tensor: int64 tensor with the indices of the elements that have been kept by NMS, sorted in decreasing order of scores """ - _log_api_usage_once("ops", "nms") + _log_api_usage_once("torchvision.ops.boxes.nms") _assert_has_ops() return torch.ops.torchvision.nms(boxes, scores, iou_threshold) @@ -63,7 +63,7 @@ def batched_nms( Tensor: int64 tensor with the indices of the elements that have been kept by NMS, sorted in decreasing order of scores """ - _log_api_usage_once("ops", "batched_nms") + _log_api_usage_once("torchvision.ops.boxes.batched_nms") # Benchmarks that drove the following thresholds are at # https://github.com/pytorch/vision/issues/1311#issuecomment-781329339 if boxes.numel() > (4000 if boxes.device.type == "cpu" else 20000) and not torchvision._is_tracing(): @@ -122,7 +122,7 @@ def remove_small_boxes(boxes: Tensor, min_size: float) -> Tensor: Tensor[K]: indices of the boxes that have both sides larger than min_size """ - _log_api_usage_once("ops", "remove_small_boxes") + _log_api_usage_once("torchvision.ops.boxes.remove_small_boxes") ws, hs = boxes[:, 2] - boxes[:, 0], boxes[:, 3] - boxes[:, 1] keep = (ws >= min_size) & (hs >= min_size) keep = torch.where(keep)[0] @@ -141,7 +141,7 @@ def clip_boxes_to_image(boxes: Tensor, size: Tuple[int, int]) -> Tensor: Returns: Tensor[N, 4]: clipped boxes """ - _log_api_usage_once("ops", "clip_boxes_to_image") + _log_api_usage_once("torchvision.ops.boxes.clip_boxes_to_image") dim = boxes.dim() boxes_x = boxes[..., 0::2] boxes_y = boxes[..., 1::2] @@ -182,7 +182,7 @@ def box_convert(boxes: Tensor, in_fmt: str, out_fmt: str) -> Tensor: Tensor[N, 4]: Boxes into converted format. """ - _log_api_usage_once("ops", "box_convert") + _log_api_usage_once("torchvision.ops.boxes.box_convert") allowed_fmts = ("xyxy", "xywh", "cxcywh") if in_fmt not in allowed_fmts or out_fmt not in allowed_fmts: raise ValueError("Unsupported Bounding Box Conversions for given in_fmt and out_fmt") @@ -232,7 +232,7 @@ def box_area(boxes: Tensor) -> Tensor: Returns: Tensor[N]: the area for each box """ - _log_api_usage_once("ops", "box_area") + _log_api_usage_once("torchvision.ops.boxes.box_area") boxes = _upcast(boxes) return (boxes[:, 2] - boxes[:, 0]) * (boxes[:, 3] - boxes[:, 1]) @@ -268,7 +268,7 @@ def box_iou(boxes1: Tensor, boxes2: Tensor) -> Tensor: Returns: Tensor[N, M]: the NxM matrix containing the pairwise IoU values for every element in boxes1 and boxes2 """ - _log_api_usage_once("ops", "box_iou") + _log_api_usage_once("torchvision.ops.boxes.box_iou") inter, union = _box_inter_union(boxes1, boxes2) iou = inter / union return iou @@ -291,7 +291,7 @@ def generalized_box_iou(boxes1: Tensor, boxes2: Tensor) -> Tensor: for every element in boxes1 and boxes2 """ - _log_api_usage_once("ops", "generalized_box_iou") + _log_api_usage_once("torchvision.ops.boxes.generalized_box_iou") # degenerate boxes gives inf / nan results # so do an early check assert (boxes1[:, 2:] >= boxes1[:, :2]).all() @@ -323,7 +323,7 @@ def masks_to_boxes(masks: torch.Tensor) -> torch.Tensor: Returns: Tensor[N, 4]: bounding boxes """ - _log_api_usage_once("ops", "masks_to_boxes") + _log_api_usage_once("torchvision.ops.boxes.masks_to_boxes") if masks.numel() == 0: return torch.zeros((0, 4), device=masks.device, dtype=torch.float) diff --git a/torchvision/ops/deform_conv.py b/torchvision/ops/deform_conv.py index b756274df71..f6bcaf1cc08 100644 --- a/torchvision/ops/deform_conv.py +++ b/torchvision/ops/deform_conv.py @@ -61,7 +61,7 @@ def deform_conv2d( >>> torch.Size([4, 5, 8, 8]) """ - _log_api_usage_once("ops", "deform_conv2d") + _log_api_usage_once("torchvision.ops.deform_conv.deform_conv2d") _assert_has_ops() out_channels = weight.shape[0] diff --git a/torchvision/ops/feature_pyramid_network.py b/torchvision/ops/feature_pyramid_network.py index e73d1ee853b..3efde8d1f86 100644 --- a/torchvision/ops/feature_pyramid_network.py +++ b/torchvision/ops/feature_pyramid_network.py @@ -77,7 +77,7 @@ def __init__( extra_blocks: Optional[ExtraFPNBlock] = None, ): super().__init__() - _log_api_usage_once("ops", self.__class__.__name__) + _log_api_usage_once(self.__class__.__qualname__) self.inner_blocks = nn.ModuleList() self.layer_blocks = nn.ModuleList() for in_channels in in_channels_list: diff --git a/torchvision/ops/focal_loss.py b/torchvision/ops/focal_loss.py index d19e7465720..9c0a98a8bb1 100644 --- a/torchvision/ops/focal_loss.py +++ b/torchvision/ops/focal_loss.py @@ -32,7 +32,7 @@ def sigmoid_focal_loss( Returns: Loss tensor with the reduction option applied. """ - _log_api_usage_once("ops", "sigmoid_focal_loss") + _log_api_usage_once("torchvision.ops.focal_loss.sigmoid_focal_loss") p = torch.sigmoid(inputs) ce_loss = F.binary_cross_entropy_with_logits(inputs, targets, reduction="none") p_t = p * targets + (1 - p) * (1 - targets) diff --git a/torchvision/ops/misc.py b/torchvision/ops/misc.py index 0189d1b140f..2a911f8c446 100644 --- a/torchvision/ops/misc.py +++ b/torchvision/ops/misc.py @@ -61,7 +61,7 @@ def __init__( warnings.warn("`n` argument is deprecated and has been renamed `num_features`", DeprecationWarning) num_features = n super().__init__() - _log_api_usage_once("ops", self.__class__.__name__) + _log_api_usage_once(self.__class__.__qualname__) self.eps = eps self.register_buffer("weight", torch.ones(num_features)) self.register_buffer("bias", torch.zeros(num_features)) @@ -155,7 +155,7 @@ def __init__( if activation_layer is not None: layers.append(activation_layer(inplace=inplace)) super().__init__(*layers) - _log_api_usage_once("ops", self.__class__.__name__) + _log_api_usage_once(self.__class__.__qualname__) self.out_channels = out_channels @@ -179,7 +179,7 @@ def __init__( scale_activation: Callable[..., torch.nn.Module] = torch.nn.Sigmoid, ) -> None: super().__init__() - _log_api_usage_once("ops", self.__class__.__name__) + _log_api_usage_once(self.__class__.__qualname__) self.avgpool = torch.nn.AdaptiveAvgPool2d(1) self.fc1 = torch.nn.Conv2d(input_channels, squeeze_channels, 1) self.fc2 = torch.nn.Conv2d(squeeze_channels, input_channels, 1) diff --git a/torchvision/ops/poolers.py b/torchvision/ops/poolers.py index cb3abc70f80..4fd6686a748 100644 --- a/torchvision/ops/poolers.py +++ b/torchvision/ops/poolers.py @@ -276,7 +276,7 @@ def __init__( canonical_level: int = 4, ): super().__init__() - _log_api_usage_once("ops", self.__class__.__name__) + _log_api_usage_once(self.__class__.__qualname__) if isinstance(output_size, int): output_size = (output_size, output_size) self.featmap_names = featmap_names diff --git a/torchvision/ops/ps_roi_align.py b/torchvision/ops/ps_roi_align.py index f24a41866e9..da03aa049d4 100644 --- a/torchvision/ops/ps_roi_align.py +++ b/torchvision/ops/ps_roi_align.py @@ -43,7 +43,7 @@ def ps_roi_align( Returns: Tensor[K, C / (output_size[0] * output_size[1]), output_size[0], output_size[1]]: The pooled RoIs """ - _log_api_usage_once("ops", "ps_roi_align") + _log_api_usage_once("torchvision.ops.ps_roi_align.ps_roi_align") _assert_has_ops() check_roi_boxes_shape(boxes) rois = boxes diff --git a/torchvision/ops/ps_roi_pool.py b/torchvision/ops/ps_roi_pool.py index 9079aaacc6e..e83280f4747 100644 --- a/torchvision/ops/ps_roi_pool.py +++ b/torchvision/ops/ps_roi_pool.py @@ -37,7 +37,7 @@ def ps_roi_pool( Returns: Tensor[K, C / (output_size[0] * output_size[1]), output_size[0], output_size[1]]: The pooled RoIs. """ - _log_api_usage_once("ops", "ps_roi_pool") + _log_api_usage_once("torchvision.ops.ps_roi_pool.ps_roi_pool") _assert_has_ops() check_roi_boxes_shape(boxes) rois = boxes diff --git a/torchvision/ops/roi_align.py b/torchvision/ops/roi_align.py index 509c0777d2d..c2ca35433bd 100644 --- a/torchvision/ops/roi_align.py +++ b/torchvision/ops/roi_align.py @@ -50,7 +50,7 @@ def roi_align( Returns: Tensor[K, C, output_size[0], output_size[1]]: The pooled RoIs. """ - _log_api_usage_once("ops", "roi_align") + _log_api_usage_once("torchvision.ops.roi_align.roi_align") _assert_has_ops() check_roi_boxes_shape(boxes) rois = boxes diff --git a/torchvision/ops/roi_pool.py b/torchvision/ops/roi_pool.py index a8f9c4d2092..c39aed98eb8 100644 --- a/torchvision/ops/roi_pool.py +++ b/torchvision/ops/roi_pool.py @@ -39,7 +39,7 @@ def roi_pool( Returns: Tensor[K, C, output_size[0], output_size[1]]: The pooled RoIs. """ - _log_api_usage_once("ops", "roi_pool") + _log_api_usage_once("torchvision.ops.roi_pool.roi_pool") _assert_has_ops() check_roi_boxes_shape(boxes) rois = boxes diff --git a/torchvision/ops/stochastic_depth.py b/torchvision/ops/stochastic_depth.py index 40143d06141..61251a3af17 100644 --- a/torchvision/ops/stochastic_depth.py +++ b/torchvision/ops/stochastic_depth.py @@ -23,7 +23,7 @@ def stochastic_depth(input: Tensor, p: float, mode: str, training: bool = True) Returns: Tensor[N, ...]: The randomly zeroed tensor. """ - _log_api_usage_once("ops", "stochastic_depth") + _log_api_usage_once("torchvision.ops.stochastic_depth.stochastic_depth") if p < 0.0 or p > 1.0: raise ValueError(f"drop probability has to be between 0 and 1, but got {p}") if mode not in ["batch", "row"]: diff --git a/torchvision/prototype/models/vision_transformer.py b/torchvision/prototype/models/vision_transformer.py index 83c8160afc4..c9ac0f42565 100644 --- a/torchvision/prototype/models/vision_transformer.py +++ b/torchvision/prototype/models/vision_transformer.py @@ -140,7 +140,7 @@ def __init__( norm_layer: Callable[..., torch.nn.Module] = partial(nn.LayerNorm, eps=1e-6), ): super().__init__() - _log_api_usage_once("models", self.__class__.__name__) + _log_api_usage_once(self.__class__.__qualname__) torch._assert(image_size % patch_size == 0, "Input shape indivisible by patch size!") self.image_size = image_size self.patch_size = patch_size diff --git a/torchvision/utils.py b/torchvision/utils.py index 3a17a46e26e..4e8e203a29e 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("utils", "make_grid") + _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)}") @@ -131,7 +131,7 @@ def save_image( **kwargs: Other arguments are documented in ``make_grid``. """ - _log_api_usage_once("utils", "save_image") + _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() @@ -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("utils", "draw_bounding_boxes") + _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: @@ -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("utils", "draw_segmentation_masks") + _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: @@ -333,7 +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") + _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: @@ -380,7 +380,9 @@ def _generate_color_palette(num_masks: int): return [tuple((i * palette) % 255) for i in range(num_masks)] -def _log_api_usage_once(module: str, name: str) -> None: +def _log_api_usage_once(event: str) -> None: if torch.jit.is_scripting() or torch.jit.is_tracing(): return - torch._C._log_api_usage_once(f"torchvision.{module}.{name}") + if not event.startswith("torchvision"): + return + torch._C._log_api_usage_once(event)