Skip to content

backbone

Module diagram

classDiagram
  class backbone {
  }
  class builder {
  }
  class norm {
  }
  class torchvision {
  }
  class regnet {
  }
  class resnet {
  }
  class squeezenet {
  }
  class vgg {
  }
  class van {
  }
  backbone --> builder
  builder --> regnet
  builder --> resnet
  builder --> squeezenet
  builder --> vgg
  builder --> van

model.backbone

build_backbone

build_backbone(_target_: str, **params) -> Module
Source code in SaigeToolkit/model/backbone/builder.py
def build_backbone(_target_: str, **params) -> nn.Module:
    if _target_ in native_models:
        builder = native_models[_target_]
    elif _target_.startswith("torchvision.models."):
        builder = getattr(torchvision.models, _target_.split(".")[-1])
    elif _target_ == "timm.create_model":
        import timm

        builder = timm.create_model
    elif _target_ == "torch.hub.load":
        builder = torch.hub.load
    else:
        raise ValueError(f"Unknown backbone target: {_target_}")

    return builder(**params)

builder

logger module-attribute

logger = getLogger('SaigeResearch')

native_models module-attribute

native_models = {'van_b0': van_b0, 'van_b1': van_b1, 'van_b2': van_b2, 'van_b3': van_b3, 'regnet_y_400mf_torchvision': regnet_y_400mf, 'regnet_y_800mf_torchvision': regnet_y_800mf, 'regnet_y_1_6gf_torchvision': regnet_y_1_6gf, 'regnet_y_3_2gf_torchvision': regnet_y_3_2gf, 'regnet_y_8gf_torchvision': regnet_y_8gf, 'regnet_y_16gf_torchvision': regnet_y_16gf, 'regnet_y_32gf_torchvision': regnet_y_32gf, 'regnet_y_128gf_torchvision': regnet_y_128gf, 'regnet_x_400mf_torchvision': regnet_x_400mf, 'regnet_x_800mf_torchvision': regnet_x_800mf, 'regnet_x_1_6gf_torchvision': regnet_x_1_6gf, 'regnet_x_3_2gf_torchvision': regnet_x_3_2gf, 'regnet_x_8gf_torchvision': regnet_x_8gf, 'regnet_x_16gf_torchvision': regnet_x_16gf, 'regnet_x_32gf_torchvision': regnet_x_32gf, 'resnet18_torchvision': resnet18, 'resnet34_torchvision': resnet34, 'resnet50_torchvision': resnet50, 'resnet101_torchvision': resnet101, 'resnet152_torchvision': resnet152, 'resnext50_32x4d_torchvision': resnext50_32x4d, 'resnext101_32x8d_torchvision': resnext101_32x8d, 'resnext101_64x4d_torchvision': resnext101_64x4d, 'wide_resnet50_2_torchvision': wide_resnet50_2, 'wide_resnet101_2_torchvision': wide_resnet101_2, 'squeezenet1_0_torchvision': squeezenet1_0, 'squeezenet1_1_torchvision': squeezenet1_1, 'vgg11_torchvision': vgg11, 'vgg11_bn_torchvision': vgg11_bn, 'vgg13_torchvision': vgg13, 'vgg13_bn_torchvision': vgg13_bn, 'vgg16_torchvision': vgg16, 'vgg16_bn_torchvision': vgg16_bn, 'vgg19_torchvision': vgg19, 'vgg19_bn_torchvision': vgg19_bn}

register_backbone

register_backbone(backbone, name: Optional[str] = None)

native_models에 백본을 등록해 build_backbone()에서 사용할 수 있도록 합니다

Source code in SaigeToolkit/model/backbone/builder.py
def register_backbone(backbone, name: Optional[str] = None):
    """`native_models`에 백본을 등록해 `build_backbone()`에서 사용할 수 있도록 합니다"""
    name = name or backbone.__name__
    if name in native_models and backbone != native_models[name]:
        raise ValueError(f"backbone name {name} already exists.")
    native_models[name] = backbone

build_backbone

build_backbone(_target_: str, **params) -> Module
Source code in SaigeToolkit/model/backbone/builder.py
def build_backbone(_target_: str, **params) -> nn.Module:
    if _target_ in native_models:
        builder = native_models[_target_]
    elif _target_.startswith("torchvision.models."):
        builder = getattr(torchvision.models, _target_.split(".")[-1])
    elif _target_ == "timm.create_model":
        import timm

        builder = timm.create_model
    elif _target_ == "torch.hub.load":
        builder = torch.hub.load
    else:
        raise ValueError(f"Unknown backbone target: {_target_}")

    return builder(**params)

norm

FrozenBatchNorm2d

FrozenBatchNorm2d(n: int)

Bases: Module

BatchNorm2d where the batch statistics and the affine parameters are fixed

Attributes:

  • weight (Tensor) –

    batch_norm weight. not nn.Parameter for freezing values.

  • bias (Tensor) –

    batch_norm bias. not nn.Parameter for freezing values.

  • running_mean (Tensor) –

    batch_norm running_mean. not nn.Parameter for freezing values.

  • running_var (Tensor) –

    batch_norm running_var. not nn.Parameter for freezing values.

Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.

Initializing FrozenBatchNorm2d

Parameters:

  • n (int) –

    number of channels for torch.Tensor

Source code in SaigeToolkit/model/backbone/norm.py
def __init__(self, n: int) -> None:
    """Initializing FrozenBatchNorm2d

    Args:
        n (int): number of channels for torch.Tensor
    """
    super(FrozenBatchNorm2d, self).__init__()
    self.register_buffer("weight", torch.ones(n))
    self.register_buffer("bias", torch.zeros(n))
    self.register_buffer("running_mean", torch.zeros(n))
    self.register_buffer("running_var", torch.ones(n))
forward
forward(x: Tensor) -> Tensor

forward function for FrozenBatchNorm2d

Parameters:

  • x (Tensor) –

    input tensor

Returns:

  • Tensor

    torch.Tensor: batch_normalized output tensor

Source code in SaigeToolkit/model/backbone/norm.py
def forward(self, x: torch.Tensor) -> torch.Tensor:
    """forward function for FrozenBatchNorm2d

    Args:
        x (torch.Tensor): input tensor

    Returns:
        torch.Tensor: batch_normalized output tensor
    """
    # Cast all fixed parameters to half() if necessary
    if x.dtype == torch.float16:
        self.weight = self.weight.half()
        self.bias = self.bias.half()
        self.running_mean = self.running_mean.half()
        self.running_var = self.running_var.half()
    scale = self.weight * self.running_var.rsqrt()
    bias = self.bias - self.running_mean * scale
    scale = scale.reshape(1, -1, 1, 1)
    bias = bias.reshape(1, -1, 1, 1)
    return x * scale + bias

get_norm

get_norm(name: str) -> Type[Module]

getting customized batch norm class

Parameters:

  • name (str) –

    batch norm class name

Returns:

  • Type[Module]

    Type[nn.Module]: custom batch norm class

Source code in SaigeToolkit/model/backbone/norm.py
def get_norm(name: str) -> Type[nn.Module]:
    """getting customized batch norm class

    Args:
        name (str): batch norm class name

    Returns:
        Type[nn.Module]: custom batch norm class
    """
    return {"fixed_batch_norm": FrozenBatchNorm2d}[name]

torchvision

regnet

__all__ module-attribute
__all__ = ['RegNet', 'regnet_y_400mf', 'regnet_y_800mf', 'regnet_y_1_6gf', 'regnet_y_3_2gf', 'regnet_y_8gf', 'regnet_y_16gf', 'regnet_y_32gf', 'regnet_y_128gf', 'regnet_x_400mf', 'regnet_x_800mf', 'regnet_x_1_6gf', 'regnet_x_3_2gf', 'regnet_x_8gf', 'regnet_x_16gf', 'regnet_x_32gf']
SimpleStemIN
SimpleStemIN(width_in: int, width_out: int, norm_layer: Callable[..., Module], activation_layer: Callable[..., Module])

Bases: Conv2dNormActivation

Simple stem for ImageNet: 3x3, BN, ReLU.

Source code in SaigeToolkit/model/backbone/torchvision/regnet.py
def __init__(
    self,
    width_in: int,
    width_out: int,
    norm_layer: Callable[..., nn.Module],
    activation_layer: Callable[..., nn.Module],
) -> None:
    super().__init__(
        width_in,
        width_out,
        kernel_size=3,
        stride=2,
        norm_layer=norm_layer,
        activation_layer=activation_layer,
    )
BottleneckTransform
BottleneckTransform(width_in: int, width_out: int, stride: int, norm_layer: Callable[..., Module], activation_layer: Callable[..., Module], group_width: int, bottleneck_multiplier: float, se_ratio: Optional[float])

Bases: Sequential

Bottleneck transformation: 1x1, 3x3 [+SE], 1x1.

Source code in SaigeToolkit/model/backbone/torchvision/regnet.py
def __init__(
    self,
    width_in: int,
    width_out: int,
    stride: int,
    norm_layer: Callable[..., nn.Module],
    activation_layer: Callable[..., nn.Module],
    group_width: int,
    bottleneck_multiplier: float,
    se_ratio: Optional[float],
) -> None:
    layers: OrderedDict[str, nn.Module] = OrderedDict()
    w_b = int(round(width_out * bottleneck_multiplier))
    g = w_b // group_width

    layers["a"] = Conv2dNormActivation(
        width_in,
        w_b,
        kernel_size=1,
        stride=1,
        norm_layer=norm_layer,
        activation_layer=activation_layer,
    )
    layers["b"] = Conv2dNormActivation(
        w_b,
        w_b,
        kernel_size=3,
        stride=stride,
        groups=g,
        norm_layer=norm_layer,
        activation_layer=activation_layer,
    )

    if se_ratio:
        # The SE reduction ratio is defined with respect to the
        # beginning of the block
        width_se_out = int(round(se_ratio * width_in))
        layers["se"] = SqueezeExcitation(
            input_channels=w_b,
            squeeze_channels=width_se_out,
            activation=activation_layer,
        )

    layers["c"] = Conv2dNormActivation(
        w_b, width_out, kernel_size=1, stride=1, norm_layer=norm_layer, activation_layer=None
    )
    super().__init__(layers)
ResBottleneckBlock
ResBottleneckBlock(width_in: int, width_out: int, stride: int, norm_layer: Callable[..., Module], activation_layer: Callable[..., Module], group_width: int = 1, bottleneck_multiplier: float = 1.0, se_ratio: Optional[float] = None)

Bases: Module

Residual bottleneck block: x + F(x), F = bottleneck transform.

Source code in SaigeToolkit/model/backbone/torchvision/regnet.py
def __init__(
    self,
    width_in: int,
    width_out: int,
    stride: int,
    norm_layer: Callable[..., nn.Module],
    activation_layer: Callable[..., nn.Module],
    group_width: int = 1,
    bottleneck_multiplier: float = 1.0,
    se_ratio: Optional[float] = None,
) -> None:
    super().__init__()

    # Use skip connection with projection if shape changes
    self.proj = None
    should_proj = (width_in != width_out) or (stride != 1)
    if should_proj:
        self.proj = Conv2dNormActivation(
            width_in,
            width_out,
            kernel_size=1,
            stride=stride,
            norm_layer=norm_layer,
            activation_layer=None,
        )
    self.f = BottleneckTransform(
        width_in,
        width_out,
        stride,
        norm_layer,
        activation_layer,
        group_width,
        bottleneck_multiplier,
        se_ratio,
    )
    self.activation = activation_layer(inplace=True)
proj instance-attribute
proj = None
f instance-attribute
f = BottleneckTransform(width_in, width_out, stride, norm_layer, activation_layer, group_width, bottleneck_multiplier, se_ratio)
activation instance-attribute
activation = activation_layer(inplace=True)
forward
forward(x: Tensor) -> Tensor
Source code in SaigeToolkit/model/backbone/torchvision/regnet.py
def forward(self, x: Tensor) -> Tensor:
    if self.proj is not None:
        x = self.proj(x) + self.f(x)
    else:
        x = x + self.f(x)
    return self.activation(x)
AnyStage
AnyStage(width_in: int, width_out: int, stride: int, depth: int, block_constructor: Callable[..., Module], norm_layer: Callable[..., Module], activation_layer: Callable[..., Module], group_width: int, bottleneck_multiplier: float, se_ratio: Optional[float] = None, stage_index: int = 0)

Bases: Sequential

AnyNet stage (sequence of blocks w/ the same output shape).

