frarch.models.classification.cnn.resnet module#

ResNet definition. Slightly tweaked pytorch implementation.

Description

ResNet

Authors

victor badenas (victor.badenas@gmail.com), pytorch.org

Version

0.1.0

Created on

21/07/2021 19:00

class frarch.models.classification.cnn.resnet.ResNet(block: frarch.models.classification.cnn.resnet.ResNetBlock, 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[[...], torch.nn.modules.module.Module]] = None)[source]#

Bases: torch.nn.modules.module.Module

Residual network architecture model.

Parameters
  • block (ResNetBlock) – basic construction block for architecture.

  • layers (List[int]) – layer configuration. I.e. [2, 2, 2, 2].

  • num_classes (int)) – output classes. Defaults to 1000.

  • zero_init_residual (bool) – True to initialize the residual layers with zeros. Default False.

  • groups (int) – groups for convolutional layers in residual blocks. Defaults to 1.

  • width_per_group (int) – Width for convolutional residual blocks. Defaults to 64.

  • replace_stride_with_dilation (Optional[List[bool]]) – Optional list of boolean values to replace stride with dilation. Defaults to None.

  • norm_layer (Optional[Callable[..., nn.Module]]) – Norm layer. If None, defaults to BatchNorm2d. Defautls to None.

forward(x: torch.Tensor) torch.Tensor[source]#

Define the computation performed at every call.

forward computation for ResNet.

Parameters

x (torch.Tensor) – input to the model.

Returns

output of the model.

Return type

torch.Tensor

training: bool#
frarch.models.classification.cnn.resnet.resnet101(pretrained: bool = False, progress: bool = True, **kwargs: Any) frarch.models.classification.cnn.resnet.ResNet[source]#

ResNet-101 model.

From “Deep Residual Learning for Image Recognition”.

Parameters
  • pretrained (bool) – If True, returns a model pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

frarch.models.classification.cnn.resnet.resnet152(pretrained: bool = False, progress: bool = True, **kwargs: Any) frarch.models.classification.cnn.resnet.ResNet[source]#

ResNet-152 model.

From “Deep Residual Learning for Image Recognition”.

Parameters
  • pretrained (bool) – If True, returns a model pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

frarch.models.classification.cnn.resnet.resnet18(pretrained: bool = False, progress: bool = True, **kwargs: Any) frarch.models.classification.cnn.resnet.ResNet[source]#

ResNet-18 model.

From “Deep Residual Learning for Image Recognition”.

Parameters
  • pretrained (bool) – If True, returns a model pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

frarch.models.classification.cnn.resnet.resnet34(pretrained: bool = False, progress: bool = True, **kwargs: Any) frarch.models.classification.cnn.resnet.ResNet[source]#

ResNet-34 model.

From “Deep Residual Learning for Image Recognition”.

Parameters
  • pretrained (bool) – If True, returns a model pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

frarch.models.classification.cnn.resnet.resnet50(pretrained: bool = False, progress: bool = True, **kwargs: Any) frarch.models.classification.cnn.resnet.ResNet[source]#

ResNet-50 model.

From “Deep Residual Learning for Image Recognition”.

Parameters
  • pretrained (bool) – If True, returns a model pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

frarch.models.classification.cnn.resnet.resnext101_32x8d(pretrained: bool = False, progress: bool = True, **kwargs: Any) frarch.models.classification.cnn.resnet.ResNet[source]#

ResNeXt-101 32x8d model.

From “Aggregated Residual Transformation for Deep Neural Networks”.

Parameters
  • pretrained (bool) – If True, returns a model pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

frarch.models.classification.cnn.resnet.resnext50_32x4d(pretrained: bool = False, progress: bool = True, **kwargs: Any) frarch.models.classification.cnn.resnet.ResNet[source]#

ResNeXt-50 32x4d model.

From “Aggregated Residual Transformation for Deep Neural Networks”.

Parameters
  • pretrained (bool) – If True, returns a model pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

frarch.models.classification.cnn.resnet.wide_resnet101_2(pretrained: bool = False, progress: bool = True, **kwargs: Any) frarch.models.classification.cnn.resnet.ResNet[source]#

Wide ResNet-101-2 model.

From “Wide Residual Networks”. 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
  • pretrained (bool) – If True, returns a model pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

frarch.models.classification.cnn.resnet.wide_resnet50_2(pretrained: bool = False, progress: bool = True, **kwargs: Any) frarch.models.classification.cnn.resnet.ResNet[source]#

Wide ResNet-50-2 model.

From “Wide Residual Networks”. 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
  • pretrained (bool) – If True, returns a model pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr