Skip to content

resnet

model.backbone.torchvision.resnet

__all__ module-attribute

__all__ = ['ResNet', 'resnet18', 'resnet34', 'resnet50', 'resnet101', 'resnet152', 'resnext50_32x4d', 'resnext101_32x8d', 'resnext101_64x4d', 'wide_resnet50_2', 'wide_resnet101_2']

BasicBlock

BasicBlock(inplanes: int, planes: int, stride: int = 1, downsample: Optional[Module] = None, groups: int = 1, base_width: int = 64, dilation: int = 1, norm_layer: Optional[Callable[..., Module]] = None)

Bases: Module

Source code in SaigeToolkit/model/backbone/torchvision/resnet.py
def __init__(
    self,
    inplanes: int,
    planes: int,
    stride: int = 1,
    downsample: Optional[nn.Module] = None,
    groups: int = 1,
    base_width: int = 64,
    dilation: int = 1,
    norm_layer: Optional[Callable[..., nn.Module]] = None,
) -> None:
    super().__init__()
    if norm_layer is None:
        norm_layer = nn.BatchNorm2d
    if groups != 1 or base_width != 64:
        raise ValueError("BasicBlock only supports groups=1 and base_width=64")
    if dilation > 1:
        raise NotImplementedError("Dilation > 1 not supported in BasicBlock")
    # Both self.conv1 and self.downsample layers downsample the input when stride != 1
    self.conv1 = conv3x3(inplanes, planes, stride)
    self.bn1 = norm_layer(planes)
    self.relu = nn.ReLU(inplace=True)
    self.conv2 = conv3x3(planes, planes)
    self.bn2 = norm_layer(planes)
    self.downsample = downsample
    self.stride = stride

Bottleneck

Bottleneck(inplanes: int, planes: int, stride: int = 1, downsample: Optional[Module] = None, groups: int = 1, base_width: int = 64, dilation: int = 1, norm_layer: Optional[Callable[..., Module]] = None)

Bases: Module

Source code in SaigeToolkit/model/backbone/torchvision/resnet.py
def __init__(
    self,
    inplanes: int,
    planes: int,
    stride: int = 1,
    downsample: Optional[nn.Module] = None,
    groups: int = 1,
    base_width: int = 64,
    dilation: int = 1,
    norm_layer: Optional[Callable[..., nn.Module]] = None,
) -> None:
    super().__init__()
    if norm_layer is None:
        norm_layer = nn.BatchNorm2d
    width = int(planes * (base_width / 64.0)) * groups
    # Both self.conv2 and self.downsample layers downsample the input when stride != 1
    self.conv1 = conv1x1(inplanes, width)
    self.bn1 = norm_layer(width)
    self.conv2 = conv3x3(width, width, stride, groups, dilation)
    self.bn2 = norm_layer(width)
    self.conv3 = conv1x1(width, planes * self.expansion)
    self.bn3 = norm_layer(planes * self.expansion)
    self.relu = nn.ReLU(inplace=True)
    self.downsample = downsample
    self.stride = stride

ResNet

ResNet(block: Type[Union[BasicBlock, Bottleneck]], layers: List[int], num_classes: int = 1000, zero_init_residual: bool = False, groups: int = 1, width_per_group: int = 64, replace_stride_with_dilation: Optional[List[bool]] = None, norm_layer: Optional[Callable[..., Module]] = None, in_channels: int = 3)

Bases: Module

Source code in SaigeToolkit/model/backbone/torchvision/resnet.py
def __init__(
    self,
    block: Type[Union[BasicBlock, Bottleneck]],
    layers: List[int],
    num_classes: int = 1000,
    zero_init_residual: bool = False,
    groups: int = 1,
    width_per_group: int = 64,
    replace_stride_with_dilation: Optional[List[bool]] = None,
    norm_layer: Optional[Callable[..., nn.Module]] = None,
    in_channels: int = 3,
) -> None:
    super().__init__()
    _log_api_usage_once(self)
    if norm_layer is None:
        norm_layer = nn.BatchNorm2d
    self._norm_layer = norm_layer
    self.in_channels = in_channels

    self.inplanes = 64
    self.dilation = 1
    if replace_stride_with_dilation is None:
        # each element in the tuple indicates if we should replace
        # the 2x2 stride with a dilated convolution instead
        replace_stride_with_dilation = [False, False, False]
    if len(replace_stride_with_dilation) != 3:
        raise ValueError(
            "replace_stride_with_dilation should be None "
            f"or a 3-element tuple, got {replace_stride_with_dilation}"
        )
    self.groups = groups
    self.base_width = width_per_group
    self.conv1 = nn.Conv2d(
        self.in_channels, self.inplanes, kernel_size=7, stride=2, padding=3, bias=False
    )
    self.bn1 = norm_layer(self.inplanes)
    self.relu = nn.ReLU(inplace=True)
    self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1)
    self.layer1 = self._make_layer(block, 64, layers[0])
    self.layer2 = self._make_layer(
        block, 128, layers[1], stride=2, dilate=replace_stride_with_dilation[0]
    )
    self.layer3 = self._make_layer(
        block, 256, layers[2], stride=2, dilate=replace_stride_with_dilation[1]
    )
    self.layer4 = self._make_layer(
        block, 512, layers[3], stride=2, dilate=replace_stride_with_dilation[2]
    )

    for m in self.modules():
        if isinstance(m, nn.Conv2d):
            nn.init.kaiming_normal_(m.weight, mode="fan_out", nonlinearity="relu")
        elif isinstance(m, (nn.BatchNorm2d, nn.GroupNorm)):
            nn.init.constant_(m.weight, 1)
            nn.init.constant_(m.bias, 0)

    # Zero-initialize the last BN in each residual branch,
    # so that the residual branch starts with zeros, and each residual block behaves like an identity.
    # This improves the model by 0.2~0.3% according to https://arxiv.org/abs/1706.02677
    if zero_init_residual:
        for m in self.modules():
            if isinstance(m, Bottleneck) and m.bn3.weight is not None:
                nn.init.constant_(m.bn3.weight, 0)  # type: ignore[arg-type]
            elif isinstance(m, BasicBlock) and m.bn2.weight is not None:
                nn.init.constant_(m.bn2.weight, 0)  # type: ignore[arg-type]

extend_state_dict_input_channel

extend_state_dict_input_channel(state_dict: Mapping[str, Any], input_weight_key: str, input_conv_layer: Conv2d) -> None

(Multipage) 3채널 이상인 이미지를 사용하기 위해 필요한 기능이며, state_dict의 input conv 채널이 네트워크의 input conv 채널보다 작은 경우 해당 weight의 채널을 늘려줍니다. 현재 네트워크가 가진 input conv 웨이트에서 앞 3 채널을 state_dict의 input conv 웨이트로 치환하는 방식을 사용합니다.

Parameters:

  • state_dict (Mapping[str, Any]) –

    로드하려는 weight

  • input_weight_key (str) –

    input conv weight의 이름

  • input_conv_layer (Conv2d) –

    input conv layer

Source code in SaigeToolkit/model/util.py
def extend_state_dict_input_channel(
    state_dict: Mapping[str, Any],
    input_weight_key: str,
    input_conv_layer: nn.Conv2d,
) -> None:
    """(Multipage) 3채널 이상인 이미지를 사용하기 위해 필요한 기능이며,
    state_dict의 input conv 채널이 네트워크의 input conv 채널보다 작은 경우 해당 weight의 채널을 늘려줍니다.
    현재 네트워크가 가진 input conv 웨이트에서 앞 3 채널을 state_dict의 input conv 웨이트로 치환하는 방식을 사용합니다.

    Args:
        state_dict (Mapping[str, Any]): 로드하려는 weight
        input_weight_key (str): input conv weight의 이름
        input_conv_layer (nn.Conv2d): input conv layer
    """
    state_dict_in_channels = state_dict[input_weight_key].shape[1]
    if state_dict_in_channels != input_conv_layer.in_channels:
        state_dict_in_channels = min(state_dict_in_channels, input_conv_layer.in_channels)
        original_input_conv_weight = input_conv_layer.state_dict()["weight"]
        original_input_conv_weight[:, :state_dict_in_channels] = state_dict[input_weight_key][
            :, :state_dict_in_channels
        ]
        state_dict[input_weight_key] = original_input_conv_weight

conv3x3

conv3x3(in_planes: int, out_planes: int, stride: int = 1, groups: int = 1, dilation: int = 1) -> Conv2d

3x3 convolution with padding

Source code in SaigeToolkit/model/backbone/torchvision/resnet.py
def conv3x3(
    in_planes: int, out_planes: int, stride: int = 1, groups: int = 1, dilation: int = 1
) -> nn.Conv2d:
    """3x3 convolution with padding"""
    return nn.Conv2d(
        in_planes,
        out_planes,
        kernel_size=3,
        stride=stride,
        padding=dilation,
        groups=groups,
        bias=False,
        dilation=dilation,
    )

conv1x1

conv1x1(in_planes: int, out_planes: int, stride: int = 1) -> Conv2d

1x1 convolution

Source code in SaigeToolkit/model/backbone/torchvision/resnet.py
def conv1x1(in_planes: int, out_planes: int, stride: int = 1) -> nn.Conv2d:
    """1x1 convolution"""
    return nn.Conv2d(in_planes, out_planes, kernel_size=1, stride=stride, bias=False)

_resnet

_resnet(block: Type[Union[BasicBlock, Bottleneck]], layers: List[int], weights: Optional[WeightsEnum], progress: bool, **kwargs: Any) -> ResNet
Source code in SaigeToolkit/model/backbone/torchvision/resnet.py
def _resnet(
    block: Type[Union[BasicBlock, Bottleneck]],
    layers: List[int],
    weights: Optional[WeightsEnum],
    progress: bool,
    **kwargs: Any,
) -> ResNet:
    if weights is not None:
        _ovewrite_named_param(kwargs, "num_classes", len(weights.meta["categories"]))

    model = ResNet(block, layers, **kwargs)

    if weights is not None:
        model.load_state_dict(weights.get_state_dict(progress=progress))

    return model

resnet18

resnet18(*, weights: Optional[ResNet18_Weights] = None, progress: bool = True, **kwargs: Any) -> ResNet

ResNet-18 from Deep Residual Learning for Image Recognition <https://arxiv.org/pdf/1512.03385.pdf>__.

Parameters:

  • weights

    class:~torchvision.models.ResNet18_Weights, optional): The pretrained weights to use. See :class:~torchvision.models.ResNet18_Weights below for more details, and possible values. By default, no pre-trained weights are used.

  • progress (bool, default: True ) –

    If True, displays a progress bar of the download to stderr. Default is True.

  • **kwargs (Any, default: {} ) –

    parameters passed to the torchvision.models.resnet.ResNet base class. Please refer to the source code <https://github.com/pytorch/vision/blob/main/torchvision/models/resnet.py>_ for more details about this class.

.. autoclass:: torchvision.models.ResNet18_Weights :members:

Source code in SaigeToolkit/model/backbone/torchvision/resnet.py
@handle_legacy_interface(weights=("pretrained", ResNet18_Weights.IMAGENET1K_V1))
def resnet18(
    *, weights: Optional[ResNet18_Weights] = None, progress: bool = True, **kwargs: Any
) -> ResNet:
    """ResNet-18 from `Deep Residual Learning for Image Recognition <https://arxiv.org/pdf/1512.03385.pdf>`__.

    Args:
        weights (:class:`~torchvision.models.ResNet18_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.ResNet18_Weights` below for
            more details, and possible values. By default, no pre-trained
            weights are used.
        progress (bool, optional): If True, displays a progress bar of the
            download to stderr. Default is True.
        **kwargs: parameters passed to the ``torchvision.models.resnet.ResNet``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/resnet.py>`_
            for more details about this class.

    .. autoclass:: torchvision.models.ResNet18_Weights
        :members:
    """
    weights = ResNet18_Weights.verify(weights)

    return _resnet(BasicBlock, [2, 2, 2, 2], weights, progress, **kwargs)

resnet34

resnet34(*, weights: Optional[ResNet34_Weights] = None, progress: bool = True, **kwargs: Any) -> ResNet

ResNet-34 from Deep Residual Learning for Image Recognition <https://arxiv.org/pdf/1512.03385.pdf>__.

Parameters:

  • weights

    class:~torchvision.models.ResNet34_Weights, optional): The pretrained weights to use. See :class:~torchvision.models.ResNet34_Weights below for more details, and possible values. By default, no pre-trained weights are used.

  • progress (bool, default: True ) –

    If True, displays a progress bar of the download to stderr. Default is True.

  • **kwargs (Any, default: {} ) –

    parameters passed to the torchvision.models.resnet.ResNet base class. Please refer to the source code <https://github.com/pytorch/vision/blob/main/torchvision/models/resnet.py>_ for more details about this class.

.. autoclass:: torchvision.models.ResNet34_Weights :members:

Source code in SaigeToolkit/model/backbone/torchvision/resnet.py
@handle_legacy_interface(weights=("pretrained", ResNet34_Weights.IMAGENET1K_V1))
def resnet34(
    *, weights: Optional[ResNet34_Weights] = None, progress: bool = True, **kwargs: Any
) -> ResNet:
    """ResNet-34 from `Deep Residual Learning for Image Recognition <https://arxiv.org/pdf/1512.03385.pdf>`__.

    Args:
        weights (:class:`~torchvision.models.ResNet34_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.ResNet34_Weights` below for
            more details, and possible values. By default, no pre-trained
            weights are used.
        progress (bool, optional): If True, displays a progress bar of the
            download to stderr. Default is True.
        **kwargs: parameters passed to the ``torchvision.models.resnet.ResNet``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/resnet.py>`_
            for more details about this class.

    .. autoclass:: torchvision.models.ResNet34_Weights
        :members:
    """
    weights = ResNet34_Weights.verify(weights)

    return _resnet(BasicBlock, [3, 4, 6, 3], weights, progress, **kwargs)

resnet50

resnet50(*, weights: Optional[ResNet50_Weights] = None, progress: bool = True, **kwargs: Any) -> ResNet

ResNet-50 from Deep Residual Learning for Image Recognition <https://arxiv.org/pdf/1512.03385.pdf>__.

.. note:: The bottleneck of TorchVision places the stride for downsampling to the second 3x3 convolution while the original paper places it to the first 1x1 convolution. This variant improves the accuracy and is known as ResNet V1.5 <https://ngc.nvidia.com/catalog/model-scripts/nvidia:resnet_50_v1_5_for_pytorch>_.

Parameters:

  • weights

    class:~torchvision.models.ResNet50_Weights, optional): The pretrained weights to use. See :class:~torchvision.models.ResNet50_Weights below for more details, and possible values. By default, no pre-trained weights are used.

  • progress (bool, default: True ) –

    If True, displays a progress bar of the download to stderr. Default is True.

  • **kwargs (Any, default: {} ) –

    parameters passed to the torchvision.models.resnet.ResNet base class. Please refer to the source code <https://github.com/pytorch/vision/blob/main/torchvision/models/resnet.py>_ for more details about this class.

.. autoclass:: torchvision.models.ResNet50_Weights :members:

Source code in SaigeToolkit/model/backbone/torchvision/resnet.py
@handle_legacy_interface(weights=("pretrained", ResNet50_Weights.IMAGENET1K_V1))
def resnet50(
    *, weights: Optional[ResNet50_Weights] = None, progress: bool = True, **kwargs: Any
) -> ResNet:
    """ResNet-50 from `Deep Residual Learning for Image Recognition <https://arxiv.org/pdf/1512.03385.pdf>`__.

    .. note::
       The bottleneck of TorchVision places the stride for downsampling to the second 3x3
       convolution while the original paper places it to the first 1x1 convolution.
       This variant improves the accuracy and is known as `ResNet V1.5
       <https://ngc.nvidia.com/catalog/model-scripts/nvidia:resnet_50_v1_5_for_pytorch>`_.

    Args:
        weights (:class:`~torchvision.models.ResNet50_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.ResNet50_Weights` below for
            more details, and possible values. By default, no pre-trained
            weights are used.
        progress (bool, optional): If True, displays a progress bar of the
            download to stderr. Default is True.
        **kwargs: parameters passed to the ``torchvision.models.resnet.ResNet``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/resnet.py>`_
            for more details about this class.

    .. autoclass:: torchvision.models.ResNet50_Weights
        :members:
    """
    weights = ResNet50_Weights.verify(weights)

    return _resnet(Bottleneck, [3, 4, 6, 3], weights, progress, **kwargs)

resnet101

resnet101(*, weights: Optional[ResNet101_Weights] = None, progress: bool = True, **kwargs: Any) -> ResNet

ResNet-101 from Deep Residual Learning for Image Recognition <https://arxiv.org/pdf/1512.03385.pdf>__.

.. note:: The bottleneck of TorchVision places the stride for downsampling to the second 3x3 convolution while the original paper places it to the first 1x1 convolution. This variant improves the accuracy and is known as ResNet V1.5 <https://ngc.nvidia.com/catalog/model-scripts/nvidia:resnet_50_v1_5_for_pytorch>_.

