Skip to content

use decorator to log API usage #4976

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion torchvision/datasets/vision.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ class VisionDataset(data.Dataset):

_repr_indent = 4

@_log_api_usage_once
def __init__(
self,
root: str,
transforms: Optional[Callable] = None,
transform: Optional[Callable] = None,
target_transform: Optional[Callable] = None,
) -> None:
_log_api_usage_once(self)
if isinstance(root, torch._six.string_classes):
root = os.path.expanduser(root)
self.root = root
Expand Down
2 changes: 1 addition & 1 deletion torchvision/models/alexnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@


class AlexNet(nn.Module):
@_log_api_usage_once
def __init__(self, num_classes: int = 1000, dropout: float = 0.5) -> None:
super().__init__()
_log_api_usage_once(self)
self.features = nn.Sequential(
nn.Conv2d(3, 64, kernel_size=11, stride=4, padding=2),
nn.ReLU(inplace=True),
Expand Down
3 changes: 1 addition & 2 deletions torchvision/models/densenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ class DenseNet(nn.Module):
but slower. Default: *False*. See `"paper" <https://arxiv.org/pdf/1707.06990.pdf>`_.
"""

@_log_api_usage_once
def __init__(
self,
growth_rate: int = 32,
Expand All @@ -161,9 +162,7 @@ def __init__(
num_classes: int = 1000,
memory_efficient: bool = False,
) -> None:

super().__init__()
_log_api_usage_once(self)

# First convolution
self.features = nn.Sequential(
Expand Down
2 changes: 1 addition & 1 deletion torchvision/models/detection/generalized_rcnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ class GeneralizedRCNN(nn.Module):
the model
"""

@_log_api_usage_once
def __init__(self, backbone: nn.Module, rpn: nn.Module, roi_heads: nn.Module, transform: nn.Module) -> None:
super().__init__()
_log_api_usage_once(self)
self.transform = transform
self.backbone = backbone
self.rpn = rpn
Expand Down
2 changes: 1 addition & 1 deletion torchvision/models/detection/retinanet.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ class RetinaNet(nn.Module):
"proposal_matcher": det_utils.Matcher,
}