Source code in SaigeToolkit/model/backbone/torchvision/regnet.py
def __init__(
    self,
    width_in: int,
    width_out: int,
    stride: int,
    depth: int,
    block_constructor: Callable[..., nn.Module],
    norm_layer: Callable[..., nn.Module],
    activation_layer: Callable[..., nn.Module],
    group_width: int,
    bottleneck_multiplier: float,
    se_ratio: Optional[float] = None,
    stage_index: int = 0,
) -> None:
    super().__init__()

    for i in range(depth):
        block = block_constructor(
            width_in if i == 0 else width_out,
            width_out,
            stride if i == 0 else 1,
            norm_layer,
            activation_layer,
            group_width,
            bottleneck_multiplier,
            se_ratio,
        )

        self.add_module(f"block{stage_index}-{i}", block)
BlockParams
BlockParams(depths: List[int], widths: List[int], group_widths: List[int], bottleneck_multipliers: List[float], strides: List[int], se_ratio: Optional[float] = None)
Source code in SaigeToolkit/model/backbone/torchvision/regnet.py
def __init__(
    self,
    depths: List[int],
    widths: List[int],
    group_widths: List[int],
    bottleneck_multipliers: List[float],
    strides: List[int],
    se_ratio: Optional[float] = None,
) -> None:
    self.depths = depths
    self.widths = widths
    self.group_widths = group_widths
    self.bottleneck_multipliers = bottleneck_multipliers
    self.strides = strides
    self.se_ratio = se_ratio
depths instance-attribute
depths = depths
widths instance-attribute
widths = widths
group_widths instance-attribute
group_widths = group_widths
bottleneck_multipliers instance-attribute
bottleneck_multipliers = bottleneck_multipliers
strides instance-attribute
strides = strides
se_ratio instance-attribute
se_ratio = se_ratio
from_init_params classmethod
from_init_params(depth: int, w_0: int, w_a: float, w_m: float, group_width: int, bottleneck_multiplier: float = 1.0, se_ratio: Optional[float] = None, **kwargs: Any) -> BlockParams

Programmatically compute all the per-block settings, given the RegNet parameters. The first step is to compute the quantized linear block parameters, in log space. Key parameters are: - w_a is the width progression slope - w_0 is the initial width - w_m is the width stepping in the log space In other terms log(block_width) = log(w_0) + w_m * block_capacity, with bock_capacity ramping up following the w_0 and w_a params. This block width is finally quantized to multiples of 8. The second step is to compute the parameters per stage, taking into account the skip connection and the final 1x1 convolutions. We use the fact that the output width is constant within a stage.

Source code in SaigeToolkit/model/backbone/torchvision/regnet.py
@classmethod
def from_init_params(
    cls,
    depth: int,
    w_0: int,
    w_a: float,
    w_m: float,
    group_width: int,
    bottleneck_multiplier: float = 1.0,
    se_ratio: Optional[float] = None,
    **kwargs: Any,
) -> "BlockParams":
    """
    Programmatically compute all the per-block settings,
    given the RegNet parameters.
    The first step is to compute the quantized linear block parameters,
    in log space. Key parameters are:
    - `w_a` is the width progression slope
    - `w_0` is the initial width
    - `w_m` is the width stepping in the log space
    In other terms
    `log(block_width) = log(w_0) + w_m * block_capacity`,
    with `bock_capacity` ramping up following the w_0 and w_a params.
    This block width is finally quantized to multiples of 8.
    The second step is to compute the parameters per stage,
    taking into account the skip connection and the final 1x1 convolutions.
    We use the fact that the output width is constant within a stage.
    """

    QUANT = 8
    STRIDE = 2

    if w_a < 0 or w_0 <= 0 or w_m <= 1 or w_0 % 8 != 0:
        raise ValueError("Invalid RegNet settings")
    # Compute the block widths. Each stage has one unique block width
    widths_cont = torch.arange(depth) * w_a + w_0
    block_capacity = torch.round(torch.log(widths_cont / w_0) / math.log(w_m))
    block_widths = (
        (torch.round(torch.divide(w_0 * torch.pow(w_m, block_capacity), QUANT)) * QUANT)
        .int()
        .tolist()
    )
    num_stages = len(set(block_widths))

    # Convert to per stage parameters
    split_helper = zip(
        block_widths + [0],
        [0] + block_widths,
        block_widths + [0],
        [0] + block_widths,
    )
    splits = [w != wp or r != rp for w, wp, r, rp in split_helper]

    stage_widths = [w for w, t in zip(block_widths, splits[:-1]) if t]
    stage_depths = torch.diff(torch.tensor([d for d, t in enumerate(splits) if t])).int().tolist()

    strides = [STRIDE] * num_stages
    bottleneck_multipliers = [bottleneck_multiplier] * num_stages
    group_widths = [group_width] * num_stages

    # Adjust the compatibility of stage widths and group widths
    stage_widths, group_widths = cls._adjust_widths_groups_compatibilty(
        stage_widths, bottleneck_multipliers, group_widths
    )

    return cls(
        depths=stage_depths,
        widths=stage_widths,
        group_widths=group_widths,
        bottleneck_multipliers=bottleneck_multipliers,
        strides=strides,
        se_ratio=se_ratio,
    )
_get_expanded_params
_get_expanded_params()
Source code in SaigeToolkit/model/backbone/torchvision/regnet.py
def _get_expanded_params(self):
    return zip(
        self.widths, self.strides, self.depths, self.group_widths, self.bottleneck_multipliers
    )
_adjust_widths_groups_compatibilty staticmethod
_adjust_widths_groups_compatibilty(stage_widths: List[int], bottleneck_ratios: List[float], group_widths: List[int]) -> Tuple[List[int], List[int]]

Adjusts the compatibility of widths and groups, depending on the bottleneck ratio.

Source code in SaigeToolkit/model/backbone/torchvision/regnet.py
@staticmethod
def _adjust_widths_groups_compatibilty(
    stage_widths: List[int], bottleneck_ratios: List[float], group_widths: List[int]
) -> Tuple[List[int], List[int]]:
    """
    Adjusts the compatibility of widths and groups,
    depending on the bottleneck ratio.
    """
    # Compute all widths for the current settings
    widths = [int(w * b) for w, b in zip(stage_widths, bottleneck_ratios)]
    group_widths_min = [min(g, w_bot) for g, w_bot in zip(group_widths, widths)]

    # Compute the adjusted widths so that stage and group widths fit
    ws_bot = [_make_divisible(w_bot, g) for w_bot, g in zip(widths, group_widths_min)]
    stage_widths = [int(w_bot / b) for w_bot, b in zip(ws_bot, bottleneck_ratios)]
    return stage_widths, group_widths_min
RegNet
RegNet(block_params: BlockParams, num_classes: int = 1000, stem_width: int = 32, stem_type: Optional[Callable[..., Module]] = None, block_type: Optional[Callable[..., Module]] = None, norm_layer: Optional[Callable[..., Module]] = None, activation: Optional[Callable[..., Module]] = None, in_channels: int = 3)

Bases: Module

Source code in SaigeToolkit/model/backbone/torchvision/regnet.py
def __init__(
    self,
    block_params: BlockParams,
    num_classes: int = 1000,
    stem_width: int = 32,
    stem_type: Optional[Callable[..., nn.Module]] = None,
    block_type: Optional[Callable[..., nn.Module]] = None,
    norm_layer: Optional[Callable[..., nn.Module]] = None,
    activation: Optional[Callable[..., nn.Module]] = None,
    in_channels: int = 3,
) -> None:
    super().__init__()
    _log_api_usage_once(self)

    if stem_type is None:
        stem_type = SimpleStemIN
    if norm_layer is None:
        norm_layer = nn.BatchNorm2d
    if block_type is None:
        block_type = ResBottleneckBlock
    if activation is None:
        activation = nn.ReLU

    self.in_channels = in_channels

    # Ad hoc stem
    self.stem = stem_type(
        self.in_channels,  # width_in
        stem_width,
        norm_layer,
        activation,
    )

    current_width = stem_width

    blocks = []
    for i, (
        width_out,
        stride,
        depth,
        group_width,
        bottleneck_multiplier,
    ) in enumerate(block_params._get_expanded_params()):
        blocks.append(
            (
                f"block{i+1}",
                AnyStage(
                    current_width,
                    width_out,
                    stride,
                    depth,
                    block_type,
                    norm_layer,
                    activation,
                    group_width,
                    bottleneck_multiplier,
                    block_params.se_ratio,
                    stage_index=i + 1,
                ),
            )
        )

        current_width = width_out

    self.trunk_output = nn.Sequential(OrderedDict(blocks))

    # Performs ResNet-style weight initialization
    for m in self.modules():
        if isinstance(m, nn.Conv2d):
            # Note that there is no bias due to BN
            fan_out = m.kernel_size[0] * m.kernel_size[1] * m.out_channels
            nn.init.normal_(m.weight, mean=0.0, std=math.sqrt(2.0 / fan_out))
        elif isinstance(m, nn.BatchNorm2d):
            nn.init.ones_(m.weight)
            nn.init.zeros_(m.bias)
        elif isinstance(m, nn.Linear):
            nn.init.normal_(m.weight, mean=0.0, std=0.01)
            nn.init.zeros_(m.bias)
in_channels instance-attribute
in_channels = in_channels
stem instance-attribute
stem = stem_type(in_channels, stem_width, norm_layer, activation)
trunk_output instance-attribute
trunk_output = Sequential(OrderedDict(blocks))
forward
forward(x: Tensor) -> Tensor
Source code in SaigeToolkit/model/backbone/torchvision/regnet.py
def forward(self, x: Tensor) -> Tensor:
    x = self.stem(x)
    x = self.trunk_output(x)
    return x
load_state_dict
load_state_dict(state_dict, strict: bool = True)
Source code in SaigeToolkit/model/backbone/torchvision/regnet.py
def load_state_dict(self, state_dict, strict: bool = True):
    extend_state_dict_input_channel(state_dict, "stem.0.weight", self.stem[0])
    for key in list(state_dict):
        if key.startswith("fc."):
            state_dict.pop(key)
    return super().load_state_dict(state_dict, strict)
_regnet
_regnet(block_params: BlockParams, weights: Optional[WeightsEnum], progress: bool, **kwargs: Any) -> RegNet
Source code in SaigeToolkit/model/backbone/torchvision/regnet.py
def _regnet(
    block_params: BlockParams,
    weights: Optional[WeightsEnum],
    progress: bool,
    **kwargs: Any,
) -> RegNet:
    if weights is not None:
        _ovewrite_named_param(kwargs, "num_classes", len(weights.meta["categories"]))

    norm_layer = kwargs.pop("norm_layer", partial(nn.BatchNorm2d, eps=1e-05, momentum=0.1))
    model = RegNet(block_params, norm_layer=norm_layer, **kwargs)

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

    return model
regnet_y_400mf
regnet_y_400mf(*, weights: Optional[RegNet_Y_400MF_Weights] = None, progress: bool = True, **kwargs: Any) -> RegNet

Constructs a RegNetY_400MF architecture from Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>. Args: weights (:class:~torchvision.models.RegNet_Y_400MF_Weights, optional): The pretrained weights to use. See :class:~torchvision.models.RegNet_Y_400MF_Weights below for more details and possible values. By default, no pretrained weights are used. progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True. **kwargs: parameters passed to either torchvision.models.regnet.RegNet or torchvision.models.regnet.BlockParams class. Please refer to the source code <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py> for more detail about the classes. .. autoclass:: torchvision.models.RegNet_Y_400MF_Weights :members:

Source code in SaigeToolkit/model/backbone/torchvision/regnet.py
@handle_legacy_interface(weights=("pretrained", RegNet_Y_400MF_Weights.IMAGENET1K_V1))
def regnet_y_400mf(
    *, weights: Optional[RegNet_Y_400MF_Weights] = None, progress: bool = True, **kwargs: Any
) -> RegNet:
    """
    Constructs a RegNetY_400MF architecture from
    `Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>`_.
    Args:
        weights (:class:`~torchvision.models.RegNet_Y_400MF_Weights`, optional): The pretrained weights to use.
            See :class:`~torchvision.models.RegNet_Y_400MF_Weights` below for more details and possible values.
            By default, no pretrained weights are used.
        progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True.
        **kwargs: parameters passed to either ``torchvision.models.regnet.RegNet`` or
            ``torchvision.models.regnet.BlockParams`` class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py>`_
            for more detail about the classes.
    .. autoclass:: torchvision.models.RegNet_Y_400MF_Weights
        :members:
    """
    weights = RegNet_Y_400MF_Weights.verify(weights)

    params = BlockParams.from_init_params(
        depth=16, w_0=48, w_a=27.89, w_m=2.09, group_width=8, se_ratio=0.25, **kwargs
    )
    return _regnet(params, weights, progress, **kwargs)
regnet_y_800mf
regnet_y_800mf(*, weights: Optional[RegNet_Y_800MF_Weights] = None, progress: bool = True, **kwargs: Any) -> RegNet

Constructs a RegNetY_800MF architecture from Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>. Args: weights (:class:~torchvision.models.RegNet_Y_800MF_Weights, optional): The pretrained weights to use. See :class:~torchvision.models.RegNet_Y_800MF_Weights below for more details and possible values. By default, no pretrained weights are used. progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True. **kwargs: parameters passed to either torchvision.models.regnet.RegNet or torchvision.models.regnet.BlockParams class. Please refer to the source code <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py> for more detail about the classes. .. autoclass:: torchvision.models.RegNet_Y_800MF_Weights :members:

Source code in SaigeToolkit/model/backbone/torchvision/regnet.py
@handle_legacy_interface(weights=("pretrained", RegNet_Y_800MF_Weights.IMAGENET1K_V1))
def regnet_y_800mf(
    *, weights: Optional[RegNet_Y_800MF_Weights] = None, progress: bool = True, **kwargs: Any
) -> RegNet:
    """
    Constructs a RegNetY_800MF architecture from
    `Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>`_.
    Args:
        weights (:class:`~torchvision.models.RegNet_Y_800MF_Weights`, optional): The pretrained weights to use.
            See :class:`~torchvision.models.RegNet_Y_800MF_Weights` below for more details and possible values.
            By default, no pretrained weights are used.
        progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True.
        **kwargs: parameters passed to either ``torchvision.models.regnet.RegNet`` or
            ``torchvision.models.regnet.BlockParams`` class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py>`_
            for more detail about the classes.
    .. autoclass:: torchvision.models.RegNet_Y_800MF_Weights
        :members:
    """
    weights = RegNet_Y_800MF_Weights.verify(weights)

    params = BlockParams.from_init_params(
        depth=14, w_0=56, w_a=38.84, w_m=2.4, group_width=16, se_ratio=0.25, **kwargs
    )
    return _regnet(params, weights, progress, **kwargs)
regnet_y_1_6gf
regnet_y_1_6gf(*, weights: Optional[RegNet_Y_1_6GF_Weights] = None, progress: bool = True, **kwargs: Any) -> RegNet

Constructs a RegNetY_1.6GF architecture from Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>. Args: weights (:class:~torchvision.models.RegNet_Y_1_6GF_Weights, optional): The pretrained weights to use. See :class:~torchvision.models.RegNet_Y_1_6GF_Weights below for more details and possible values. By default, no pretrained weights are used. progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True. **kwargs: parameters passed to either torchvision.models.regnet.RegNet or torchvision.models.regnet.BlockParams class. Please refer to the source code <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py> for more detail about the classes. .. autoclass:: torchvision.models.RegNet_Y_1_6GF_Weights :members:

Source code in SaigeToolkit/model/backbone/torchvision/regnet.py
@handle_legacy_interface(weights=("pretrained", RegNet_Y_1_6GF_Weights.IMAGENET1K_V1))
def regnet_y_1_6gf(
    *, weights: Optional[RegNet_Y_1_6GF_Weights] = None, progress: bool = True, **kwargs: Any
) -> RegNet:
    """
    Constructs a RegNetY_1.6GF architecture from
    `Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>`_.
    Args:
        weights (:class:`~torchvision.models.RegNet_Y_1_6GF_Weights`, optional): The pretrained weights to use.
            See :class:`~torchvision.models.RegNet_Y_1_6GF_Weights` below for more details and possible values.
            By default, no pretrained weights are used.
        progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True.
        **kwargs: parameters passed to either ``torchvision.models.regnet.RegNet`` or
            ``torchvision.models.regnet.BlockParams`` class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py>`_
            for more detail about the classes.
    .. autoclass:: torchvision.models.RegNet_Y_1_6GF_Weights
        :members:
    """
    weights = RegNet_Y_1_6GF_Weights.verify(weights)

    params = BlockParams.from_init_params(
        depth=27, w_0=48, w_a=20.71, w_m=2.65, group_width=24, se_ratio=0.25, **kwargs
    )
    return _regnet(params, weights, progress, **kwargs)
regnet_y_3_2gf
regnet_y_3_2gf(*, weights: Optional[RegNet_Y_3_2GF_Weights] = None, progress: bool = True, **kwargs: Any) -> RegNet

Constructs a RegNetY_3.2GF architecture from Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>. Args: weights (:class:~torchvision.models.RegNet_Y_3_2GF_Weights, optional): The pretrained weights to use. See :class:~torchvision.models.RegNet_Y_3_2GF_Weights below for more details and possible values. By default, no pretrained weights are used. progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True. **kwargs: parameters passed to either torchvision.models.regnet.RegNet or torchvision.models.regnet.BlockParams class. Please refer to the source code <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py> for more detail about the classes. .. autoclass:: torchvision.models.RegNet_Y_3_2GF_Weights :members:

Source code in SaigeToolkit/model/backbone/torchvision/regnet.py
@handle_legacy_interface(weights=("pretrained", RegNet_Y_3_2GF_Weights.IMAGENET1K_V1))
def regnet_y_3_2gf(
    *, weights: Optional[RegNet_Y_3_2GF_Weights] = None, progress: bool = True, **kwargs: Any
) -> RegNet:
    """
    Constructs a RegNetY_3.2GF architecture from
    `Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>`_.
    Args:
        weights (:class:`~torchvision.models.RegNet_Y_3_2GF_Weights`, optional): The pretrained weights to use.
            See :class:`~torchvision.models.RegNet_Y_3_2GF_Weights` below for more details and possible values.
            By default, no pretrained weights are used.
        progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True.
        **kwargs: parameters passed to either ``torchvision.models.regnet.RegNet`` or
            ``torchvision.models.regnet.BlockParams`` class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py>`_
            for more detail about the classes.
    .. autoclass:: torchvision.models.RegNet_Y_3_2GF_Weights
        :members:
    """
    weights = RegNet_Y_3_2GF_Weights.verify(weights)

    params = BlockParams.from_init_params(
        depth=21, w_0=80, w_a=42.63, w_m=2.66, group_width=24, se_ratio=0.25, **kwargs
    )
    return _regnet(params, weights, progress, **kwargs)
regnet_y_8gf
regnet_y_8gf(*, weights: Optional[RegNet_Y_8GF_Weights] = None, progress: bool = True, **kwargs: Any) -> RegNet

Constructs a RegNetY_8GF architecture from Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>. Args: weights (:class:~torchvision.models.RegNet_Y_8GF_Weights, optional): The pretrained weights to use. See :class:~torchvision.models.RegNet_Y_8GF_Weights below for more details and possible values. By default, no pretrained weights are used. progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True. **kwargs: parameters passed to either torchvision.models.regnet.RegNet or torchvision.models.regnet.BlockParams class. Please refer to the source code <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py> for more detail about the classes. .. autoclass:: torchvision.models.RegNet_Y_8GF_Weights :members:

Source code in SaigeToolkit/model/backbone/torchvision/regnet.py
@handle_legacy_interface(weights=("pretrained", RegNet_Y_8GF_Weights.IMAGENET1K_V1))
def regnet_y_8gf(
    *, weights: Optional[RegNet_Y_8GF_Weights] = None, progress: bool = True, **kwargs: Any
) -> RegNet:
    """
    Constructs a RegNetY_8GF architecture from
    `Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>`_.
    Args:
        weights (:class:`~torchvision.models.RegNet_Y_8GF_Weights`, optional): The pretrained weights to use.
            See :class:`~torchvision.models.RegNet_Y_8GF_Weights` below for more details and possible values.
            By default, no pretrained weights are used.
        progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True.
        **kwargs: parameters passed to either ``torchvision.models.regnet.RegNet`` or
            ``torchvision.models.regnet.BlockParams`` class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py>`_
            for more detail about the classes.
    .. autoclass:: torchvision.models.RegNet_Y_8GF_Weights
        :members:
    """
    weights = RegNet_Y_8GF_Weights.verify(weights)

    params = BlockParams.from_init_params(
        depth=17, w_0=192, w_a=76.82, w_m=2.19, group_width=56, se_ratio=0.25, **kwargs
    )
    return _regnet(params, weights, progress, **kwargs)
regnet_y_16gf
regnet_y_16gf(*, weights: Optional[RegNet_Y_16GF_Weights] = None, progress: bool = True, **kwargs: Any) -> RegNet

Constructs a RegNetY_16GF architecture from Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>. Args: weights (:class:~torchvision.models.RegNet_Y_16GF_Weights, optional): The pretrained weights to use. See :class:~torchvision.models.RegNet_Y_16GF_Weights below for more details and possible values. By default, no pretrained weights are used. progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True. **kwargs: parameters passed to either torchvision.models.regnet.RegNet or torchvision.models.regnet.BlockParams class. Please refer to the source code <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py> for more detail about the classes. .. autoclass:: torchvision.models.RegNet_Y_16GF_Weights :members:

Source code in SaigeToolkit/model/backbone/torchvision/regnet.py
@handle_legacy_interface(weights=("pretrained", RegNet_Y_16GF_Weights.IMAGENET1K_V1))
def regnet_y_16gf(
    *, weights: Optional[RegNet_Y_16GF_Weights] = None, progress: bool = True, **kwargs: Any
) -> RegNet:
    """
    Constructs a RegNetY_16GF architecture from
    `Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>`_.
    Args:
        weights (:class:`~torchvision.models.RegNet_Y_16GF_Weights`, optional): The pretrained weights to use.
            See :class:`~torchvision.models.RegNet_Y_16GF_Weights` below for more details and possible values.
            By default, no pretrained weights are used.
        progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True.
        **kwargs: parameters passed to either ``torchvision.models.regnet.RegNet`` or
            ``torchvision.models.regnet.BlockParams`` class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py>`_
            for more detail about the classes.
    .. autoclass:: torchvision.models.RegNet_Y_16GF_Weights
        :members:
    """
    weights = RegNet_Y_16GF_Weights.verify(weights)

    params = BlockParams.from_init_params(
        depth=18, w_0=200, w_a=106.23, w_m=2.48, group_width=112, se_ratio=0.25, **kwargs
    )
    return _regnet(params, weights, progress, **kwargs)
regnet_y_32gf
regnet_y_32gf(*, weights: Optional[RegNet_Y_32GF_Weights] = None, progress: bool = True, **kwargs: Any) -> RegNet

Constructs a RegNetY_32GF architecture from Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>. Args: weights (:class:~torchvision.models.RegNet_Y_32GF_Weights, optional): The pretrained weights to use. See :class:~torchvision.models.RegNet_Y_32GF_Weights below for more details and possible values. By default, no pretrained weights are used. progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True. **kwargs: parameters passed to either torchvision.models.regnet.RegNet or torchvision.models.regnet.BlockParams class. Please refer to the source code <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py> for more detail about the classes. .. autoclass:: torchvision.models.RegNet_Y_32GF_Weights :members:

Source code in SaigeToolkit/model/backbone/torchvision/regnet.py
@handle_legacy_interface(weights=("pretrained", RegNet_Y_32GF_Weights.IMAGENET1K_V1))
def regnet_y_32gf(
    *, weights: Optional[RegNet_Y_32GF_Weights] = None, progress: bool = True, **kwargs: Any
) -> RegNet:
    """
    Constructs a RegNetY_32GF architecture from
    `Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>`_.
    Args:
        weights (:class:`~torchvision.models.RegNet_Y_32GF_Weights`, optional): The pretrained weights to use.
            See :class:`~torchvision.models.RegNet_Y_32GF_Weights` below for more details and possible values.
            By default, no pretrained weights are used.
        progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True.
        **kwargs: parameters passed to either ``torchvision.models.regnet.RegNet`` or
            ``torchvision.models.regnet.BlockParams`` class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py>`_
            for more detail about the classes.
    .. autoclass:: torchvision.models.RegNet_Y_32GF_Weights
        :members:
    """
    weights = RegNet_Y_32GF_Weights.verify(weights)

    params = BlockParams.from_init_params(
        depth=20, w_0=232, w_a=115.89, w_m=2.53, group_width=232, se_ratio=0.25, **kwargs
    )
    return _regnet(params, weights, progress, **kwargs)
regnet_y_128gf
regnet_y_128gf(*, weights: Optional[RegNet_Y_128GF_Weights] = None, progress: bool = True, **kwargs: Any) -> RegNet

Constructs a RegNetY_128GF architecture from Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>. Args: weights (:class:~torchvision.models.RegNet_Y_128GF_Weights, optional): The pretrained weights to use. See :class:~torchvision.models.RegNet_Y_128GF_Weights below for more details and possible values. By default, no pretrained weights are used. progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True. **kwargs: parameters passed to either torchvision.models.regnet.RegNet or torchvision.models.regnet.BlockParams class. Please refer to the source code <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py> for more detail about the classes. .. autoclass:: torchvision.models.RegNet_Y_128GF_Weights :members:

Source code in SaigeToolkit/model/backbone/torchvision/regnet.py
@handle_legacy_interface(weights=("pretrained", None))
def regnet_y_128gf(
    *, weights: Optional[RegNet_Y_128GF_Weights] = None, progress: bool = True, **kwargs: Any
) -> RegNet:
    """
    Constructs a RegNetY_128GF architecture from
    `Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>`_.
    Args:
        weights (:class:`~torchvision.models.RegNet_Y_128GF_Weights`, optional): The pretrained weights to use.
            See :class:`~torchvision.models.RegNet_Y_128GF_Weights` below for more details and possible values.
            By default, no pretrained weights are used.
        progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True.
        **kwargs: parameters passed to either ``torchvision.models.regnet.RegNet`` or
            ``torchvision.models.regnet.BlockParams`` class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py>`_
            for more detail about the classes.
    .. autoclass:: torchvision.models.RegNet_Y_128GF_Weights
        :members:
    """
    weights = RegNet_Y_128GF_Weights.verify(weights)

    params = BlockParams.from_init_params(
        depth=27, w_0=456, w_a=160.83, w_m=2.52, group_width=264, se_ratio=0.25, **kwargs
    )
    return _regnet(params, weights, progress, **kwargs)
regnet_x_400mf
regnet_x_400mf(*, weights: Optional[RegNet_X_400MF_Weights] = None, progress: bool = True, **kwargs: Any) -> RegNet

Constructs a RegNetX_400MF architecture from Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>. Args: weights (:class:~torchvision.models.RegNet_X_400MF_Weights, optional): The pretrained weights to use. See :class:~torchvision.models.RegNet_X_400MF_Weights below for more details and possible values. By default, no pretrained weights are used. progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True. **kwargs: parameters passed to either torchvision.models.regnet.RegNet or torchvision.models.regnet.BlockParams class. Please refer to the source code <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py> for more detail about the classes. .. autoclass:: torchvision.models.RegNet_X_400MF_Weights :members:

Source code in SaigeToolkit/model/backbone/torchvision/regnet.py
@handle_legacy_interface(weights=("pretrained", RegNet_X_400MF_Weights.IMAGENET1K_V1))
def regnet_x_400mf(
    *, weights: Optional[RegNet_X_400MF_Weights] = None, progress: bool = True, **kwargs: Any
) -> RegNet:
    """
    Constructs a RegNetX_400MF architecture from
    `Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>`_.
    Args:
        weights (:class:`~torchvision.models.RegNet_X_400MF_Weights`, optional): The pretrained weights to use.
            See :class:`~torchvision.models.RegNet_X_400MF_Weights` below for more details and possible values.
            By default, no pretrained weights are used.
        progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True.
        **kwargs: parameters passed to either ``torchvision.models.regnet.RegNet`` or
            ``torchvision.models.regnet.BlockParams`` class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py>`_
            for more detail about the classes.
    .. autoclass:: torchvision.models.RegNet_X_400MF_Weights
        :members:
    """
    weights = RegNet_X_400MF_Weights.verify(weights)

    params = BlockParams.from_init_params(
        depth=22, w_0=24, w_a=24.48, w_m=2.54, group_width=16, **kwargs
    )
    return _regnet(params, weights, progress, **kwargs)
regnet_x_800mf
regnet_x_800mf(*, weights: Optional[RegNet_X_800MF_Weights] = None, progress: bool = True, **kwargs: Any) -> RegNet

Constructs a RegNetX_800MF architecture from Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>. Args: weights (:class:~torchvision.models.RegNet_X_800MF_Weights, optional): The pretrained weights to use. See :class:~torchvision.models.RegNet_X_800MF_Weights below for more details and possible values. By default, no pretrained weights are used. progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True. **kwargs: parameters passed to either torchvision.models.regnet.RegNet or torchvision.models.regnet.BlockParams class. Please refer to the source code <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py> for more detail about the classes. .. autoclass:: torchvision.models.RegNet_X_800MF_Weights :members:

Source code in SaigeToolkit/model/backbone/torchvision/regnet.py
@handle_legacy_interface(weights=("pretrained", RegNet_X_800MF_Weights.IMAGENET1K_V1))
def regnet_x_800mf(
    *, weights: Optional[RegNet_X_800MF_Weights] = None, progress: bool = True, **kwargs: Any
) -> RegNet:
    """
    Constructs a RegNetX_800MF architecture from
    `Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>`_.
    Args:
        weights (:class:`~torchvision.models.RegNet_X_800MF_Weights`, optional): The pretrained weights to use.
            See :class:`~torchvision.models.RegNet_X_800MF_Weights` below for more details and possible values.
            By default, no pretrained weights are used.
        progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True.
        **kwargs: parameters passed to either ``torchvision.models.regnet.RegNet`` or
            ``torchvision.models.regnet.BlockParams`` class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py>`_
            for more detail about the classes.
    .. autoclass:: torchvision.models.RegNet_X_800MF_Weights
        :members:
    """
    weights = RegNet_X_800MF_Weights.verify(weights)

    params = BlockParams.from_init_params(
        depth=16, w_0=56, w_a=35.73, w_m=2.28, group_width=16, **kwargs
    )
    return _regnet(params, weights, progress, **kwargs)
regnet_x_1_6gf
regnet_x_1_6gf(*, weights: Optional[RegNet_X_1_6GF_Weights] = None, progress: bool = True, **kwargs: Any) -> RegNet

Constructs a RegNetX_1.6GF architecture from Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>. Args: weights (:class:~torchvision.models.RegNet_X_1_6GF_Weights, optional): The pretrained weights to use. See :class:~torchvision.models.RegNet_X_1_6GF_Weights below for more details and possible values. By default, no pretrained weights are used. progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True. **kwargs: parameters passed to either torchvision.models.regnet.RegNet or torchvision.models.regnet.BlockParams class. Please refer to the source code <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py> for more detail about the classes. .. autoclass:: torchvision.models.RegNet_X_1_6GF_Weights :members:

Source code in SaigeToolkit/model/backbone/torchvision/regnet.py
@handle_legacy_interface(weights=("pretrained", RegNet_X_1_6GF_Weights.IMAGENET1K_V1))
def regnet_x_1_6gf(
    *, weights: Optional[RegNet_X_1_6GF_Weights] = None, progress: bool = True, **kwargs: Any
) -> RegNet:
    """
    Constructs a RegNetX_1.6GF architecture from
    `Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>`_.
    Args:
        weights (:class:`~torchvision.models.RegNet_X_1_6GF_Weights`, optional): The pretrained weights to use.
            See :class:`~torchvision.models.RegNet_X_1_6GF_Weights` below for more details and possible values.
            By default, no pretrained weights are used.
        progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True.
        **kwargs: parameters passed to either ``torchvision.models.regnet.RegNet`` or
            ``torchvision.models.regnet.BlockParams`` class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py>`_
            for more detail about the classes.
    .. autoclass:: torchvision.models.RegNet_X_1_6GF_Weights
        :members:
    """
    weights = RegNet_X_1_6GF_Weights.verify(weights)

    params = BlockParams.from_init_params(
        depth=18, w_0=80, w_a=34.01, w_m=2.25, group_width=24, **kwargs
    )
    return _regnet(params, weights, progress, **kwargs)
regnet_x_3_2gf
regnet_x_3_2gf(*, weights: Optional[RegNet_X_3_2GF_Weights] = None, progress: bool = True, **kwargs: Any) -> RegNet

Constructs a RegNetX_3.2GF architecture from Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>. Args: weights (:class:~torchvision.models.RegNet_X_3_2GF_Weights, optional): The pretrained weights to use. See :class:~torchvision.models.RegNet_X_3_2GF_Weights below for more details and possible values. By default, no pretrained weights are used. progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True. **kwargs: parameters passed to either torchvision.models.regnet.RegNet or torchvision.models.regnet.BlockParams class. Please refer to the source code <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py> for more detail about the classes. .. autoclass:: torchvision.models.RegNet_X_3_2GF_Weights :members:

Source code in SaigeToolkit/model/backbone/torchvision/regnet.py
@handle_legacy_interface(weights=("pretrained", RegNet_X_3_2GF_Weights.IMAGENET1K_V1))
def regnet_x_3_2gf(
    *, weights: Optional[RegNet_X_3_2GF_Weights] = None, progress: bool = True, **kwargs: Any
) -> RegNet:
    """
    Constructs a RegNetX_3.2GF architecture from
    `Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>`_.
    Args:
        weights (:class:`~torchvision.models.RegNet_X_3_2GF_Weights`, optional): The pretrained weights to use.
            See :class:`~torchvision.models.RegNet_X_3_2GF_Weights` below for more details and possible values.
            By default, no pretrained weights are used.
        progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True.
        **kwargs: parameters passed to either ``torchvision.models.regnet.RegNet`` or
            ``torchvision.models.regnet.BlockParams`` class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py>`_
            for more detail about the classes.
    .. autoclass:: torchvision.models.RegNet_X_3_2GF_Weights
        :members:
    """
    weights = RegNet_X_3_2GF_Weights.verify(weights)

    params = BlockParams.from_init_params(
        depth=25, w_0=88, w_a=26.31, w_m=2.25, group_width=48, **kwargs
    )
    return _regnet(params, weights, progress, **kwargs)
regnet_x_8gf
regnet_x_8gf(*, weights: Optional[RegNet_X_8GF_Weights] = None, progress: bool = True, **kwargs: Any) -> RegNet

Constructs a RegNetX_8GF architecture from Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>. Args: weights (:class:~torchvision.models.RegNet_X_8GF_Weights, optional): The pretrained weights to use. See :class:~torchvision.models.RegNet_X_8GF_Weights below for more details and possible values. By default, no pretrained weights are used. progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True. **kwargs: parameters passed to either torchvision.models.regnet.RegNet or torchvision.models.regnet.BlockParams class. Please refer to the source code <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py> for more detail about the classes. .. autoclass:: torchvision.models.RegNet_X_8GF_Weights :members:

Source code in SaigeToolkit/model/backbone/torchvision/regnet.py
@handle_legacy_interface(weights=("pretrained", RegNet_X_8GF_Weights.IMAGENET1K_V1))
def regnet_x_8gf(
    *, weights: Optional[RegNet_X_8GF_Weights] = None, progress: bool = True, **kwargs: Any
) -> RegNet:
    """
    Constructs a RegNetX_8GF architecture from
    `Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>`_.
    Args:
        weights (:class:`~torchvision.models.RegNet_X_8GF_Weights`, optional): The pretrained weights to use.
            See :class:`~torchvision.models.RegNet_X_8GF_Weights` below for more details and possible values.
            By default, no pretrained weights are used.
        progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True.
        **kwargs: parameters passed to either ``torchvision.models.regnet.RegNet`` or
            ``torchvision.models.regnet.BlockParams`` class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py>`_
            for more detail about the classes.
    .. autoclass:: torchvision.models.RegNet_X_8GF_Weights
        :members:
    """
    weights = RegNet_X_8GF_Weights.verify(weights)

    params = BlockParams.from_init_params(
        depth=23, w_0=80, w_a=49.56, w_m=2.88, group_width=120, **kwargs
    )
    return _regnet(params, weights, progress, **kwargs)
regnet_x_16gf
regnet_x_16gf(*, weights: Optional[RegNet_X_16GF_Weights] = None, progress: bool = True, **kwargs: Any) -> RegNet

Constructs a RegNetX_16GF architecture from Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>. Args: weights (:class:~torchvision.models.RegNet_X_16GF_Weights, optional): The pretrained weights to use. See :class:~torchvision.models.RegNet_X_16GF_Weights below for more details and possible values. By default, no pretrained weights are used. progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True. **kwargs: parameters passed to either torchvision.models.regnet.RegNet or torchvision.models.regnet.BlockParams class. Please refer to the source code <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py> for more detail about the classes. .. autoclass:: torchvision.models.RegNet_X_16GF_Weights :members:

Source code in SaigeToolkit/model/backbone/torchvision/regnet.py
@handle_legacy_interface(weights=("pretrained", RegNet_X_16GF_Weights.IMAGENET1K_V1))
def regnet_x_16gf(
    *, weights: Optional[RegNet_X_16GF_Weights] = None, progress: bool = True, **kwargs: Any
) -> RegNet:
    """
    Constructs a RegNetX_16GF architecture from
    `Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>`_.
    Args:
        weights (:class:`~torchvision.models.RegNet_X_16GF_Weights`, optional): The pretrained weights to use.
            See :class:`~torchvision.models.RegNet_X_16GF_Weights` below for more details and possible values.
            By default, no pretrained weights are used.
        progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True.
        **kwargs: parameters passed to either ``torchvision.models.regnet.RegNet`` or
            ``torchvision.models.regnet.BlockParams`` class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py>`_
            for more detail about the classes.
    .. autoclass:: torchvision.models.RegNet_X_16GF_Weights
        :members:
    """
    weights = RegNet_X_16GF_Weights.verify(weights)

    params = BlockParams.from_init_params(
        depth=22, w_0=216, w_a=55.59, w_m=2.1, group_width=128, **kwargs
    )
    return _regnet(params, weights, progress, **kwargs)