Parameters:

  • weights

    class:~torchvision.models.ResNet101_Weights, optional): The pretrained weights to use. See :class:~torchvision.models.ResNet101_Weights below for more details, and possible values. By default, no pre-trained weights are used.

  • progress (bool, default: True ) –

    If True, displays a progress bar of the download to stderr. Default is True.

  • **kwargs (Any, default: {} ) –

    parameters passed to the torchvision.models.resnet.ResNet base class. Please refer to the source code <https://github.com/pytorch/vision/blob/main/torchvision/models/resnet.py>_ for more details about this class.

.. autoclass:: torchvision.models.ResNet101_Weights :members:

Source code in SaigeToolkit/model/backbone/torchvision/resnet.py
@handle_legacy_interface(weights=("pretrained", ResNet101_Weights.IMAGENET1K_V1))
def resnet101(
    *, weights: Optional[ResNet101_Weights] = None, progress: bool = True, **kwargs: Any
) -> ResNet:
    """ResNet-101 from `Deep Residual Learning for Image Recognition <https://arxiv.org/pdf/1512.03385.pdf>`__.

    .. note::
       The bottleneck of TorchVision places the stride for downsampling to the second 3x3
       convolution while the original paper places it to the first 1x1 convolution.
       This variant improves the accuracy and is known as `ResNet V1.5
       <https://ngc.nvidia.com/catalog/model-scripts/nvidia:resnet_50_v1_5_for_pytorch>`_.

    Args:
        weights (:class:`~torchvision.models.ResNet101_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.ResNet101_Weights` below for
            more details, and possible values. By default, no pre-trained
            weights are used.
        progress (bool, optional): If True, displays a progress bar of the
            download to stderr. Default is True.
        **kwargs: parameters passed to the ``torchvision.models.resnet.ResNet``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/resnet.py>`_
            for more details about this class.

    .. autoclass:: torchvision.models.ResNet101_Weights
        :members:
    """
    weights = ResNet101_Weights.verify(weights)

    return _resnet(Bottleneck, [3, 4, 23, 3], weights, progress, **kwargs)

resnet152

resnet152(*, weights: Optional[ResNet152_Weights] = None, progress: bool = True, **kwargs: Any) -> ResNet

ResNet-152 from Deep Residual Learning for Image Recognition <https://arxiv.org/pdf/1512.03385.pdf>__.

.. note:: The bottleneck of TorchVision places the stride for downsampling to the second 3x3 convolution while the original paper places it to the first 1x1 convolution. This variant improves the accuracy and is known as ResNet V1.5 <https://ngc.nvidia.com/catalog/model-scripts/nvidia:resnet_50_v1_5_for_pytorch>_.

Parameters:

  • weights

    class:~torchvision.models.ResNet152_Weights, optional): The pretrained weights to use. See :class:~torchvision.models.ResNet152_Weights below for more details, and possible values. By default, no pre-trained weights are used.

  • progress (bool, default: True ) –

    If True, displays a progress bar of the download to stderr. Default is True.

  • **kwargs (Any, default: {} ) –

    parameters passed to the torchvision.models.resnet.ResNet base class. Please refer to the source code <https://github.com/pytorch/vision/blob/main/torchvision/models/resnet.py>_ for more details about this class.

.. autoclass:: torchvision.models.ResNet152_Weights :members:

Source code in SaigeToolkit/model/backbone/torchvision/resnet.py
@handle_legacy_interface(weights=("pretrained", ResNet152_Weights.IMAGENET1K_V1))
def resnet152(
    *, weights: Optional[ResNet152_Weights] = None, progress: bool = True, **kwargs: Any
) -> ResNet:
    """ResNet-152 from `Deep Residual Learning for Image Recognition <https://arxiv.org/pdf/1512.03385.pdf>`__.

    .. note::
       The bottleneck of TorchVision places the stride for downsampling to the second 3x3
       convolution while the original paper places it to the first 1x1 convolution.
       This variant improves the accuracy and is known as `ResNet V1.5
       <https://ngc.nvidia.com/catalog/model-scripts/nvidia:resnet_50_v1_5_for_pytorch>`_.

    Args:
        weights (:class:`~torchvision.models.ResNet152_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.ResNet152_Weights` below for
            more details, and possible values. By default, no pre-trained
            weights are used.
        progress (bool, optional): If True, displays a progress bar of the
            download to stderr. Default is True.
        **kwargs: parameters passed to the ``torchvision.models.resnet.ResNet``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/resnet.py>`_
            for more details about this class.

    .. autoclass:: torchvision.models.ResNet152_Weights
        :members:
    """
    weights = ResNet152_Weights.verify(weights)

    return _resnet(Bottleneck, [3, 8, 36, 3], weights, progress, **kwargs)

