model
Module diagram
classDiagram
class model {
}
class backbone {
}
class builder {
}
class norm {
}
class torchvision {
}
class regnet {
}
class resnet {
}
class squeezenet {
}
class vgg {
}
class van {
}
class benchmark {
}
class feature_extractor {
}
class neck {
}
class builder {
}
class fpem {
}
class fpn {
}
class util {
}
backbone --> builder
builder --> regnet
builder --> resnet
builder --> squeezenet
builder --> vgg
builder --> van
benchmark --> backbone
feature_extractor --> backbone
neck --> builder
builder --> fpem
builder --> fpn
model
backbone
builder
register_backbone
native_models에 백본을 등록해 build_backbone()에서 사용할 수 있도록 합니다
Source code in SaigeToolkit/model/backbone/builder.py
norm
FrozenBatchNorm2d
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
forward
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
get_norm
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
torchvision
regnet
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
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
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
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
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
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
_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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
resnet
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
conv1x1
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_Weightsbelow 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.ResNetbase class. Please refer to thesource 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
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_Weightsbelow 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.ResNetbase class. Please refer to thesource 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
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_Weightsbelow 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.ResNetbase class. Please refer to thesource 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
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_Weightsbelow 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.ResNetbase class. Please refer to thesource 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
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_Weightsbelow 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.ResNetbase class. Please refer to thesource 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
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_Weightsbelow 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.ResNetbase class. Please refer to thesource 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
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_Weightsbelow 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.ResNetbase class. Please refer to thesource 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
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_Weightsbelow 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.ResNetbase class. Please refer to thesource 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
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_Weightsbelow 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.ResNetbase class. Please refer to thesource 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
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_Weightsbelow 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.ResNetbase class. Please refer to thesource 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
squeezenet
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_Weightsbelow 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.SqueezeNetbase class. Please refer to thesource 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
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_Weightsbelow 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.SqueezeNetbase class. Please refer to thesource 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
vgg
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_Weightsbelow 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.VGGbase class. Please refer to thesource 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
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_Weightsbelow 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.VGGbase class. Please refer to thesource 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
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_Weightsbelow 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.VGGbase class. Please refer to thesource 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
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_Weightsbelow 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.VGGbase class. Please refer to thesource 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
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_Weightsbelow 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.VGGbase class. Please refer to thesource 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
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_Weightsbelow 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.VGGbase class. Please refer to thesource 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
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_Weightsbelow 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.VGGbase class. Please refer to thesource 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
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_Weightsbelow 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.VGGbase class. Please refer to thesource 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
van
PyTorch Visual Attention Network (VAN) model.
URL: https://github.com/Visual-Attention-Network/VAN-Classification
OverlapPatchEmbed
Bases: Module
Image to Patch Embedding
Source code in SaigeToolkit/model/backbone/van.py
benchmark
ModelSpecInspector
measure_model_inference_spec
classmethod
measure_model_inference_spec(model: Module, batch: int = 1, image_size: int = 256, image_channels: int = 3, warmup: int = 3, device: device = torch.device('cuda'), num_iteration: int = 100)
모델 인퍼런스 시 속도와 메모리 등을 측정합니다.
Source code in SaigeToolkit/model/benchmark.py
measure_and_save_model_inference_spec_from_config
classmethod
measure_and_save_model_inference_spec_from_config(model: Union[str, Dict], json_path: str, model_builder: Callable = build_backbone, **measure_kwargs)
모델 config 또는 config 파일의 경로를 받아서 모델 인퍼런스 스펙 측정 후 json_path에 결과를 저장합니다.
Source code in SaigeToolkit/model/benchmark.py
benchmark_model_inference_spec
classmethod
benchmark_model_inference_spec(logdir, add_time_to_logdir: bool = True, image_sizes=[256, 512, 1024, 2048], **measure_kwargs)
여러 이미지 사이즈에 인퍼런스 스펙을 별도 프로세스로 측정하고 logdir 하위에 json들로 저장합니다.
Source code in SaigeToolkit/model/benchmark.py
feature_extractor
ForwardHookFeatureExtractor
Bases: Module
Extract intermediate features from the model with forward hooks.
return example: {"layer1": layer1_output, "layer2": layer2_output, ..}
Note
- DOES NOT work with DataParallel. forward input이 단일 tensor가 아닌 경우 device로 분류하는 기존 방식이 동작하지 않기 때문에 제거함.
- DOES work with DistributedDataParallel.
Source code in SaigeToolkit/model/feature_extractor.py
build_feature_extractor
build_feature_extractor(backbone: Union[dict, Module], _target_: str = 'create_feature_extractor', layers: Optional[List[str]] = None, **params) -> Module
Build feature extractor
Parameters:
-
backbone(dict | Module) –backbone config.
-
_target_(str, default:'create_feature_extractor') –feature extractor target. Defaults to "create_feature_extractor".
-
layers(List[str], default:None) –feature layers to extract. Defaults to None.
Returns:
-
Module–nn.Module: feature extractor
Note
ForwardHookFeatureExtractor의 경우 hook을 사용하므로 기존 모델과의 동일성이 보장되지만 불필요한 레이어까지 모두 사용하게됨.IntermediateLayerGetter의 경우 타겟 레이어 이후의 레이어를 제거해 효율적. 하지만 기존 모델의 forward가 복잡한 경우 동일성이 보장되지 않을 수 있음.create_feature_extractor의 경우 연산 그래프를 고려하여 타겟 레이어 이외의 레이어를 제거해 동일성과 효율성 측면에서 좋음. 하지만 timm 모델은 사용할 수 없는듯.
Source code in SaigeToolkit/model/feature_extractor.py
neck
builder
build_neck
build network 'neck' part, such as FPN "Feature Pyramid Networks for Object Detection".
Parameters:
-
cfg_neck(dict) –configuration parameters for building 'neck' network
Returns:
-
Module–nn.Module: 'neck' network
Source code in SaigeToolkit/model/neck/builder.py
get_neck_class
returns neck network class.
Parameters:
-
cfg_neck_name(str) –neck network class name
Returns:
-
Type[Module]–Type[nn.Module]: neck network class
Source code in SaigeToolkit/model/neck/builder.py
fpem
FPEM_FFM
Bases: Module
PANnet :param backbone_out_channels: 基础网络输出的维度
Source code in SaigeToolkit/model/neck/fpem.py
fpn
ConvBlock
ConvBlock(in_channels: int, out_channels: int, kernel_size: int = 1, stride: int = 1, padding: int = 0)
Bases: Module
ConvBlock defined, which consists of Convolution, BatchNorm, ReLU
Attributes:
-
conv(Conv2d) –convolution layer for ConvBlock
-
bn(BatchNorm2d) –2d batch norm layer for ConvBlock
-
act(ReLU) –ReLU activation function for ConvBlock
initializing ConvBlock
Parameters:
-
in_channels(int) –'input channel' for conv layer
-
out_channels(int) –'output channel' for conv layer, which is also 'input channel' for bn layer
-
kernel_size(int, default:1) –kernel size for conv layer. Defaults to 1.
-
stride(int, default:1) –stride for conv layer. Defaults to 1.
-
padding(int, default:0) –padding for conv layer. Defaults to 0.
Source code in SaigeToolkit/model/neck/fpn.py
forward
forward function for nn.Module class
Parameters:
-
inputs(Tensor) –input tensor for ConvBlock
Returns:
-
Tensor–torch.Tensor: output tensor for ConvBlock
Source code in SaigeToolkit/model/neck/fpn.py
FpnBlock
FpnBlock(in_channels: Union[List[int], int, None] = [64, 128, 256, 512], out_channels: Union[List[int], int, None] = None, channel_fpn: int = 64, num_feat: int = 4)
Bases: Module
block for constructing FeaturePyramidNetwork.
Attributes:
-
block_in(ModuleList) –Convolution layer, that backbone output feature is directly applied
-
block_out(ModuleList) –Convolution layer, that tensors from 'block_in' is applied after 'upsampled and sumed'
initializing FpnBlock
Parameters:
-
in_channels(Union[List[int], int, None], default:[64, 128, 256, 512]) –input channels for block_in. Defaults to [64, 128, 256, 512].
-
out_channels(Union[List[int], int, None], default:None) –output channels for block_out. Defaults to None.
-
channel_fpn(int, default:64) –output channels for block_in, also input channels for block_out. Defaults to 64.
-
num_feat(int, default:4) –number of layer of block_in/block_out. Defaults to 4.
Source code in SaigeToolkit/model/neck/fpn.py
_upsample_add
upsample intput x to size of input y, and sum both inputs
Parameters:
-
x(Tensor) –smaller (size) input
-
y(Tensor) –larger (size) input
Returns:
-
Tensor–torch.Tensor: upsampled and sumed tensor
Source code in SaigeToolkit/model/neck/fpn.py
forward
forward function for nn.Module class
Parameters:
-
features(List[Tensor]) –list of tensors from backbone network
Returns:
-
List[Tensor]–List[torch.Tensor]: list of tensors processed after FpnBlock
Source code in SaigeToolkit/model/neck/fpn.py
FPN
FPN(in_channels: Optional[List[int]] = None, out_channels: int = 64, channel_fpn: int = 256, num_feat: int = 4, num_block: int = 1)
Bases: Module
"Feature Pyramid Networks for Object Detection".
Attributes:
-
block_fpn(ModuleList) –torch module list, consists of FpnBlocks.
initializing Feature Pyramid Networks
Parameters:
-
in_channels(List[int], default:None) –channels from backbone network output tensors. Defaults to None.
-
out_channels(int, default:64) –final output channels for FPN. Defaults to 64.
-
channel_fpn(int, default:256) –inner channels for FpnBlocks. Defaults to 256.
-
num_feat(int, default:4) –number of blocks inside of FpnBlocks. Defaults to 4.
-
num_block(int, default:1) –number of FpnBlocks. Defaults to 1.
Source code in SaigeToolkit/model/neck/fpn.py
forward
forward function for FPN
Parameters:
-
features(List[Tensor]) –output tensors from backbone network.
Returns:
-
List[Tensor]–List[torch.Tensor]: output tensors from FPN.
Source code in SaigeToolkit/model/neck/fpn.py
BiFpnBlock
Bases: Module
block for constructing BidirectionalFeaturePyramidNetwork.
Attributes:
-
epsilon(float) –epsilon value for BiFpnBlock
-
block_td(ModuleList) –blocks for
upsample_weighted_sum -
block_out(ModuleList) –blocks for
downsample_weighted_sum -
w1(Parameter) –weight parameter for block_td
-
w1_relu(ReLU) –ReLU layer for
w1parameter -
w2(Parameter) –weight parameter for block_out
-
w2_relu(ReLU) –ReLU layer for
w2parameter
initializing BiFpnBlock
Parameters:
-
channel_fpn(int, default:256) –input/output channels for all blocks. Defaults to 256.
-
num_feat(int, default:4) –number of each blocks. Defaults to 4.
-
epsilon(float, default:1e-06) –epsilon value for attribute
self.epsilon. Defaults to 1e-6.
Source code in SaigeToolkit/model/neck/fpn.py
forward
forward function for nn.Module
Parameters:
-
inputs(List[Tensor]) –list of tensors from former network
Returns:
-
List[Tensor]–List[torch.Tensor]: output list of tensors from BiFpnBlock
Source code in SaigeToolkit/model/neck/fpn.py
_upsample_weighted_sum
upsample input x and weighted sum with input y
Parameters:
-
x(Tensor) –smaller (size) input
-
y(Tensor) –larger (size) input
-
w(Parameter) –weight parameter
Returns:
-
Tensor–torch.Tensor: 'upsample_weight_sum'ed output
Source code in SaigeToolkit/model/neck/fpn.py
_downsample_weighted_sum
downsample input z and weighted sum with input x and input y
Parameters:
-
x(Tensor) –smaller (size) input
-
y(Tensor) –smaller (size) input
-
z(Tensor) –larger (size) input
-
w(Parameter) –weight parameter
Returns:
-
Tensor–torch.Tensor: 'downsample_weight_sum'ed output
Source code in SaigeToolkit/model/neck/fpn.py
BiFPN
BiFPN(in_channels: Optional[List[int]] = None, out_channels: int = 64, channel_fpn: int = 256, num_feat: int = 4, num_block: int = 2)
Bases: Module
"BidirectionalFeaturePyramidNetwork".
Attribute
block_in (nn.ModuleList): list of conv layers, which transfers input channels into fixed channel_fpn block_ex (nn.ModuleList): list of ConvBlock, residual blocks block_fpn (nn.ModuleList): list of BiFpnBlocks block_rtn (nn.ModuleList): list of ConvBlock, refining BiFpnBlock output
initializing Bidirectional FPN
Args:
in_channels (List[int], optional): channels from backbone network output tensors. Defaults to None.
out_channels (int, optional): final output channels for FPN. Defaults to 64.
channel_fpn (int, optional): inner channels for BiFpnBlocks. Defaults to 256.
num_feat (int, optional): number of blocks inside of BiFpnBlocks. Defaults to 4.
num_block (int, optional): number of FpnBlocks. Defaults to 1.
Source code in SaigeToolkit/model/neck/fpn.py
forward
forward function for FPN
Parameters:
-
inputs(List[Tensor]) –output tensors from backbone network.
Returns:
-
List[Tensor]–List[torch.Tensor]: output tensors from BiFPN.
Source code in SaigeToolkit/model/neck/fpn.py
FPN_DB
FPN_DB(in_channels: Optional[List[int]] = None, inner_channels: int = 256, bias: bool = False, *args, **kwargs)
Bases: Module
bias: Whether conv layers have bias or not.
Source code in SaigeToolkit/model/neck/fpn.py
util
get_last_conv_channels
WARNING: This will return the number of output channels of the last conv layer defined in model,
and it could differ from the actual output channels of the model.
Parameters:
-
model(Module) –torch.nn.Module who will return its last conv layer channels
Returns:
-
int(int) –last conv layer channels
Source code in SaigeToolkit/model/util.py
extend_state_dict_input_channel
extend_state_dict_input_channel(state_dict: Mapping[str, Any], input_weight_key: str, input_conv_layer: Conv2d) -> None
(Multipage) 3채널 이상인 이미지를 사용하기 위해 필요한 기능이며, state_dict의 input conv 채널이 네트워크의 input conv 채널보다 작은 경우 해당 weight의 채널을 늘려줍니다. 현재 네트워크가 가진 input conv 웨이트에서 앞 3 채널을 state_dict의 input conv 웨이트로 치환하는 방식을 사용합니다.
Parameters:
-
state_dict(Mapping[str, Any]) –로드하려는 weight
-
input_weight_key(str) –input conv weight의 이름
-
input_conv_layer(Conv2d) –input conv layer