@_log_api_usage_once
def __init__(
self,
backbone,
Expand All @@ -337,7 +338,6 @@ def __init__(
topk_candidates=1000,
):
super().__init__()
_log_api_usage_once(self)

if not hasattr(backbone, "out_channels"):
raise ValueError(
Expand Down
2 changes: 1 addition & 1 deletion torchvision/models/detection/ssd.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ class SSD(nn.Module):
"proposal_matcher": det_utils.Matcher,
}

@_log_api_usage_once
def __init__(
self,
backbone: nn.Module,
Expand All @@ -182,7 +183,6 @@ def __init__(
positive_fraction: float = 0.25,
):
super().__init__()
_log_api_usage_once(self)

self.backbone = backbone

Expand Down
2 changes: 1 addition & 1 deletion torchvision/models/detection/ssdlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def __init__(self, in_channels: List[int], num_anchors: List[int], norm_layer: C


class SSDLiteFeatureExtractorMobileNet(nn.Module):
@_log_api_usage_once
def __init__(
self,
backbone: nn.Module,
Expand All @@ -120,7 +121,6 @@ def __init__(
min_depth: int = 16,
):
super().__init__()
_log_api_usage_once(self)

assert not backbone[c4_pos].use_res_connect
self.features = nn.Sequential(
Expand Down
2 changes: 1 addition & 1 deletion torchvision/models/efficientnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def forward(self, input: Tensor) -> Tensor:


class EfficientNet(nn.Module):
@_log_api_usage_once
def __init__(
self,
inverted_residual_setting: List[MBConvConfig],
Expand All @@ -170,7 +171,6 @@ def __init__(
norm_layer (Optional[Callable[..., nn.Module]]): Module specifying the normalization layer to use
"""
super().__init__()
_log_api_usage_once(self)

if not inverted_residual_setting:
raise ValueError("The inverted_residual_setting should not be empty")
Expand Down
2 changes: 1 addition & 1 deletion torchvision/models/googlenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
class GoogLeNet(nn.Module):
__constants__ = ["aux_logits", "transform_input"]

@_log_api_usage_once
def __init__(
self,
num_classes: int = 1000,
Expand All @@ -39,7 +40,6 @@ def __init__(
dropout_aux: float = 0.7,
) -> None:
super().__init__()
_log_api_usage_once(self)
if blocks is None:
blocks = [BasicConv2d, Inception, InceptionAux]
if init_weights is None:
Expand Down
2 changes: 1 addition & 1 deletion torchvision/models/inception.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@


class Inception3(nn.Module):
@_log_api_usage_once
def __init__(
self,
num_classes: int = 1000,
Expand All @@ -37,7 +38,6 @@ def __init__(
dropout: float = 0.5,
) -> None:
super().__init__()
_log_api_usage_once(self)
if inception_blocks is None:
inception_blocks = [BasicConv2d, InceptionA, InceptionB, InceptionC, InceptionD, InceptionE, InceptionAux]
if init_weights is None:
Expand Down
2 changes: 1 addition & 1 deletion torchvision/models/mnasnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ class MNASNet(torch.nn.Module):
# Version 2 adds depth scaling in the initial stages of the network.
_version = 2

@_log_api_usage_once
def __init__(self, alpha: float, num_classes: int = 1000, dropout: float = 0.2) -> None:
super().__init__()
_log_api_usage_once(self)
assert alpha > 0.0
self.alpha = alpha
self.num_classes = num_classes
Expand Down
2 changes: 1 addition & 1 deletion torchvision/models/mobilenetv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def forward(self, x: Tensor) -> Tensor:


class MobileNetV2(nn.Module):
@_log_api_usage_once
def __init__(
self,
num_classes: int = 1000,
Expand All @@ -111,7 +112,6 @@ def __init__(

"""
super().__init__()
_log_api_usage_once(self)

if block is None:
block = InvertedResidual
Expand Down
2 changes: 1 addition & 1 deletion torchvision/models/mobilenetv3.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def forward(self, input: Tensor) -> Tensor:


class MobileNetV3(nn.Module):
@_log_api_usage_once
def __init__(
self,
inverted_residual_setting: List[InvertedResidualConfig],
Expand All @@ -151,7 +152,6 @@ def __init__(
dropout (float): The droupout probability
"""
super().__init__()
_log_api_usage_once(self)

if not inverted_residual_setting:
raise ValueError("The inverted_residual_setting should not be empty")
Expand Down
2 changes: 1 addition & 1 deletion torchvision/models/regnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ def _adjust_widths_groups_compatibilty(


class RegNet(nn.Module):
@_log_api_usage_once
def __init__(
self,
block_params: BlockParams,
Expand All @@ -310,7 +311,6 @@ def __init__(
activation: Optional[Callable[..., nn.Module]] = None,
) -> None:
super().__init__()
_log_api_usage_once(self)

if stem_type is None:
stem_type = SimpleStemIN
Expand Down
2 changes: 1 addition & 1 deletion torchvision/models/resnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def forward(self, x: Tensor) -> Tensor:


class ResNet(nn.Module):
@_log_api_usage_once
def __init__(
self,
block: Type[Union[BasicBlock, Bottleneck]],
Expand All @@ -174,7 +175,6 @@ def __init__(
norm_layer: Optional[Callable[..., nn.Module]] = None,
) -> None:
super().__init__()
_log_api_usage_once(self)
if norm_layer is None:
norm_layer = nn.BatchNorm2d
self._norm_layer = norm_layer
Expand Down
2 changes: 1 addition & 1 deletion torchvision/models/segmentation/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
class _SimpleSegmentationModel(nn.Module):
__constants__ = ["aux_classifier"]

@_log_api_usage_once
def __init__(self, backbone: nn.Module, classifier: nn.Module, aux_classifier: Optional[nn.Module] = None) -> None:
super().__init__()
_log_api_usage_once(self)
self.backbone = backbone
self.classifier = classifier
self.aux_classifier = aux_classifier
Expand Down
2 changes: 1 addition & 1 deletion torchvision/models/segmentation/lraspp.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ class LRASPP(nn.Module):
inter_channels (int, optional): the number of channels for intermediate computations.
"""

@_log_api_usage_once
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(self)
self.backbone = backbone
self.classifier = LRASPPHead(low_channels, high_channels, num_classes, inter_channels)

Expand Down
2 changes: 1 addition & 1 deletion torchvision/models/shufflenetv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def forward(self, x: Tensor) -> Tensor:


class ShuffleNetV2(nn.Module):
@_log_api_usage_once
def __init__(
self,
stages_repeats: List[int],
Expand All @@ -100,7 +101,6 @@ def __init__(
inverted_residual: Callable[..., nn.Module] = InvertedResidual,
) -> None:
super().__init__()
_log_api_usage_once(self)

if len(stages_repeats) != 3:
raise ValueError("expected stages_repeats as list of 3 positive ints")
Expand Down
2 changes: 1 addition & 1 deletion torchvision/models/squeezenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ def forward(self, x: torch.Tensor) -> torch.Tensor:


class SqueezeNet(nn.Module):
@_log_api_usage_once
def __init__(self, version: str = "1_0", num_classes: int = 1000, dropout: float = 0.5) -> None:
super().__init__()
_log_api_usage_once(self)
self.num_classes = num_classes
if version == "1_0":
self.features = nn.Sequential(
Expand Down
2 changes: 1 addition & 1 deletion torchvision/models/vgg.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@


class VGG(nn.Module):
@_log_api_usage_once
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(self)
self.features = features
self.avgpool = nn.AdaptiveAvgPool2d((7, 7))
self.classifier = nn.Sequential(
Expand Down
2 changes: 1 addition & 1 deletion torchvision/models/video/resnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ def __init__(self) -> None:


class VideoResNet(nn.Module):
@_log_api_usage_once
def __init__(
self,
block: Type[Union[BasicBlock, Bottleneck]],
Expand All @@ -209,7 +210,6 @@ def __init__(
zero_init_residual (bool, optional): Zero init bottleneck residual BN. Defaults to False.
"""
super().__init__()
_log_api_usage_once(self)
self.inplanes = 64

self.stem = stem()
Expand Down
Loading