regnet_x_32gf
regnet_x_32gf(*, weights: Optional[RegNet_X_32GF_Weights] = None, progress: bool = True, **kwargs: Any) -> RegNet

Constructs a RegNetX_32GF architecture from Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>. Args: weights (:class:~torchvision.models.RegNet_X_32GF_Weights, optional): The pretrained weights to use. See :class:~torchvision.models.RegNet_X_32GF_Weights below for more details and possible values. By default, no pretrained weights are used. progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True. **kwargs: parameters passed to either torchvision.models.regnet.RegNet or torchvision.models.regnet.BlockParams class. Please refer to the source code <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py> for more detail about the classes. .. autoclass:: torchvision.models.RegNet_X_32GF_Weights :members:

Source code in SaigeToolkit/model/backbone/torchvision/regnet.py
@handle_legacy_interface(weights=("pretrained", RegNet_X_32GF_Weights.IMAGENET1K_V1))
def regnet_x_32gf(
    *, weights: Optional[RegNet_X_32GF_Weights] = None, progress: bool = True, **kwargs: Any
) -> RegNet:
    """
    Constructs a RegNetX_32GF architecture from
    `Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>`_.
    Args:
        weights (:class:`~torchvision.models.RegNet_X_32GF_Weights`, optional): The pretrained weights to use.
            See :class:`~torchvision.models.RegNet_X_32GF_Weights` below for more details and possible values.
            By default, no pretrained weights are used.
        progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True.
        **kwargs: parameters passed to either ``torchvision.models.regnet.RegNet`` or
            ``torchvision.models.regnet.BlockParams`` class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py>`_
            for more detail about the classes.
    .. autoclass:: torchvision.models.RegNet_X_32GF_Weights
        :members:
    """
    weights = RegNet_X_32GF_Weights.verify(weights)

    params = BlockParams.from_init_params(
        depth=23, w_0=320, w_a=69.86, w_m=2.0, group_width=168, **kwargs
    )
    return _regnet(params, weights, progress, **kwargs)

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
expansion class-attribute instance-attribute
expansion: int = 1
conv1 instance-attribute
conv1 = conv3x3(inplanes, planes, stride)
bn1 instance-attribute
bn1 = norm_layer(planes)
relu instance-attribute
relu = ReLU(inplace=True)
conv2 instance-attribute
conv2 = conv3x3(planes, planes)
bn2 instance-attribute
bn2 = norm_layer(planes)
downsample instance-attribute
downsample = downsample
stride instance-attribute
stride = stride
forward
forward(x: Tensor) -> Tensor
Source code in SaigeToolkit/model/backbone/torchvision/resnet.py
def forward(self, x: Tensor) -> Tensor:
    identity = x

    out = self.conv1(x)
    out = self.bn1(out)
    out = self.relu(out)

    out = self.conv2(out)
    out = self.bn2(out)

    if self.downsample is not None:
        identity = self.downsample(x)

    out += identity
    out = self.relu(out)

    return out
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
expansion class-attribute instance-attribute
expansion: int = 4
conv1 instance-attribute
conv1 = conv1x1(inplanes, width)
bn1 instance-attribute
bn1 = norm_layer(width)
conv2 instance-attribute
conv2 = conv3x3(width, width, stride, groups, dilation)
bn2 instance-attribute
bn2 = norm_layer(width)
conv3 instance-attribute
conv3 = conv1x1(width, planes * expansion)
bn3 instance-attribute
bn3 = norm_layer(planes * expansion)
relu instance-attribute
relu = ReLU(inplace=True)
downsample instance-attribute
downsample = downsample
stride instance-attribute
stride = stride
forward
forward(x: Tensor) -> Tensor
Source code in SaigeToolkit/model/backbone/torchvision/resnet.py
def forward(self, x: Tensor) -> Tensor:
    identity = x

    out = self.conv1(x)
    out = self.bn1(out)
    out = self.relu(out)

    out = self.conv2(out)
    out = self.bn2(out)
    out = self.relu(out)

    out = self.conv3(out)
    out = self.bn3(out)

    if self.downsample is not None:
        identity = self.downsample(x)

    out += identity
    out = self.relu(out)

    return out
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]
_norm_layer instance-attribute
_norm_layer = norm_layer
in_channels instance-attribute
in_channels = in_channels
inplanes instance-attribute
inplanes = 64
dilation instance-attribute
dilation = 1
groups instance-attribute
groups = groups
base_width instance-attribute
base_width = width_per_group
conv1 instance-attribute
conv1 = Conv2d(in_channels, inplanes, kernel_size=7, stride=2, padding=3, bias=False)
bn1 instance-attribute
bn1 = norm_layer(inplanes)
relu instance-attribute
relu = ReLU(inplace=True)
maxpool instance-attribute
maxpool = MaxPool2d(kernel_size=3, stride=2, padding=1)
layer1 instance-attribute
layer1 = _make_layer(block, 64, layers[0])
layer2 instance-attribute
layer2 = _make_layer(block, 128, layers[1], stride=2, dilate=replace_stride_with_dilation[0])
layer3 instance-attribute
layer3 = _make_layer(block, 256, layers[2], stride=2, dilate=replace_stride_with_dilation[1])
layer4 instance-attribute
layer4 = _make_layer(block, 512, layers[3], stride=2, dilate=replace_stride_with_dilation[2])
_make_layer
_make_layer(block: Type[Union[BasicBlock, Bottleneck]], planes: int, blocks: int, stride: int = 1, dilate: bool = False) -> Sequential
Source code in SaigeToolkit/model/backbone/torchvision/resnet.py
def _make_layer(
    self,
    block: Type[Union[BasicBlock, Bottleneck]],
    planes: int,
    blocks: int,
    stride: int = 1,
    dilate: bool = False,
) -> nn.Sequential:
    norm_layer = self._norm_layer
    downsample = None
    previous_dilation = self.dilation
    if dilate:
        self.dilation *= stride
        stride = 1
    if stride != 1 or self.inplanes != planes * block.expansion:
        downsample = nn.Sequential(
            conv1x1(self.inplanes, planes * block.expansion, stride),
            norm_layer(planes * block.expansion),
        )

    layers = []
    layers.append(
        block(
            self.inplanes,
            planes,
            stride,
            downsample,
            self.groups,
            self.base_width,
            previous_dilation,
            norm_layer,
        )
    )
    self.inplanes = planes * block.expansion
    for _ in range(1, blocks):
        layers.append(
            block(
                self.inplanes,
                planes,
                groups=self.groups,
                base_width=self.base_width,
                dilation=self.dilation,
                norm_layer=norm_layer,
            )
        )

    return nn.Sequential(*layers)
_forward_impl
_forward_impl(x: Tensor) -> Tensor
Source code in SaigeToolkit/model/backbone/torchvision/resnet.py
def _forward_impl(self, x: Tensor) -> Tensor:
    # See note [TorchScript super()]
    x = self.conv1(x)
    x = self.bn1(x)
    x = self.relu(x)
    x = self.maxpool(x)

    x = self.layer1(x)
    x = self.layer2(x)
    x = self.layer3(x)
    x = self.layer4(x)

    return x
forward
forward(x: Tensor) -> Tensor
Source code in SaigeToolkit/model/backbone/torchvision/resnet.py
def forward(self, x: Tensor) -> Tensor:
    return self._forward_impl(x)
load_state_dict
load_state_dict(state_dict, strict: bool = True)
Source code in SaigeToolkit/model/backbone/torchvision/resnet.py
def load_state_dict(self, state_dict, strict: bool = True):
    extend_state_dict_input_channel(state_dict, "conv1.weight", self.conv1)
    for key in list(state_dict):
        if key.startswith("fc."):
            state_dict.pop(key)
    return super().load_state_dict(state_dict, strict)
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)

squeezenet

__all__ module-attribute
__all__ = ['SqueezeNet', 'squeezenet1_0', 'squeezenet1_1']
Fire
Fire(inplanes: int, squeeze_planes: int, expand1x1_planes: int, expand3x3_planes: int)

Bases: Module

Source code in SaigeToolkit/model/backbone/torchvision/squeezenet.py
def __init__(
    self, inplanes: int, squeeze_planes: int, expand1x1_planes: int, expand3x3_planes: int
) -> None:
    super().__init__()
    self.inplanes = inplanes
    self.squeeze = nn.Conv2d(inplanes, squeeze_planes, kernel_size=1)
    self.squeeze_activation = nn.ReLU(inplace=True)
    self.expand1x1 = nn.Conv2d(squeeze_planes, expand1x1_planes, kernel_size=1)
    self.expand1x1_activation = nn.ReLU(inplace=True)
    self.expand3x3 = nn.Conv2d(squeeze_planes, expand3x3_planes, kernel_size=3, padding=1)
    self.expand3x3_activation = nn.ReLU(inplace=True)
inplanes instance-attribute
inplanes = inplanes
squeeze instance-attribute
squeeze = Conv2d(inplanes, squeeze_planes, kernel_size=1)
squeeze_activation instance-attribute
squeeze_activation = ReLU(inplace=True)
expand1x1 instance-attribute
expand1x1 = Conv2d(squeeze_planes, expand1x1_planes, kernel_size=1)
expand1x1_activation instance-attribute
expand1x1_activation = ReLU(inplace=True)
expand3x3 instance-attribute
expand3x3 = Conv2d(squeeze_planes, expand3x3_planes, kernel_size=3, padding=1)
expand3x3_activation instance-attribute
expand3x3_activation = ReLU(inplace=True)
forward
forward(x: Tensor) -> Tensor
Source code in SaigeToolkit/model/backbone/torchvision/squeezenet.py
def forward(self, x: torch.Tensor) -> torch.Tensor:
    x = self.squeeze_activation(self.squeeze(x))
    return torch.cat(
        [self.expand1x1_activation(self.expand1x1(x)), self.expand3x3_activation(self.expand3x3(x))],
        1,
    )
SqueezeNet
SqueezeNet(version: str = '1_0', num_classes: int = 1000, dropout: float = 0.5, in_channels: int = 3)

Bases: Module

Source code in SaigeToolkit/model/backbone/torchvision/squeezenet.py
def __init__(
    self,
    version: str = "1_0",
    num_classes: int = 1000,
    dropout: float = 0.5,
    in_channels: int = 3,
) -> None:
    super().__init__()
    _log_api_usage_once(self)
    self.num_classes = num_classes
    self.in_channels = in_channels
    if version == "1_0":
        self.features = nn.Sequential(
            nn.Conv2d(self.in_channels, 96, kernel_size=7, stride=2),
            nn.ReLU(inplace=True),
            nn.MaxPool2d(kernel_size=3, stride=2, ceil_mode=True),
            Fire(96, 16, 64, 64),
            Fire(128, 16, 64, 64),
            Fire(128, 32, 128, 128),
            nn.MaxPool2d(kernel_size=3, stride=2, ceil_mode=True),
            Fire(256, 32, 128, 128),
            Fire(256, 48, 192, 192),
            Fire(384, 48, 192, 192),
            Fire(384, 64, 256, 256),
            nn.MaxPool2d(kernel_size=3, stride=2, ceil_mode=True),
            Fire(512, 64, 256, 256),
        )
    elif version == "1_1":
        self.features = nn.Sequential(
            nn.Conv2d(self.in_channels, 64, kernel_size=3, stride=2),
            nn.ReLU(inplace=True),
            nn.MaxPool2d(kernel_size=3, stride=2, ceil_mode=True),
            Fire(64, 16, 64, 64),
            Fire(128, 16, 64, 64),
            nn.MaxPool2d(kernel_size=3, stride=2, ceil_mode=True),
            Fire(128, 32, 128, 128),
            Fire(256, 32, 128, 128),
            nn.MaxPool2d(kernel_size=3, stride=2, ceil_mode=True),
            Fire(256, 48, 192, 192),
            Fire(384, 48, 192, 192),
            Fire(384, 64, 256, 256),
            Fire(512, 64, 256, 256),
        )
    else:
        # FIXME: Is this needed? SqueezeNet should only be called from the
        # FIXME: squeezenet1_x() functions
        # FIXME: This checking is not done for the other models
        raise ValueError(f"Unsupported SqueezeNet version {version}: 1_0 or 1_1 expected")

    for m in self.modules():
        if isinstance(m, nn.Conv2d):
            init.kaiming_uniform_(m.weight)
            if m.bias is not None:
                init.constant_(m.bias, 0)
