Skip to content

Commit 4a004a9

Browse files
committed
use decorator to log API usage
1 parent 999ef25 commit 4a004a9

33 files changed

+57
-54
lines changed

torchvision/datasets/vision.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ class VisionDataset(data.Dataset):
2828

2929
_repr_indent = 4
3030

31+
@_log_api_usage_once
3132
def __init__(
3233
self,
3334
root: str,
3435
transforms: Optional[Callable] = None,
3536
transform: Optional[Callable] = None,
3637
target_transform: Optional[Callable] = None,
3738
) -> None:
38-
_log_api_usage_once(self)
3939
if isinstance(root, torch._six.string_classes):
4040
root = os.path.expanduser(root)
4141
self.root = root

torchvision/models/alexnet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717

1818
class AlexNet(nn.Module):
19+
@_log_api_usage_once
1920
def __init__(self, num_classes: int = 1000, dropout: float = 0.5) -> None:
2021
super().__init__()
21-
_log_api_usage_once(self)
2222
self.features = nn.Sequential(
2323
nn.Conv2d(3, 64, kernel_size=11, stride=4, padding=2),
2424
nn.ReLU(inplace=True),

torchvision/models/densenet.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ class DenseNet(nn.Module):
151151
but slower. Default: *False*. See `"paper" <https://arxiv.org/pdf/1707.06990.pdf>`_.
152152
"""
153153

154+
@_log_api_usage_once
154155
def __init__(
155156
self,
156157
growth_rate: int = 32,
@@ -161,9 +162,7 @@ def __init__(
161162
num_classes: int = 1000,
162163
memory_efficient: bool = False,
163164
) -> None:
164-
165165
super().__init__()
166-
_log_api_usage_once(self)
167166

168167
# First convolution
169168
self.features = nn.Sequential(

torchvision/models/detection/generalized_rcnn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ class GeneralizedRCNN(nn.Module):
2525
the model
2626
"""
2727

28+
@_log_api_usage_once
2829
def __init__(self, backbone: nn.Module, rpn: nn.Module, roi_heads: nn.Module, transform: nn.Module) -> None:
2930
super().__init__()
30-
_log_api_usage_once(self)
3131
self.transform = transform
3232
self.backbone = backbone
3333
self.rpn = rpn

torchvision/models/detection/retinanet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ class RetinaNet(nn.Module):
316316
"proposal_matcher": det_utils.Matcher,
317317
}
318318

