yamle.models.resnet module#
- class yamle.models.resnet.BasicBlock(inplanes, planes, stride=1, normalization=<class 'torch.nn.modules.batchnorm.BatchNorm2d'>, normalization_kwargs={}, first=False)[source]#
Bases:
ModuleA basic block for ResNet. It consists of two convolutional layers with batch normalization and ReLU activation. :type _sphinx_paramlinks_yamle.models.resnet.BasicBlock.inplanes:
int:param _sphinx_paramlinks_yamle.models.resnet.BasicBlock.inplanes: The number of input channels. :type _sphinx_paramlinks_yamle.models.resnet.BasicBlock.inplanes: int :type _sphinx_paramlinks_yamle.models.resnet.BasicBlock.planes:int:param _sphinx_paramlinks_yamle.models.resnet.BasicBlock.planes: The number of output channels. :type _sphinx_paramlinks_yamle.models.resnet.BasicBlock.planes: int :type _sphinx_paramlinks_yamle.models.resnet.BasicBlock.stride:int:param _sphinx_paramlinks_yamle.models.resnet.BasicBlock.stride: The stride of the first convolutional layer. :type _sphinx_paramlinks_yamle.models.resnet.BasicBlock.stride: int :type _sphinx_paramlinks_yamle.models.resnet.BasicBlock.normalization:Type[Module] :param _sphinx_paramlinks_yamle.models.resnet.BasicBlock.normalization: The normalization to use. :type _sphinx_paramlinks_yamle.models.resnet.BasicBlock.normalization: Type[nn.Module] :type _sphinx_paramlinks_yamle.models.resnet.BasicBlock.normalization_kwargs:Dict[str,Any] :param _sphinx_paramlinks_yamle.models.resnet.BasicBlock.normalization_kwargs: The keyword arguments for the normalization. :type _sphinx_paramlinks_yamle.models.resnet.BasicBlock.normalization_kwargs: Dict[str, Any] :type _sphinx_paramlinks_yamle.models.resnet.BasicBlock.first:bool:param _sphinx_paramlinks_yamle.models.resnet.BasicBlock.first: Whether this is the first block in the sequence. Defaults to False. :type _sphinx_paramlinks_yamle.models.resnet.BasicBlock.first: bool- expansion = 1#
-
training:
bool#
- class yamle.models.resnet.Bottleneck(inplanes, planes, stride=1, normalization=<class 'torch.nn.modules.batchnorm.BatchNorm2d'>, normalization_kwargs={}, first=False)[source]#
Bases:
ModuleA bottleneck block for ResNet. It consists of 3 convolutional layers with batch normalization and ReLU activation. It is used to construct wide ResNet.
- Parameters:
inplanes¶ (int) – The number of input channels.
planes¶ (int) – The number of output channels.
stride¶ (int) – The stride of the first convolutional layer.
normalization¶ (Type[nn.Module]) – The normalization to use.
normalization_kwargs¶ (Dict[str, Any]) – The keyword arguments for the normalization.
first¶ (bool) – Whether this is the first block in the sequence. Defaults to False.
- base_width_multiplier = 2#
- groups = 1#
- expansion = 4#
- base_width = 32#
-
training:
bool#
- class yamle.models.resnet.Blocks(inplanes, planes, blocks, stride, normalization, normalization_kwargs={}, block=<class 'yamle.models.resnet.BasicBlock'>)[source]#
Bases:
ModuleA class implementing a stack of basic blocks. :type _sphinx_paramlinks_yamle.models.resnet.Blocks.inplanes:
int:param _sphinx_paramlinks_yamle.models.resnet.Blocks.inplanes: The number of input channels. :type _sphinx_paramlinks_yamle.models.resnet.Blocks.inplanes: int :type _sphinx_paramlinks_yamle.models.resnet.Blocks.planes:int:param _sphinx_paramlinks_yamle.models.resnet.Blocks.planes: The number of output channels. :type _sphinx_paramlinks_yamle.models.resnet.Blocks.planes: int :type _sphinx_paramlinks_yamle.models.resnet.Blocks.blocks:int:param _sphinx_paramlinks_yamle.models.resnet.Blocks.blocks: The number of basic blocks. :type _sphinx_paramlinks_yamle.models.resnet.Blocks.blocks: int :type _sphinx_paramlinks_yamle.models.resnet.Blocks.stride:int:param _sphinx_paramlinks_yamle.models.resnet.Blocks.stride: The stride of the first convolutional layer. :type _sphinx_paramlinks_yamle.models.resnet.Blocks.stride: int :type _sphinx_paramlinks_yamle.models.resnet.Blocks.normalization:Type[Module] :param _sphinx_paramlinks_yamle.models.resnet.Blocks.normalization: The normalization to use. :type _sphinx_paramlinks_yamle.models.resnet.Blocks.normalization: Type[nn.Module] :type _sphinx_paramlinks_yamle.models.resnet.Blocks.normalization_kwargs:Dict[str,Any] :param _sphinx_paramlinks_yamle.models.resnet.Blocks.normalization_kwargs: The keyword arguments for the normalization. :type _sphinx_paramlinks_yamle.models.resnet.Blocks.normalization_kwargs: Dict[str, Any] :type _sphinx_paramlinks_yamle.models.resnet.Blocks.block:Union[Type[BasicBlock],Type[Bottleneck]] :param _sphinx_paramlinks_yamle.models.resnet.Blocks.block: The block to use. Defaults to BasicBlock. :type _sphinx_paramlinks_yamle.models.resnet.Blocks.block: Union[Type[BasicBlock], Type[Bottleneck]]-
training:
bool#
-
training:
- class yamle.models.resnet.ResNetModel(layers=[2, 2, 2, 2], depth=None, planes=[32, 64, 128, 256], width_multiplier=1, strides=[1, 2, 2, 2], normalization='batch', block='basic', *args, **kwargs)[source]#
Bases:
BaseModelThis class implements the ResNet architecture as described in the paper: Deep Residual Learning for Image Recognition, published at the IEEE Conference on Computer Vision and Pattern Recognition, CVPR, 2016. and the paper can be found at: https://arxiv.org/abs/1512.03385.
The code is based on the implementation of the model is sourced from: https://pytorch.org/hub/pytorch_vision_resnet/
- Parameters:
layers¶ (List[int]) – The number of basic blocks in each stack.
depth¶ (int) – The depth of the network respective to the the length of the layers list.
planes¶ (List[int]) – The number of output channels in each stack.
width_multiplier¶ (int) – The width multiplier for the planes list.
strides¶ (List[int]) – The stride of the first convolutional layer in each stack.
normalization¶ (Optional[str]) – The normalization to use. Can be either ‘batch’, ‘instance’, group, layer, or None. Defaults to ‘batch’.
block¶ (str) – The block to use. Can be either ‘basic’ or ‘bottleneck’. Defaults to ‘basic’.
- tasks = ['regression', 'classification']#
-
training:
bool#
- forward(x, staged_output=False, input_kwargs={}, output_kwargs={})[source]#
The forward function of the ResNet model.
- Parameters:
- Return type:
Union[Tensor,Tuple[Tensor,List[Tensor]]]
- final_layer(x, **output_kwargs)[source]#
This function is used to get the final layer output.
- Return type:
Tensor
- add_method_specific_layers(method, **kwargs)[source]#
This method is used to add method specific layers to the model.
- Parameters:
method¶ (str) – The method to use.
- Return type:
None