Skip to content
Merged
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
4 changes: 3 additions & 1 deletion torchvision/datasets/vision.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import torch
import torch.utils.data as data

from ..utils import _log_api_usage_once


class VisionDataset(data.Dataset):
"""
Expand Down Expand Up @@ -33,7 +35,7 @@ def __init__(
transform: Optional[Callable] = None,
target_transform: Optional[Callable] = None,
) -> None:
torch._C._log_api_usage_once(f"torchvision.datasets.{self.__class__.__name__}")
_log_api_usage_once(self)
if isinstance(root, torch._six.string_classes):
root = os.path.expanduser(root)
self.root = root
Expand Down
2 changes: 2 additions & 0 deletions torchvision/models/alexnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import torch.nn as nn

from .._internally_replaced_utils import load_state_dict_from_url
from ..utils import _log_api_usage_once


__all__ = ["AlexNet", "alexnet"]
Expand All @@ -17,6 +18,7 @@
class AlexNet(nn.Module):
def __init__(self, num_classes: int = 1000, dropout: float = 0.5) -> None:
super(AlexNet, self).__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
2 changes: 2 additions & 0 deletions torchvision/models/densenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from torch import Tensor

from .._internally_replaced_utils import load_state_dict_from_url
from ..utils import _log_api_usage_once


__all__ = ["DenseNet", "densenet121", "densenet169", "densenet201", "densenet161"]
Expand Down Expand Up @@ -162,6 +163,7 @@ def __init__(
) -> None:

super(DenseNet, self).__init__()
_log_api_usage_once(self)

# First convolution
self.features = nn.Sequential(
Expand Down
2 changes: 2 additions & 0 deletions torchvision/models/efficientnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from .._internally_replaced_utils import load_state_dict_from_url
from ..ops.misc import ConvNormActivation, SqueezeExcitation
from ..utils import _log_api_usage_once
from ._utils import _make_divisible


Expand Down Expand Up @@ -169,6 +170,7 @@ 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: 2 additions & 0 deletions torchvision/models/googlenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from torch import Tensor

from .._internally_replaced_utils import load_state_dict_from_url
from ..utils import _log_api_usage_once

__all__ = ["GoogLeNet", "googlenet", "GoogLeNetOutputs", "_GoogLeNetOutputs"]

Expand Down Expand Up @@ -75,6 +76,7 @@ def __init__(
dropout_aux: float = 0.7,
) -> None:
super(GoogLeNet, self).__init__()
_log_api_usage_once(self)
if blocks is None:
blocks = [BasicConv2d, Inception, InceptionAux]
if init_weights is None:
Expand Down
2 changes: 2 additions & 0 deletions torchvision/models/inception.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from torch import nn, Tensor

from .._internally_replaced_utils import load_state_dict_from_url
from ..utils import _log_api_usage_once


__all__ = ["Inception3", "inception_v3", "InceptionOutputs", "_InceptionOutputs"]
Expand Down Expand Up @@ -73,6 +74,7 @@ def __init__(
dropout: float = 0.5,
) -> None:
super(Inception3, self).__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: 2 additions & 0 deletions torchvision/models/mnasnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from torch import Tensor

from .._internally_replaced_utils import load_state_dict_from_url
from ..utils import _log_api_usage_once

__all__ = ["MNASNet", "mnasnet0_5", "mnasnet0_75", "mnasnet1_0", "mnasnet1_3"]

Expand Down Expand Up @@ -97,6 +98,7 @@ class MNASNet(torch.nn.Module):

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

from .._internally_replaced_utils import load_state_dict_from_url
from ..ops.misc import ConvNormActivation
from ..utils import _log_api_usage_once
from ._utils import _make_divisible


Expand Down Expand Up @@ -110,6 +111,7 @@ def __init__(

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

if block is None:
block = InvertedResidual
Expand Down
2 changes: 2 additions & 0 deletions torchvision/models/mobilenetv3.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from .._internally_replaced_utils import load_state_dict_from_url
from ..ops.misc import ConvNormActivation, SqueezeExcitation as SElayer
from ..utils import _log_api_usage_once
from ._utils import _make_divisible


Expand Down Expand Up @@ -150,6 +151,7 @@ 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: 2 additions & 0 deletions torchvision/models/regnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from .._internally_replaced_utils import load_state_dict_from_url
from ..ops.misc import ConvNormActivation, SqueezeExcitation
from ..utils import _log_api_usage_once
from ._utils import _make_divisible


Expand Down Expand Up @@ -309,6 +310,7 @@ 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: 2 additions & 0 deletions torchvision/models/resnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from torch import Tensor

from .._internally_replaced_utils import load_state_dict_from_url
from ..utils import _log_api_usage_once


__all__ = [
Expand Down Expand Up @@ -173,6 +174,7 @@ def __init__(
norm_layer: Optional[Callable[..., nn.Module]] = None,
) -> None:
super(ResNet, self).__init__()
_log_api_usage_once(self)
if norm_layer is None:
norm_layer = nn.BatchNorm2d
self._norm_layer = norm_layer
Expand Down
2 changes: 2 additions & 0 deletions torchvision/models/shufflenetv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from torch import Tensor

from .._internally_replaced_utils import load_state_dict_from_url
from ..utils import _log_api_usage_once


__all__ = ["ShuffleNetV2", "shufflenet_v2_x0_5", "shufflenet_v2_x1_0", "shufflenet_v2_x1_5", "shufflenet_v2_x2_0"]
Expand Down Expand Up @@ -99,6 +100,7 @@ def __init__(
inverted_residual: Callable[..., nn.Module] = InvertedResidual,
) -> None:
super(ShuffleNetV2, self).__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: 2 additions & 0 deletions torchvision/models/squeezenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import torch.nn.init as init

from .._internally_replaced_utils import load_state_dict_from_url
from ..utils import _log_api_usage_once

__all__ = ["SqueezeNet", "squeezenet1_0", "squeezenet1_1"]

Expand Down Expand Up @@ -35,6 +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(SqueezeNet, self).__init__()
_log_api_usage_once(self)
self.num_classes = num_classes
if version == "1_0":
self.features = nn.Sequential(
Expand Down
2 changes: 2 additions & 0 deletions torchvision/models/vgg.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import torch.nn as nn

from .._internally_replaced_utils import load_state_dict_from_url
from ..utils import _log_api_usage_once


__all__ = [
Expand Down Expand Up @@ -36,6 +37,7 @@ def __init__(
self, features: nn.Module, num_classes: int = 1000, init_weights: bool = True, dropout: float = 0.5
) -> None:
super(VGG, self).__init__()
_log_api_usage_once(self)
self.features = features
self.avgpool = nn.AdaptiveAvgPool2d((7, 7))
self.classifier = nn.Sequential(
Expand Down
4 changes: 4 additions & 0 deletions torchvision/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,7 @@ def draw_segmentation_masks(
def _generate_color_palette(num_masks: int):
palette = torch.tensor([2 ** 25 - 1, 2 ** 15 - 1, 2 ** 21 - 1])
return [tuple((i * palette) % 255) for i in range(num_masks)]


def _log_api_usage_once(obj: object) -> None:
torch._C._log_api_usage_once(f"{obj.__module__}.{obj.__class__.__name__}")