319+
@_log_api_usage_once
319320
def __init__(
320321
self,
321322
backbone,
@@ -337,7 +338,6 @@ def __init__(
337338
topk_candidates=1000,
338339
):
339340
super().__init__()
340-
_log_api_usage_once(self)
341341

342342
if not hasattr(backbone, "out_channels"):
343343
raise ValueError(

torchvision/models/detection/ssd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ class SSD(nn.Module):
165165
"proposal_matcher": det_utils.Matcher,
166166
}
167167

168+
@_log_api_usage_once
168169
def __init__(
169170
self,
170171
backbone: nn.Module,
@@ -182,7 +183,6 @@ def __init__(
182183
positive_fraction: float = 0.25,
183184
):
184185
super().__init__()
185-
_log_api_usage_once(self)
186186

187187
self.backbone = backbone
188188

torchvision/models/detection/ssdlite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def __init__(self, in_channels: List[int], num_anchors: List[int], norm_layer: C
111111

112112

113113
class SSDLiteFeatureExtractorMobileNet(nn.Module):
114+
@_log_api_usage_once
114115
def __init__(
115116
self,
116117
backbone: nn.Module,
@@ -120,7 +121,6 @@ def __init__(
120121
min_depth: int = 16,
121122
):
122123
super().__init__()
123-
_log_api_usage_once(self)
124124

125125
assert not backbone[c4_pos].use_res_connect
126126
self.features = nn.Sequential(

torchvision/models/efficientnet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ def forward(self, input: Tensor) -> Tensor:
148148

149149

150150
class EfficientNet(nn.Module):
151+
@_log_api_usage_once
151152
def __init__(
152153
self,
153154
inverted_residual_setting: List[MBConvConfig],
@@ -170,7 +171,6 @@ def __init__(
170171
norm_layer (Optional[Callable[..., nn.Module]]): Module specifying the normalization layer to use
171172
"""
172173
super().__init__()
173-
_log_api_usage_once(self)
174174

175175
if not inverted_residual_setting:
176176
raise ValueError("The inverted_residual_setting should not be empty")

torchvision/models/googlenet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
class GoogLeNet(nn.Module):
2929
__constants__ = ["aux_logits", "transform_input"]
3030

31+
@_log_api_usage_once
3132
def __init__(
3233
self,
3334
num_classes: int = 1000,
@@ -39,7 +40,6 @@ def __init__(
3940
dropout_aux: float = 0.7,
4041
) -> None:
4142
super().__init__()
42-
_log_api_usage_once(self)
4343
if blocks is None:
4444
blocks = [BasicConv2d, Inception, InceptionAux]
4545
if init_weights is None:

torchvision/models/inception.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828

2929
class Inception3(nn.Module):
30+
@_log_api_usage_once
3031
def __init__(
3132
self,
3233
num_classes: int = 1000,
@@ -37,7 +38,6 @@ def __init__(
3738
dropout: float = 0.5,
3839
) -> None:
3940
super().__init__()
40-
_log_api_usage_once(self)
4141
if inception_blocks is None:
4242
inception_blocks = [BasicConv2d, InceptionA, InceptionB, InceptionC, InceptionD, InceptionE, InceptionAux]
4343
if init_weights is None:

torchvision/models/mnasnet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ class MNASNet(torch.nn.Module):
9696
# Version 2 adds depth scaling in the initial stages of the network.
9797
_version = 2
9898

99+
@_log_api_usage_once
99100
def __init__(self, alpha: float, num_classes: int = 1000, dropout: float = 0.2) -> None:
100101
super().__init__()
101-
_log_api_usage_once(self)
102102
assert alpha > 0.0
103103
self.alpha = alpha
104104
self.num_classes = num_classes

torchvision/models/mobilenetv2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def forward(self, x: Tensor) -> Tensor:
8686

8787

8888
class MobileNetV2(nn.Module):
89+
@_log_api_usage_once
8990
def __init__(
9091
self,
9192
num_classes: int = 1000,
@@ -111,7 +112,6 @@ def __init__(
111112
112113
"""
113114
super().__init__()
114-
_log_api_usage_once(self)
115115

116116
if block is None:
117117
block = InvertedResidual

torchvision/models/mobilenetv3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ def forward(self, input: Tensor) -> Tensor:
129129

130130

131131
class MobileNetV3(nn.Module):
132+
@_log_api_usage_once
132133
def __init__(
133134
self,
134135
inverted_residual_setting: List[InvertedResidualConfig],
@@ -151,7 +152,6 @@ def __init__(
151152
dropout (float): The droupout probability
152153
"""
153154
super().__init__()
154-
_log_api_usage_once(self)
155155

156156
if not inverted_residual_setting:
157157
raise ValueError("The inverted_residual_setting should not be empty")

torchvision/models/regnet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ def _adjust_widths_groups_compatibilty(
299299

300300

301301
class RegNet(nn.Module):
302+
@_log_api_usage_once
302303
def __init__(
303304
self,
304305
block_params: BlockParams,
@@ -310,7 +311,6 @@ def __init__(
310311
activation: Optional[Callable[..., nn.Module]] = None,
311312
) -> None:
312313
super().__init__()
313-
_log_api_usage_once(self)
314314

315315
if stem_type is None:
316316
stem_type = SimpleStemIN

torchvision/models/resnet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ def forward(self, x: Tensor) -> Tensor:
162162

163163

164164
class ResNet(nn.Module):
165+
@_log_api_usage_once
165166
def __init__(
166167
self,
167168
block: Type[Union[BasicBlock, Bottleneck]],
@@ -174,7 +175,6 @@ def __init__(
174175
norm_layer: Optional[Callable[..., nn.Module]] = None,
175176
) -> None:
176177
super().__init__()
177-
_log_api_usage_once(self)
178178
if norm_layer is None:
179179
norm_layer = nn.BatchNorm2d
180180
self._norm_layer = norm_layer

torchvision/models/segmentation/_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
class _SimpleSegmentationModel(nn.Module):
1212
__constants__ = ["aux_classifier"]
1313

14+
@_log_api_usage_once
1415
def __init__(self, backbone: nn.Module, classifier: nn.Module, aux_classifier: Optional[nn.Module] = None) -> None:
1516
super().__init__()
16-
_log_api_usage_once(self)
1717
self.backbone = backbone
1818
self.classifier = classifier
1919
self.aux_classifier = aux_classifier

torchvision/models/segmentation/lraspp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ class LRASPP(nn.Module):
3434
inter_channels (int, optional): the number of channels for intermediate computations.
3535
"""
3636

37+
@_log_api_usage_once
3738
def __init__(
3839
self, backbone: nn.Module, low_channels: int, high_channels: int, num_classes: int, inter_channels: int = 128
3940
) -> None:
4041
super().__init__()
41-
_log_api_usage_once(self)
4242
self.backbone = backbone
4343
self.classifier = LRASPPHead(low_channels, high_channels, num_classes, inter_channels)
4444

torchvision/models/shufflenetv2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ def forward(self, x: Tensor) -> Tensor:
9292

9393

9494
class ShuffleNetV2(nn.Module):
95+
@_log_api_usage_once
9596
def __init__(
9697
self,
9798
stages_repeats: List[int],
@@ -100,7 +101,6 @@ def __init__(
100101
inverted_residual: Callable[..., nn.Module] = InvertedResidual,
101102
) -> None:
102103
super().__init__()
103-
_log_api_usage_once(self)
104104

105105
if len(stages_repeats) != 3:
106106
raise ValueError("expected stages_repeats as list of 3 positive ints")

torchvision/models/squeezenet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ def forward(self, x: torch.Tensor) -> torch.Tensor:
3434

3535

3636
class SqueezeNet(nn.Module):
37+
@_log_api_usage_once
3738
def __init__(self, version: str = "1_0", num_classes: int = 1000, dropout: float = 0.5) -> None:
3839
super().__init__()
39-
_log_api_usage_once(self)
4040
self.num_classes = num_classes
4141
if version == "1_0":
4242
self.features = nn.Sequential(

torchvision/models/vgg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@
3333

3434

3535
class VGG(nn.Module):
36+
@_log_api_usage_once
3637
def __init__(
3738
self, features: nn.Module, num_classes: int = 1000, init_weights: bool = True, dropout: float = 0.5
3839
) -> None:
3940
super().__init__()
40-
_log_api_usage_once(self)
4141
self.features = features
4242
self.avgpool = nn.AdaptiveAvgPool2d((7, 7))
4343
self.classifier = nn.Sequential(

torchvision/models/video/resnet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ def __init__(self) -> None:
188188

189189

190190
class VideoResNet(nn.Module):
191+
@_log_api_usage_once
191192
def __init__(
192193
self,
193194
block: Type[Union[BasicBlock, Bottleneck]],
@@ -209,7 +210,6 @@ def __init__(
209210
zero_init_residual (bool, optional): Zero init bottleneck residual BN. Defaults to False.
210211
"""
211212
super().__init__()
212-
_log_api_usage_once(self)
213213
self.inplanes = 64
214214

215215
self.stem = stem()

0 commit comments

Comments
 (0)