resnext50_32x4d

resnext50_32x4d(*, weights: Optional[ResNeXt50_32X4D_Weights] = None, progress: bool = True, **kwargs: Any) -> ResNet

ResNeXt-50 32x4d model from Aggregated Residual Transformation for Deep Neural Networks <https://arxiv.org/abs/1611.05431>_.

Parameters:

  • weights

    class:~torchvision.models.ResNeXt50_32X4D_Weights, optional): The pretrained weights to use. See :class:~torchvision.models.ResNext50_32X4D_Weights below for more details, and possible values. By default, no pre-trained weights are used.

  • progress (bool, default: True ) –

    If True, displays a progress bar of the download to stderr. Default is True.

  • **kwargs (Any, default: {} ) –

    parameters passed to the torchvision.models.resnet.ResNet base class. Please refer to the source code <https://github.com/pytorch/vision/blob/main/torchvision/models/resnet.py>_ for more details about this class.

.. autoclass:: torchvision.models.ResNeXt50_32X4D_Weights :members:

Source code in SaigeToolkit/model/backbone/torchvision/resnet.py
@handle_legacy_interface(weights=("pretrained", ResNeXt50_32X4D_Weights.IMAGENET1K_V1))
def resnext50_32x4d(
    *, weights: Optional[ResNeXt50_32X4D_Weights] = None, progress: bool = True, **kwargs: Any
) -> ResNet:
    """ResNeXt-50 32x4d model from
    `Aggregated Residual Transformation for Deep Neural Networks <https://arxiv.org/abs/1611.05431>`_.

    Args:
        weights (:class:`~torchvision.models.ResNeXt50_32X4D_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.ResNext50_32X4D_Weights` below for
            more details, and possible values. By default, no pre-trained
            weights are used.
        progress (bool, optional): If True, displays a progress bar of the
            download to stderr. Default is True.
        **kwargs: parameters passed to the ``torchvision.models.resnet.ResNet``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/resnet.py>`_
            for more details about this class.
    .. autoclass:: torchvision.models.ResNeXt50_32X4D_Weights
        :members:
    """
    weights = ResNeXt50_32X4D_Weights.verify(weights)

    _ovewrite_named_param(kwargs, "groups", 32)
    _ovewrite_named_param(kwargs, "width_per_group", 4)
    return _resnet(Bottleneck, [3, 4, 6, 3], weights, progress, **kwargs)

resnext101_32x8d

resnext101_32x8d(*, weights: Optional[ResNeXt101_32X8D_Weights] = None, progress: bool = True, **kwargs: Any) -> ResNet

ResNeXt-101 32x8d model from Aggregated Residual Transformation for Deep Neural Networks <https://arxiv.org/abs/1611.05431>_.

Parameters:

  • weights

    class:~torchvision.models.ResNeXt101_32X8D_Weights, optional): The pretrained weights to use. See :class:~torchvision.models.ResNeXt101_32X8D_Weights below for more details, and possible values. By default, no pre-trained weights are used.

  • progress (bool, default: True ) –

    If True, displays a progress bar of the download to stderr. Default is True.

  • **kwargs (Any, default: {} ) –

    parameters passed to the torchvision.models.resnet.ResNet base class. Please refer to the source code <https://github.com/pytorch/vision/blob/main/torchvision/models/resnet.py>_ for more details about this class.

.. autoclass:: torchvision.models.ResNeXt101_32X8D_Weights :members:

Source code in SaigeToolkit/model/backbone/torchvision/resnet.py
@handle_legacy_interface(weights=("pretrained", ResNeXt101_32X8D_Weights.IMAGENET1K_V1))
def resnext101_32x8d(
    *, weights: Optional[ResNeXt101_32X8D_Weights] = None, progress: bool = True, **kwargs: Any
) -> ResNet:
    """ResNeXt-101 32x8d model from
    `Aggregated Residual Transformation for Deep Neural Networks <https://arxiv.org/abs/1611.05431>`_.

    Args:
        weights (:class:`~torchvision.models.ResNeXt101_32X8D_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.ResNeXt101_32X8D_Weights` below for
            more details, and possible values. By default, no pre-trained
            weights are used.
        progress (bool, optional): If True, displays a progress bar of the
            download to stderr. Default is True.
        **kwargs: parameters passed to the ``torchvision.models.resnet.ResNet``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/resnet.py>`_
            for more details about this class.
    .. autoclass:: torchvision.models.ResNeXt101_32X8D_Weights
        :members:
    """
    weights = ResNeXt101_32X8D_Weights.verify(weights)

    _ovewrite_named_param(kwargs, "groups", 32)
    _ovewrite_named_param(kwargs, "width_per_group", 8)
    return _resnet(Bottleneck, [3, 4, 23, 3], weights, progress, **kwargs)

resnext101_64x4d

resnext101_64x4d(*, weights: Optional[ResNeXt101_64X4D_Weights] = None, progress: bool = True, **kwargs: Any) -> ResNet

ResNeXt-101 64x4d model from Aggregated Residual Transformation for Deep Neural Networks <https://arxiv.org/abs/1611.05431>_.

Parameters:

  • weights

    class:~torchvision.models.ResNeXt101_64X4D_Weights, optional): The pretrained weights to use. See :class:~torchvision.models.ResNeXt101_64X4D_Weights below for more details, and possible values. By default, no pre-trained weights are used.

  • progress (bool, default: True ) –

    If True, displays a progress bar of the download to stderr. Default is True.

  • **kwargs (Any, default: {} ) –

    parameters passed to the torchvision.models.resnet.ResNet base class. Please refer to the source code <https://github.com/pytorch/vision/blob/main/torchvision/models/resnet.py>_ for more details about this class.

.. autoclass:: torchvision.models.ResNeXt101_64X4D_Weights :members:

Source code in SaigeToolkit/model/backbone/torchvision/resnet.py
def resnext101_64x4d(
    *, weights: Optional[ResNeXt101_64X4D_Weights] = None, progress: bool = True, **kwargs: Any
) -> ResNet:
    """ResNeXt-101 64x4d model from
    `Aggregated Residual Transformation for Deep Neural Networks <https://arxiv.org/abs/1611.05431>`_.

    Args:
        weights (:class:`~torchvision.models.ResNeXt101_64X4D_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.ResNeXt101_64X4D_Weights` below for
            more details, and possible values. By default, no pre-trained
            weights are used.
        progress (bool, optional): If True, displays a progress bar of the
            download to stderr. Default is True.
        **kwargs: parameters passed to the ``torchvision.models.resnet.ResNet``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/resnet.py>`_
            for more details about this class.
    .. autoclass:: torchvision.models.ResNeXt101_64X4D_Weights
        :members:
    """
    weights = ResNeXt101_64X4D_Weights.verify(weights)

    _ovewrite_named_param(kwargs, "groups", 64)
    _ovewrite_named_param(kwargs, "width_per_group", 4)
    return _resnet(Bottleneck, [3, 4, 23, 3], weights, progress, **kwargs)

wide_resnet50_2

wide_resnet50_2(*, weights: Optional[Wide_ResNet50_2_Weights] = None, progress: bool = True, **kwargs: Any) -> ResNet

Wide ResNet-50-2 model from Wide Residual Networks <https://arxiv.org/abs/1605.07146>_.

The model is the same as ResNet except for the bottleneck number of channels which is twice larger in every block. The number of channels in outer 1x1 convolutions is the same, e.g. last block in ResNet-50 has 2048-512-2048 channels, and in Wide ResNet-50-2 has 2048-1024-2048.

Parameters:

  • weights

    class:~torchvision.models.Wide_ResNet50_2_Weights, optional): The pretrained weights to use. See :class:~torchvision.models.Wide_ResNet50_2_Weights below for more details, and possible values. By default, no pre-trained weights are used.

  • progress (bool, default: True ) –

    If True, displays a progress bar of the download to stderr. Default is True.

  • **kwargs (Any, default: {} ) –

    parameters passed to the torchvision.models.resnet.ResNet base class. Please refer to the source code <https://github.com/pytorch/vision/blob/main/torchvision/models/resnet.py>_ for more details about this class.

.. autoclass:: torchvision.models.Wide_ResNet50_2_Weights :members:

Source code in SaigeToolkit/model/backbone/torchvision/resnet.py
@handle_legacy_interface(weights=("pretrained", Wide_ResNet50_2_Weights.IMAGENET1K_V1))
def wide_resnet50_2(
    *, weights: Optional[Wide_ResNet50_2_Weights] = None, progress: bool = True, **kwargs: Any
) -> ResNet:
    """Wide ResNet-50-2 model from
    `Wide Residual Networks <https://arxiv.org/abs/1605.07146>`_.

    The model is the same as ResNet except for the bottleneck number of channels
    which is twice larger in every block. The number of channels in outer 1x1
    convolutions is the same, e.g. last block in ResNet-50 has 2048-512-2048
    channels, and in Wide ResNet-50-2 has 2048-1024-2048.

    Args:
        weights (:class:`~torchvision.models.Wide_ResNet50_2_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.Wide_ResNet50_2_Weights` below for
            more details, and possible values. By default, no pre-trained
            weights are used.
        progress (bool, optional): If True, displays a progress bar of the
            download to stderr. Default is True.
        **kwargs: parameters passed to the ``torchvision.models.resnet.ResNet``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/resnet.py>`_
            for more details about this class.
    .. autoclass:: torchvision.models.Wide_ResNet50_2_Weights
        :members:
    """
    weights = Wide_ResNet50_2_Weights.verify(weights)

    _ovewrite_named_param(kwargs, "width_per_group", 64 * 2)
    return _resnet(Bottleneck, [3, 4, 6, 3], weights, progress, **kwargs)

wide_resnet101_2

wide_resnet101_2(*, weights: Optional[Wide_ResNet101_2_Weights] = None, progress: bool = True, **kwargs: Any) -> ResNet

Wide ResNet-101-2 model from Wide Residual Networks <https://arxiv.org/abs/1605.07146>_.

The model is the same as ResNet except for the bottleneck number of channels which is twice larger in every block. The number of channels in outer 1x1 convolutions is the same, e.g. last block in ResNet-101 has 2048-512-2048 channels, and in Wide ResNet-101-2 has 2048-1024-2048.

Parameters:

  • weights

    class:~torchvision.models.Wide_ResNet101_2_Weights, optional): The pretrained weights to use. See :class:~torchvision.models.Wide_ResNet101_2_Weights below for more details, and possible values. By default, no pre-trained weights are used.

  • progress (bool, default: True ) –

    If True, displays a progress bar of the download to stderr. Default is True.

  • **kwargs (Any, default: {} ) –

    parameters passed to the torchvision.models.resnet.ResNet base class. Please refer to the source code <https://github.com/pytorch/vision/blob/main/torchvision/models/resnet.py>_ for more details about this class.

.. autoclass:: torchvision.models.Wide_ResNet101_2_Weights :members:

Source code in SaigeToolkit/model/backbone/torchvision/resnet.py
@handle_legacy_interface(weights=("pretrained", Wide_ResNet101_2_Weights.IMAGENET1K_V1))
def wide_resnet101_2(
    *, weights: Optional[Wide_ResNet101_2_Weights] = None, progress: bool = True, **kwargs: Any
) -> ResNet:
    """Wide ResNet-101-2 model from
    `Wide Residual Networks <https://arxiv.org/abs/1605.07146>`_.

    The model is the same as ResNet except for the bottleneck number of channels
    which is twice larger in every block. The number of channels in outer 1x1
    convolutions is the same, e.g. last block in ResNet-101 has 2048-512-2048
    channels, and in Wide ResNet-101-2 has 2048-1024-2048.

    Args:
        weights (:class:`~torchvision.models.Wide_ResNet101_2_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.Wide_ResNet101_2_Weights` below for
            more details, and possible values. By default, no pre-trained
            weights are used.
        progress (bool, optional): If True, displays a progress bar of the
            download to stderr. Default is True.
        **kwargs: parameters passed to the ``torchvision.models.resnet.ResNet``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/resnet.py>`_
            for more details about this class.
    .. autoclass:: torchvision.models.Wide_ResNet101_2_Weights
        :members:
    """
    weights = Wide_ResNet101_2_Weights.verify(weights)

    _ovewrite_named_param(kwargs, "width_per_group", 64 * 2)
    return _resnet(Bottleneck, [3, 4, 23, 3], weights, progress, **kwargs)