num_classes instance-attribute
num_classes = num_classes
in_channels instance-attribute
in_channels = in_channels
features instance-attribute
features = Sequential(Conv2d(in_channels, 96, kernel_size=7, stride=2), ReLU(inplace=True), MaxPool2d(kernel_size=3, stride=2, ceil_mode=True), Fire(96, 16, 64, 64), Fire(128, 16, 64, 64), Fire(128, 32, 128, 128), MaxPool2d(kernel_size=3, stride=2, ceil_mode=True), Fire(256, 32, 128, 128), Fire(256, 48, 192, 192), Fire(384, 48, 192, 192), Fire(384, 64, 256, 256), MaxPool2d(kernel_size=3, stride=2, ceil_mode=True), Fire(512, 64, 256, 256))
forward
forward(x: Tensor) -> Tensor
Source code in SaigeToolkit/model/backbone/torchvision/squeezenet.py
def forward(self, x: torch.Tensor) -> torch.Tensor:
    x = self.features(x)
    return x
load_state_dict
load_state_dict(state_dict, strict: bool = True)
Source code in SaigeToolkit/model/backbone/torchvision/squeezenet.py
def load_state_dict(self, state_dict, strict: bool = True):
    extend_state_dict_input_channel(state_dict, "features.0.weight", self.features[0])
    for key in list(state_dict):
        if key.startswith("classifier."):
            state_dict.pop(key)
    return super().load_state_dict(state_dict, strict)
_squeezenet
_squeezenet(version: str, weights: Optional[WeightsEnum], progress: bool, **kwargs: Any) -> SqueezeNet
Source code in SaigeToolkit/model/backbone/torchvision/squeezenet.py
def _squeezenet(
    version: str,
    weights: Optional[WeightsEnum],
    progress: bool,
    **kwargs: Any,
) -> SqueezeNet:
    if weights is not None:
        _ovewrite_named_param(kwargs, "num_classes", len(weights.meta["categories"]))

    model = SqueezeNet(version, **kwargs)

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

    return model
squeezenet1_0
squeezenet1_0(*, weights: Optional[SqueezeNet1_0_Weights] = None, progress: bool = True, **kwargs: Any) -> SqueezeNet

SqueezeNet model architecture from the SqueezeNet: AlexNet-level accuracy with 50x fewer parameters and <0.5MB model size <https://arxiv.org/abs/1602.07360>_ paper.

Parameters:

  • weights

    class:~torchvision.models.SqueezeNet1_0_Weights, optional): The pretrained weights to use. See :class:~torchvision.models.SqueezeNet1_0_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.squeezenet.SqueezeNet base class. Please refer to the source code <https://github.com/pytorch/vision/blob/main/torchvision/models/squeezenet.py>_ for more details about this class.

.. autoclass:: torchvision.models.SqueezeNet1_0_Weights :members:

Source code in SaigeToolkit/model/backbone/torchvision/squeezenet.py
@handle_legacy_interface(weights=("pretrained", SqueezeNet1_0_Weights.IMAGENET1K_V1))
def squeezenet1_0(
    *, weights: Optional[SqueezeNet1_0_Weights] = None, progress: bool = True, **kwargs: Any
) -> SqueezeNet:
    """SqueezeNet model architecture from the `SqueezeNet: AlexNet-level
    accuracy with 50x fewer parameters and <0.5MB model size
    <https://arxiv.org/abs/1602.07360>`_ paper.

    Args:
        weights (:class:`~torchvision.models.SqueezeNet1_0_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.SqueezeNet1_0_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.squeezenet.SqueezeNet``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/squeezenet.py>`_
            for more details about this class.

    .. autoclass:: torchvision.models.SqueezeNet1_0_Weights
        :members:
    """
    weights = SqueezeNet1_0_Weights.verify(weights)
    return _squeezenet("1_0", weights, progress, **kwargs)
squeezenet1_1
squeezenet1_1(*, weights: Optional[SqueezeNet1_1_Weights] = None, progress: bool = True, **kwargs: Any) -> SqueezeNet

SqueezeNet 1.1 model from the official SqueezeNet repo <https://github.com/DeepScale/SqueezeNet/tree/master/SqueezeNet_v1.1>_.

SqueezeNet 1.1 has 2.4x less computation and slightly fewer parameters than SqueezeNet 1.0, without sacrificing accuracy.

Parameters:

  • weights

    class:~torchvision.models.SqueezeNet1_1_Weights, optional): The pretrained weights to use. See :class:~torchvision.models.SqueezeNet1_1_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.squeezenet.SqueezeNet base class. Please refer to the source code <https://github.com/pytorch/vision/blob/main/torchvision/models/squeezenet.py>_ for more details about this class.

.. autoclass:: torchvision.models.SqueezeNet1_1_Weights :members:

Source code in SaigeToolkit/model/backbone/torchvision/squeezenet.py
@handle_legacy_interface(weights=("pretrained", SqueezeNet1_1_Weights.IMAGENET1K_V1))
def squeezenet1_1(
    *, weights: Optional[SqueezeNet1_1_Weights] = None, progress: bool = True, **kwargs: Any
) -> SqueezeNet:
    """SqueezeNet 1.1 model from the `official SqueezeNet repo
    <https://github.com/DeepScale/SqueezeNet/tree/master/SqueezeNet_v1.1>`_.

    SqueezeNet 1.1 has 2.4x less computation and slightly fewer parameters
    than SqueezeNet 1.0, without sacrificing accuracy.

    Args:
        weights (:class:`~torchvision.models.SqueezeNet1_1_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.SqueezeNet1_1_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.squeezenet.SqueezeNet``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/squeezenet.py>`_
            for more details about this class.

    .. autoclass:: torchvision.models.SqueezeNet1_1_Weights
        :members:
    """
    weights = SqueezeNet1_1_Weights.verify(weights)
    return _squeezenet("1_1", weights, progress, **kwargs)

vgg

__all__ module-attribute
__all__ = ['VGG', 'vgg11', 'vgg11_bn', 'vgg13', 'vgg13_bn', 'vgg16', 'vgg16_bn', 'vgg19', 'vgg19_bn']
cfgs module-attribute
cfgs: Dict[str, List[Union[str, int]]] = {'A': [64, 'M', 128, 'M', 256, 256, 'M', 512, 512, 'M', 512, 512, 'M'], 'B': [64, 64, 'M', 128, 128, 'M', 256, 256, 'M', 512, 512, 'M', 512, 512, 'M'], 'D': [64, 64, 'M', 128, 128, 'M', 256, 256, 256, 'M', 512, 512, 512, 'M', 512, 512, 512, 'M'], 'E': [64, 64, 'M', 128, 128, 'M', 256, 256, 256, 256, 'M', 512, 512, 512, 512, 'M', 512, 512, 512, 512, 'M']}
VGG
VGG(features: Module, num_classes: int = 1000, init_weights: bool = True, dropout: float = 0.5)

Bases: Module

Source code in SaigeToolkit/model/backbone/torchvision/vgg.py
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
    if init_weights:
        for m in self.modules():
            if isinstance(m, nn.Conv2d):
                nn.init.kaiming_normal_(m.weight, mode="fan_out", nonlinearity="relu")
                if m.bias is not None:
                    nn.init.constant_(m.bias, 0)
            elif isinstance(m, nn.BatchNorm2d):
                nn.init.constant_(m.weight, 1)
                nn.init.constant_(m.bias, 0)
            elif isinstance(m, nn.Linear):
                nn.init.normal_(m.weight, 0, 0.01)
                nn.init.constant_(m.bias, 0)
features instance-attribute
features = features
forward
forward(x: Tensor) -> Tensor
Source code in SaigeToolkit/model/backbone/torchvision/vgg.py
def forward(self, x: torch.Tensor) -> torch.Tensor:
    x = self.features(x)
    return x
load_state_dict
load_state_dict(state_dict, strict: bool = True)
Source code in SaigeToolkit/model/backbone/torchvision/vgg.py
def load_state_dict(self, state_dict, strict: bool = True):
    extend_state_dict_input_channel(state_dict, "features.0.weight", self.features[0])
    for key in list(state_dict):
        if key.startswith("classifier."):
            state_dict.pop(key)
    return super().load_state_dict(state_dict, strict)
make_layers
make_layers(cfg: List[Union[str, int]], batch_norm: bool = False, in_channels: int = 3) -> Sequential
Source code in SaigeToolkit/model/backbone/torchvision/vgg.py
def make_layers(
    cfg: List[Union[str, int]], batch_norm: bool = False, in_channels: int = 3
) -> nn.Sequential:
    layers: List[nn.Module] = []
    for v in cfg:
        if v == "M":
            layers += [nn.MaxPool2d(kernel_size=2, stride=2)]
        else:
            v = cast(int, v)
            conv2d = nn.Conv2d(in_channels, v, kernel_size=3, padding=1)
            if batch_norm:
                layers += [conv2d, nn.BatchNorm2d(v), nn.ReLU(inplace=True)]
            else:
                layers += [conv2d, nn.ReLU(inplace=True)]
            in_channels = v
    return nn.Sequential(*layers)
_vgg
_vgg(cfg: str, batch_norm: bool, weights: Optional[WeightsEnum], progress: bool, in_channels: int = 3, **kwargs: Any) -> VGG
Source code in SaigeToolkit/model/backbone/torchvision/vgg.py
def _vgg(
    cfg: str,
    batch_norm: bool,
    weights: Optional[WeightsEnum],
    progress: bool,
    in_channels: int = 3,
    **kwargs: Any,
) -> VGG:
    if weights is not None:
        kwargs["init_weights"] = False
        if weights.meta["categories"] is not None:
            _ovewrite_named_param(kwargs, "num_classes", len(weights.meta["categories"]))
    model = VGG(make_layers(cfgs[cfg], batch_norm=batch_norm, in_channels=in_channels), **kwargs)
    if weights is not None:
        model.load_state_dict(weights.get_state_dict(progress=progress))
    return model
vgg11
vgg11(*, weights: Optional[VGG11_Weights] = None, progress: bool = True, **kwargs: Any) -> VGG

VGG-11 from Very Deep Convolutional Networks for Large-Scale Image Recognition <https://arxiv.org/abs/1409.1556>__.

Parameters:

  • weights

    class:~torchvision.models.VGG11_Weights, optional): The pretrained weights to use. See :class:~torchvision.models.VGG11_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.vgg.VGG base class. Please refer to the source code <https://github.com/pytorch/vision/blob/main/torchvision/models/vgg.py>_ for more details about this class.

.. autoclass:: torchvision.models.VGG11_Weights :members:

Source code in SaigeToolkit/model/backbone/torchvision/vgg.py
@handle_legacy_interface(weights=("pretrained", VGG11_Weights.IMAGENET1K_V1))
def vgg11(*, weights: Optional[VGG11_Weights] = None, progress: bool = True, **kwargs: Any) -> VGG:
    """VGG-11 from `Very Deep Convolutional Networks for Large-Scale Image Recognition <https://arxiv.org/abs/1409.1556>`__.

    Args:
        weights (:class:`~torchvision.models.VGG11_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.VGG11_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.vgg.VGG``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/vgg.py>`_
            for more details about this class.

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

    return _vgg("A", False, weights, progress, **kwargs)
vgg11_bn
vgg11_bn(*, weights: Optional[VGG11_BN_Weights] = None, progress: bool = True, **kwargs: Any) -> VGG

VGG-11-BN from Very Deep Convolutional Networks for Large-Scale Image Recognition <https://arxiv.org/abs/1409.1556>__.

Parameters:

  • weights

    class:~torchvision.models.VGG11_BN_Weights, optional): The pretrained weights to use. See :class:~torchvision.models.VGG11_BN_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.vgg.VGG base class. Please refer to the source code <https://github.com/pytorch/vision/blob/main/torchvision/models/vgg.py>_ for more details about this class.

.. autoclass:: torchvision.models.VGG11_BN_Weights :members:

Source code in SaigeToolkit/model/backbone/torchvision/vgg.py
@handle_legacy_interface(weights=("pretrained", VGG11_BN_Weights.IMAGENET1K_V1))
def vgg11_bn(*, weights: Optional[VGG11_BN_Weights] = None, progress: bool = True, **kwargs: Any) -> VGG:
    """VGG-11-BN from `Very Deep Convolutional Networks for Large-Scale Image Recognition <https://arxiv.org/abs/1409.1556>`__.

    Args:
        weights (:class:`~torchvision.models.VGG11_BN_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.VGG11_BN_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.vgg.VGG``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/vgg.py>`_
            for more details about this class.

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

    return _vgg("A", True, weights, progress, **kwargs)
vgg13
vgg13(*, weights: Optional[VGG13_Weights] = None, progress: bool = True, **kwargs: Any) -> VGG

VGG-13 from Very Deep Convolutional Networks for Large-Scale Image Recognition <https://arxiv.org/abs/1409.1556>__.

Parameters:

  • weights

    class:~torchvision.models.VGG13_Weights, optional): The pretrained weights to use. See :class:~torchvision.models.VGG13_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.vgg.VGG base class. Please refer to the source code <https://github.com/pytorch/vision/blob/main/torchvision/models/vgg.py>_ for more details about this class.

.. autoclass:: torchvision.models.VGG13_Weights :members:

Source code in SaigeToolkit/model/backbone/torchvision/vgg.py
@handle_legacy_interface(weights=("pretrained", VGG13_Weights.IMAGENET1K_V1))
def vgg13(*, weights: Optional[VGG13_Weights] = None, progress: bool = True, **kwargs: Any) -> VGG:
    """VGG-13 from `Very Deep Convolutional Networks for Large-Scale Image Recognition <https://arxiv.org/abs/1409.1556>`__.

    Args:
        weights (:class:`~torchvision.models.VGG13_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.VGG13_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.vgg.VGG``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/vgg.py>`_
            for more details about this class.

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

    return _vgg("B", False, weights, progress, **kwargs)
vgg13_bn
vgg13_bn(*, weights: Optional[VGG13_BN_Weights] = None, progress: bool = True, **kwargs: Any) -> VGG

VGG-13-BN from Very Deep Convolutional Networks for Large-Scale Image Recognition <https://arxiv.org/abs/1409.1556>__.

Parameters:

  • weights

    class:~torchvision.models.VGG13_BN_Weights, optional): The pretrained weights to use. See :class:~torchvision.models.VGG13_BN_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.vgg.VGG base class. Please refer to the source code <https://github.com/pytorch/vision/blob/main/torchvision/models/vgg.py>_ for more details about this class.

.. autoclass:: torchvision.models.VGG13_BN_Weights :members:

Source code in SaigeToolkit/model/backbone/torchvision/vgg.py
@handle_legacy_interface(weights=("pretrained", VGG13_BN_Weights.IMAGENET1K_V1))
def vgg13_bn(*, weights: Optional[VGG13_BN_Weights] = None, progress: bool = True, **kwargs: Any) -> VGG:
    """VGG-13-BN from `Very Deep Convolutional Networks for Large-Scale Image Recognition <https://arxiv.org/abs/1409.1556>`__.

    Args:
        weights (:class:`~torchvision.models.VGG13_BN_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.VGG13_BN_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.vgg.VGG``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/vgg.py>`_
            for more details about this class.

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

    return _vgg("B", True, weights, progress, **kwargs)
vgg16
vgg16(*, weights: Optional[VGG16_Weights] = None, progress: bool = True, **kwargs: Any) -> VGG

VGG-16 from Very Deep Convolutional Networks for Large-Scale Image Recognition <https://arxiv.org/abs/1409.1556>__.

Parameters:

  • weights

    class:~torchvision.models.VGG16_Weights, optional): The pretrained weights to use. See :class:~torchvision.models.VGG16_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.vgg.VGG base class. Please refer to the source code <https://github.com/pytorch/vision/blob/main/torchvision/models/vgg.py>_ for more details about this class.

.. autoclass:: torchvision.models.VGG16_Weights :members:

Source code in SaigeToolkit/model/backbone/torchvision/vgg.py
@handle_legacy_interface(weights=("pretrained", VGG16_Weights.IMAGENET1K_V1))
def vgg16(*, weights: Optional[VGG16_Weights] = None, progress: bool = True, **kwargs: Any) -> VGG:
    """VGG-16 from `Very Deep Convolutional Networks for Large-Scale Image Recognition <https://arxiv.org/abs/1409.1556>`__.

    Args:
        weights (:class:`~torchvision.models.VGG16_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.VGG16_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.vgg.VGG``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/vgg.py>`_
            for more details about this class.

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

    return _vgg("D", False, weights, progress, **kwargs)
vgg16_bn
vgg16_bn(*, weights: Optional[VGG16_BN_Weights] = None, progress: bool = True, **kwargs: Any) -> VGG

VGG-16-BN from Very Deep Convolutional Networks for Large-Scale Image Recognition <https://arxiv.org/abs/1409.1556>__.

Parameters:

  • weights

    class:~torchvision.models.VGG16_BN_Weights, optional): The pretrained weights to use. See :class:~torchvision.models.VGG16_BN_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.vgg.VGG base class. Please refer to the source code <https://github.com/pytorch/vision/blob/main/torchvision/models/vgg.py>_ for more details about this class.

.. autoclass:: torchvision.models.VGG16_BN_Weights :members:

Source code in SaigeToolkit/model/backbone/torchvision/vgg.py
@handle_legacy_interface(weights=("pretrained", VGG16_BN_Weights.IMAGENET1K_V1))
def vgg16_bn(*, weights: Optional[VGG16_BN_Weights] = None, progress: bool = True, **kwargs: Any) -> VGG:
    """VGG-16-BN from `Very Deep Convolutional Networks for Large-Scale Image Recognition <https://arxiv.org/abs/1409.1556>`__.

    Args:
        weights (:class:`~torchvision.models.VGG16_BN_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.VGG16_BN_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.vgg.VGG``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/vgg.py>`_
            for more details about this class.

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

    return _vgg("D", True, weights, progress, **kwargs)
vgg19
vgg19(*, weights: Optional[VGG19_Weights] = None, progress: bool = True, **kwargs: Any) -> VGG

VGG-19 from Very Deep Convolutional Networks for Large-Scale Image Recognition <https://arxiv.org/abs/1409.1556>__.

Parameters:

  • weights

    class:~torchvision.models.VGG19_Weights, optional): The pretrained weights to use. See :class:~torchvision.models.VGG19_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.vgg.VGG base class. Please refer to the source code <https://github.com/pytorch/vision/blob/main/torchvision/models/vgg.py>_ for more details about this class.

.. autoclass:: torchvision.models.VGG19_Weights :members:

Source code in SaigeToolkit/model/backbone/torchvision/vgg.py
@handle_legacy_interface(weights=("pretrained", VGG19_Weights.IMAGENET1K_V1))
def vgg19(*, weights: Optional[VGG19_Weights] = None, progress: bool = True, **kwargs: Any) -> VGG:
    """VGG-19 from `Very Deep Convolutional Networks for Large-Scale Image Recognition <https://arxiv.org/abs/1409.1556>`__.

    Args:
        weights (:class:`~torchvision.models.VGG19_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.VGG19_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.vgg.VGG``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/vgg.py>`_
            for more details about this class.

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

    return _vgg("E", False, weights, progress, **kwargs)
vgg19_bn
vgg19_bn(*, weights: Optional[VGG19_BN_Weights] = None, progress: bool = True, **kwargs: Any) -> VGG

VGG-19_BN from Very Deep Convolutional Networks for Large-Scale Image Recognition <https://arxiv.org/abs/1409.1556>__.

Parameters:

  • weights

    class:~torchvision.models.VGG19_BN_Weights, optional): The pretrained weights to use. See :class:~torchvision.models.VGG19_BN_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.vgg.VGG base class. Please refer to the source code <https://github.com/pytorch/vision/blob/main/torchvision/models/vgg.py>_ for more details about this class.

.. autoclass:: torchvision.models.VGG19_BN_Weights :members:

Source code in SaigeToolkit/model/backbone/torchvision/vgg.py
@handle_legacy_interface(weights=("pretrained", VGG19_BN_Weights.IMAGENET1K_V1))
def vgg19_bn(*, weights: Optional[VGG19_BN_Weights] = None, progress: bool = True, **kwargs: Any) -> VGG:
    """VGG-19_BN from `Very Deep Convolutional Networks for Large-Scale Image Recognition <https://arxiv.org/abs/1409.1556>`__.

    Args:
        weights (:class:`~torchvision.models.VGG19_BN_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.VGG19_BN_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.vgg.VGG``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/vgg.py>`_
            for more details about this class.

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

    return _vgg("E", True, weights, progress, **kwargs)

van

PyTorch Visual Attention Network (VAN) model.

URL: https://github.com/Visual-Attention-Network/VAN-Classification

model_urls module-attribute

model_urls = {'van_b0': 'https://huggingface.co/Visual-Attention-Network/VAN-Tiny-original/resolve/main/van_tiny_754.pth.tar', 'van_b1': 'https://huggingface.co/Visual-Attention-Network/VAN-Small-original/resolve/main/van_small_811.pth.tar', 'van_b2': 'https://huggingface.co/Visual-Attention-Network/VAN-Base-original/resolve/main/van_base_828.pth.tar', 'van_b3': 'https://huggingface.co/Visual-Attention-Network/VAN-Large-original/resolve/main/van_large_839.pth.tar'}

DWConv

DWConv(dim=768)

Bases: Module

Source code in SaigeToolkit/model/backbone/van.py
def __init__(self, dim=768):
    super(DWConv, self).__init__()
    self.dwconv = nn.Conv2d(dim, dim, 3, 1, 1, bias=True, groups=dim)
dwconv instance-attribute
dwconv = Conv2d(dim, dim, 3, 1, 1, bias=True, groups=dim)
forward
forward(x)
Source code in SaigeToolkit/model/backbone/van.py
def forward(self, x):
    x = self.dwconv(x)
    return x

Mlp

Mlp(in_features, hidden_features=None, out_features=None, act_layer=nn.GELU, drop=0.0)

Bases: Module

Source code in SaigeToolkit/model/backbone/van.py
def __init__(
    self, in_features, hidden_features=None, out_features=None, act_layer=nn.GELU, drop=0.0
):
    super().__init__()
    out_features = out_features or in_features
    hidden_features = hidden_features or in_features
    self.fc1 = nn.Conv2d(in_features, hidden_features, 1)
    self.dwconv = DWConv(hidden_features)
    self.act = act_layer()
    self.fc2 = nn.Conv2d(hidden_features, out_features, 1)
    self.drop = nn.Dropout(drop)
    self.apply(self._init_weights)
fc1 instance-attribute
fc1 = Conv2d(in_features, hidden_features, 1)
dwconv instance-attribute
dwconv = DWConv(hidden_features)
act instance-attribute
act = act_layer()
fc2 instance-attribute
fc2 = Conv2d(hidden_features, out_features, 1)
drop instance-attribute
drop = Dropout(drop)
_init_weights
_init_weights(m)
Source code in SaigeToolkit/model/backbone/van.py
def _init_weights(self, m):
    if isinstance(m, nn.Linear):
        trunc_normal_(m.weight, std=0.02)
        if isinstance(m, nn.Linear) and m.bias is not None:
            nn.init.constant_(m.bias, 0)
    elif isinstance(m, nn.LayerNorm):
        nn.init.constant_(m.bias, 0)
        nn.init.constant_(m.weight, 1.0)
    elif isinstance(m, nn.Conv2d):
        fan_out = m.kernel_size[0] * m.kernel_size[1] * m.out_channels
        fan_out //= m.groups
        m.weight.data.normal_(0, math.sqrt(2.0 / fan_out))
        if m.bias is not None:
            m.bias.data.zero_()
forward
forward(x)
Source code in SaigeToolkit/model/backbone/van.py
def forward(self, x):
    x = self.fc1(x)
    x = self.dwconv(x)
    x = self.act(x)
    x = self.drop(x)
    x = self.fc2(x)
    x = self.drop(x)
    return x

LKA

LKA(dim, clip_attn=None)

Bases: Module

Source code in SaigeToolkit/model/backbone/van.py
def __init__(self, dim, clip_attn=None):
    super().__init__()
    self.conv0 = nn.Conv2d(dim, dim, 5, padding=2, groups=dim)
    self.conv_spatial = nn.Conv2d(dim, dim, 7, stride=1, padding=9, groups=dim, dilation=3)
    self.conv1 = nn.Conv2d(dim, dim, 1)
    self.clip_attn = clip_attn
conv0 instance-attribute
conv0 = Conv2d(dim, dim, 5, padding=2, groups=dim)
conv_spatial instance-attribute
conv_spatial = Conv2d(dim, dim, 7, stride=1, padding=9, groups=dim, dilation=3)
conv1 instance-attribute
conv1 = Conv2d(dim, dim, 1)
clip_attn instance-attribute
clip_attn = clip_attn
forward
forward(x)
Source code in SaigeToolkit/model/backbone/van.py
def forward(self, x):
    u = x.clone()
    attn = self.conv0(x)
    attn = self.conv_spatial(attn)
    attn = self.conv1(attn)
    attn = u * attn

    if self.clip_attn is not None:
        attn = torch.clamp(attn, min=-self.clip_attn, max=self.clip_attn)

    return attn

Attention

Attention(d_model, clip_attn=None)

Bases: Module

Source code in SaigeToolkit/model/backbone/van.py
def __init__(self, d_model, clip_attn=None):
    super().__init__()

    self.proj_1 = nn.Conv2d(d_model, d_model, 1)
    self.activation = nn.GELU()
    self.spatial_gating_unit = LKA(d_model, clip_attn=clip_attn)
    self.proj_2 = nn.Conv2d(d_model, d_model, 1)
proj_1 instance-attribute
proj_1 = Conv2d(d_model, d_model, 1)
activation instance-attribute
activation = GELU()
spatial_gating_unit instance-attribute
spatial_gating_unit = LKA(d_model, clip_attn=clip_attn)
proj_2 instance-attribute
proj_2 = Conv2d(d_model, d_model, 1)
forward
forward(x)
Source code in SaigeToolkit/model/backbone/van.py
def forward(self, x):
    shorcut = x.clone()
    x = self.proj_1(x)
    x = self.activation(x)
    x = self.spatial_gating_unit(x)
    x = self.proj_2(x)
    x = x + shorcut
    return x

Block

Block(dim, mlp_ratio=4.0, drop=0.0, drop_path=0.0, act_layer=nn.GELU, clip_attn=None)

Bases: Module

Source code in SaigeToolkit/model/backbone/van.py
def __init__(self, dim, mlp_ratio=4.0, drop=0.0, drop_path=0.0, act_layer=nn.GELU, clip_attn=None):
    super().__init__()
    self.norm1 = nn.BatchNorm2d(dim)
    self.attn = Attention(dim, clip_attn=clip_attn)
    self.drop_path = DropPath(drop_path) if drop_path > 0.0 else nn.Identity()

    self.norm2 = nn.BatchNorm2d(dim)
    mlp_hidden_dim = int(dim * mlp_ratio)
    self.mlp = Mlp(in_features=dim, hidden_features=mlp_hidden_dim, act_layer=act_layer, drop=drop)
    layer_scale_init_value = 1e-2
    self.layer_scale_1 = nn.Parameter(layer_scale_init_value * torch.ones((dim)), requires_grad=True)
    self.layer_scale_2 = nn.Parameter(layer_scale_init_value * torch.ones((dim)), requires_grad=True)

    self.apply(self._init_weights)
norm1 instance-attribute
norm1 = BatchNorm2d(dim)
attn instance-attribute
attn = Attention(dim, clip_attn=clip_attn)
drop_path instance-attribute
drop_path = DropPath(drop_path) if drop_path > 0.0 else Identity()
norm2 instance-attribute
norm2 = BatchNorm2d(dim)
mlp instance-attribute
mlp = Mlp(in_features=dim, hidden_features=mlp_hidden_dim, act_layer=act_layer, drop=drop)
layer_scale_1 instance-attribute
layer_scale_1 = Parameter(layer_scale_init_value * ones(dim), requires_grad=True)
layer_scale_2 instance-attribute
layer_scale_2 = Parameter(layer_scale_init_value * ones(dim), requires_grad=True)
_init_weights
_init_weights(m)
Source code in SaigeToolkit/model/backbone/van.py
def _init_weights(self, m):
    if isinstance(m, nn.Linear):
        trunc_normal_(m.weight, std=0.02)
        if isinstance(m, nn.Linear) and m.bias is not None:
            nn.init.constant_(m.bias, 0)
    elif isinstance(m, nn.LayerNorm):
        nn.init.constant_(m.bias, 0)
        nn.init.constant_(m.weight, 1.0)
    elif isinstance(m, nn.Conv2d):
        fan_out = m.kernel_size[0] * m.kernel_size[1] * m.out_channels
        fan_out //= m.groups
        m.weight.data.normal_(0, math.sqrt(2.0 / fan_out))
        if m.bias is not None:
            m.bias.data.zero_()
forward
forward(x)
Source code in SaigeToolkit/model/backbone/van.py
def forward(self, x):
    x = x + self.drop_path(self.layer_scale_1.unsqueeze(-1).unsqueeze(-1) * self.attn(self.norm1(x)))
    x = x + self.drop_path(self.layer_scale_2.unsqueeze(-1).unsqueeze(-1) * self.mlp(self.norm2(x)))
    return x

OverlapPatchEmbed

OverlapPatchEmbed(img_size=224, patch_size=7, stride=4, in_channels=3, embed_dim=768)

Bases: Module

Image to Patch Embedding

Source code in SaigeToolkit/model/backbone/van.py
def __init__(self, img_size=224, patch_size=7, stride=4, in_channels=3, embed_dim=768):
    super().__init__()
    patch_size = to_2tuple(patch_size)
    self.proj = nn.Conv2d(
        in_channels,
        embed_dim,
        kernel_size=patch_size,
        stride=stride,
        padding=(patch_size[0] // 2, patch_size[1] // 2),
    )
    self.norm = nn.BatchNorm2d(embed_dim)

    self.apply(self._init_weights)
proj instance-attribute
proj = Conv2d(in_channels, embed_dim, kernel_size=patch_size, stride=stride, padding=(patch_size[0] // 2, patch_size[1] // 2))
norm instance-attribute
norm = BatchNorm2d(embed_dim)
_init_weights
_init_weights(m)
Source code in SaigeToolkit/model/backbone/van.py
def _init_weights(self, m):
    if isinstance(m, nn.Linear):
        trunc_normal_(m.weight, std=0.02)
        if isinstance(m, nn.Linear) and m.bias is not None:
            nn.init.constant_(m.bias, 0)
    elif isinstance(m, nn.LayerNorm):
        nn.init.constant_(m.bias, 0)
        nn.init.constant_(m.weight, 1.0)
    elif isinstance(m, nn.Conv2d):
        fan_out = m.kernel_size[0] * m.kernel_size[1] * m.out_channels
        fan_out //= m.groups
        m.weight.data.normal_(0, math.sqrt(2.0 / fan_out))
        if m.bias is not None:
            m.bias.data.zero_()
forward
forward(x)
Source code in SaigeToolkit/model/backbone/van.py
def forward(self, x):
    x = self.proj(x)
    _, _, H, W = x.shape
    x = self.norm(x)
    return x, H, W

VAN

VAN(img_size: int = 224, in_channels: int = 3, embed_dims: List[int] = [64, 128, 256, 512], mlp_ratios: List[int] = [4, 4, 4, 4], drop_rate: float = 0.0, drop_path_rate: float = 0.0, norm_layer: Module = nn.LayerNorm, depths: List[int] = [3, 4, 6, 3], num_stages: int = 4, clip_attn: Optional[float] = None)

Bases: Module

Source code in SaigeToolkit/model/backbone/van.py
def __init__(
    self,
    img_size: int = 224,
    in_channels: int = 3,
    embed_dims: List[int] = [64, 128, 256, 512],
    mlp_ratios: List[int] = [4, 4, 4, 4],
    drop_rate: float = 0.0,
    drop_path_rate: float = 0.0,
    norm_layer: nn.Module = nn.LayerNorm,
    depths: List[int] = [3, 4, 6, 3],
    num_stages: int = 4,
    clip_attn: Optional[float] = None,
):
    super().__init__()

    self.depths = depths
    self.num_stages = num_stages
    self.embed_dims = embed_dims

    dpr = [
        x.item() for x in torch.linspace(0, drop_path_rate, sum(depths))
    ]  # stochastic depth decay rule
    cur = 0

    for i in range(num_stages):
        patch_embed = OverlapPatchEmbed(
            img_size=img_size if i == 0 else img_size // (2 ** (i + 1)),
            patch_size=7 if i == 0 else 3,
            stride=4 if i == 0 else 2,
            in_channels=in_channels if i == 0 else embed_dims[i - 1],
            embed_dim=embed_dims[i],
        )

        block = nn.ModuleList(
            [
                Block(
                    dim=embed_dims[i],
                    mlp_ratio=mlp_ratios[i],
                    drop=drop_rate,
                    drop_path=dpr[cur + j],
                    clip_attn=clip_attn,
                )
                for j in range(depths[i])
            ]
        )
        norm = norm_layer(embed_dims[i])
        cur += depths[i]

        setattr(self, f"patch_embed{i + 1}", patch_embed)
        setattr(self, f"block{i + 1}", block)
        setattr(self, f"norm{i + 1}", norm)

    self.apply(self._init_weights)
depths instance-attribute
depths = depths
num_stages instance-attribute
num_stages = num_stages
embed_dims instance-attribute
embed_dims = embed_dims
_init_weights
_init_weights(m)
Source code in SaigeToolkit/model/backbone/van.py
def _init_weights(self, m):
    if isinstance(m, nn.Linear):
        trunc_normal_(m.weight, std=0.02)
        if isinstance(m, nn.Linear) and m.bias is not None:
            nn.init.constant_(m.bias, 0)
    elif isinstance(m, nn.LayerNorm):
        nn.init.constant_(m.bias, 0)
        nn.init.constant_(m.weight, 1.0)
    elif isinstance(m, nn.Conv2d):
        fan_out = m.kernel_size[0] * m.kernel_size[1] * m.out_channels
        fan_out //= m.groups
        m.weight.data.normal_(0, math.sqrt(2.0 / fan_out))
        if m.bias is not None:
            m.bias.data.zero_()
freeze_patch_emb
freeze_patch_emb()
Source code in SaigeToolkit/model/backbone/van.py
def freeze_patch_emb(self):
    self.patch_embed1.requires_grad = False
no_weight_decay
no_weight_decay()
Source code in SaigeToolkit/model/backbone/van.py
@torch.jit.ignore
def no_weight_decay(self):
    return {
        "pos_embed1",
        "pos_embed2",
        "pos_embed3",
        "pos_embed4",
        "cls_token",
    }  # has pos_embed may be better
forward
forward(x)
Source code in SaigeToolkit/model/backbone/van.py
def forward(self, x):
    B = x.shape[0]

    for i in range(self.num_stages):
        patch_embed = getattr(self, f"patch_embed{i + 1}")
        block = getattr(self, f"block{i + 1}")
        norm = getattr(self, f"norm{i + 1}")
        x, H, W = patch_embed(x)
        for blk in block:
            x = blk(x)
        x = x.flatten(2).transpose(1, 2)
        x = norm(x)
        if i != self.num_stages - 1:
            x = x.reshape(B, H, W, -1).permute(0, 3, 1, 2).contiguous()

    return x.mean(dim=1)
load_state_dict
load_state_dict(state_dict, strict: bool = True)
Source code in SaigeToolkit/model/backbone/van.py
def load_state_dict(self, state_dict, strict: bool = True):
    extend_state_dict_input_channel(state_dict, "patch_embed1.proj.weight", self.patch_embed1.proj)
    for key in list(state_dict):
        if key.startswith("head."):
            state_dict.pop(key)
    return super().load_state_dict(state_dict, strict)

load_model_weights

load_model_weights(model, arch, kwargs)
Source code in SaigeToolkit/model/backbone/van.py
def load_model_weights(model, arch, kwargs):
    url = model_urls[arch]
    checkpoint = torch.hub.load_state_dict_from_url(url=url, map_location="cpu", check_hash=True)
    strict = True
    if "num_classes" in kwargs and kwargs["num_classes"] != 1000:
        strict = False
        del checkpoint["state_dict"]["head.weight"]
        del checkpoint["state_dict"]["head.bias"]
    model.load_state_dict(checkpoint["state_dict"], strict=strict)
    return model

van_b0

van_b0(pretrained=False, **kwargs)
Source code in SaigeToolkit/model/backbone/van.py
def van_b0(pretrained=False, **kwargs):
    model = VAN(
        embed_dims=[32, 64, 160, 256],
        mlp_ratios=[8, 8, 4, 4],
        norm_layer=partial(nn.LayerNorm, eps=1e-6),
        depths=[3, 3, 5, 2],
        **kwargs,
    )
    model.default_cfg = _cfg()
    if pretrained:
        model = load_model_weights(model, "van_b0", kwargs)
    return model

van_b1

van_b1(pretrained=False, **kwargs)
Source code in SaigeToolkit/model/backbone/van.py
def van_b1(pretrained=False, **kwargs):
    model = VAN(
        embed_dims=[64, 128, 320, 512],
        mlp_ratios=[8, 8, 4, 4],
        norm_layer=partial(nn.LayerNorm, eps=1e-6),
        depths=[2, 2, 4, 2],
        **kwargs,
    )
    model.default_cfg = _cfg()
    if pretrained:
        model = load_model_weights(model, "van_b1", kwargs)
    return model

van_b2

van_b2(pretrained=False, **kwargs)
Source code in SaigeToolkit/model/backbone/van.py
def van_b2(pretrained=False, **kwargs):
    model = VAN(
        embed_dims=[64, 128, 320, 512],
        mlp_ratios=[8, 8, 4, 4],
        norm_layer=partial(nn.LayerNorm, eps=1e-6),
        depths=[3, 3, 12, 3],
        **kwargs,
    )
    model.default_cfg = _cfg()
    if pretrained:
        model = load_model_weights(model, "van_b2", kwargs)
    return model

van_b3

van_b3(pretrained=False, **kwargs)
Source code in SaigeToolkit/model/backbone/van.py
def van_b3(pretrained=False, **kwargs):
    model = VAN(
        embed_dims=[64, 128, 320, 512],
        mlp_ratios=[8, 8, 4, 4],
        norm_layer=partial(nn.LayerNorm, eps=1e-6),
        depths=[3, 5, 27, 3],
        **kwargs,
    )
    model.default_cfg = _cfg()
    if pretrained:
        model = load_model_weights(model, "van_b3", kwargs)
    return model