glasses.models.classification.vgg package¶
Module contents¶
- class glasses.models.classification.vgg.VGG(encoder: torch.nn.modules.module.Module = <class 'glasses.models.classification.vgg.VGGEncoder'>, head: torch.nn.modules.module.Module = <class 'glasses.models.classification.vgg.VGGHead'>, **kwargs)[source]¶
Bases:
glasses.models.classification.base.ClassificationModule
Implementation of VGG proposed in Very Deep Convolutional Networks For Large-Scale Image Recognition
VGG.vgg11() VGG.vgg13() VGG.vgg16() VGG.vgg19() VGG.vgg11_bn() VGG.vgg13_bn() VGG.vgg16_bn() VGG.vgg19_bn()
Please be aware that the bn models uses BatchNorm but they are very old and people back then don’t know the bias is superfluous in a conv followed by a batchnorm.
Examples
# change activation VGG.vgg11(activation = nn.SELU) # change number of classes (default is 1000 ) VGG.vgg11(n_classes=100) # pass a different block from nn.models.classification.senet import SENetBasicBlock VGG.vgg11(block=SENetBasicBlock) # store the features tensor after every block
- Parameters
in_channels (int, optional) – Number of channels in the input Image (3 for RGB and 1 for Gray). Defaults to 3.
n_classes (int, optional) – Number of classes. Defaults to 1000.
Initializes internal Module state, shared by both nn.Module and ScriptModule.
- training: bool¶
- classmethod vgg11(*args, **kwargs) glasses.models.classification.vgg.VGG [source]¶
Creates a vgg11 model
- Returns
A vgg11 model
- Return type
- classmethod vgg11_bn(*args, **kwargs) glasses.models.classification.vgg.VGG [source]¶
Creates a vgg11 model with batchnorm
- Returns
A vgg13 model
- Return type
- classmethod vgg13(*args, **kwargs) glasses.models.classification.vgg.VGG [source]¶
Creates a vgg13 model
- Returns
A vgg13 model
- Return type
- classmethod vgg13_bn(*args, **kwargs) glasses.models.classification.vgg.VGG [source]¶
Creates a vgg13 model with batchnorm
- Returns
A vgg13 model
- Return type
- classmethod vgg16(*args, **kwargs) glasses.models.classification.vgg.VGG [source]¶
Creates a vgg16 model
- Returns
A vgg16 model
- Return type
- classmethod vgg16_bn(*args, **kwargs) glasses.models.classification.vgg.VGG [source]¶
Creates a vgg16 model with batchnorm
- Returns
A vgg16 model
- Return type
- classmethod vgg19(*args, **kwargs) glasses.models.classification.vgg.VGG [source]¶
Creates a vgg19 model
- Returns
A vgg19 model
- Return type
- classmethod vgg19_bn(*args, **kwargs) glasses.models.classification.vgg.VGG [source]¶
Creates a vgg19 model with batchnorm
- Returns
A vgg19 model
- Return type
- class glasses.models.classification.vgg.VGGEncoder(in_channels: int = 3, widths: List[int] = [64, 128, 256, 512, 512], depths: List[int] = [1, 1, 2, 2, 2], block: torch.nn.modules.module.Module = functools.partial(<class 'glasses.nn.blocks.ConvBnAct'>, normalization=None, bias=True, kernel_size=3), **kwargs)[source]¶
Bases:
glasses.models.base.Encoder
VGG encoder, composed by default by a sequence of VGGLayer modules with an increasing number of output features.
- Parameters
in_channels (int, optional) – [description]. Defaults to 3.
widths (List[int], optional) – [description]. Defaults to [64, 128, 256, 512, 512].
depths (List[int], optional) – [description]. Defaults to [1, 1, 2, 2, 2].
activation (nn.Module, optional) – [description]. Defaults to ReLUInPlace.
block (nn.Module, optional) – [description]. Defaults to VGGBasicBlock.
Initializes internal Module state, shared by both nn.Module and ScriptModule.
- forward(x: torch.Tensor) torch.Tensor [source]¶
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- training: bool¶
- class glasses.models.classification.vgg.VGGHead(in_features: int, n_classes: int)[source]¶
Bases:
torch.nn.modules.container.Sequential
This class represents the classifier of VGG. It converts the filters into 6x6 by means of the average pooling. Then, it maps the output to the correct class by means of fully connected layers. Dropout is used to decrease the overfitting.
Args: out_features (int): Number of input features n_classes (int): [description]
Initializes internal Module state, shared by both nn.Module and ScriptModule.
- class glasses.models.classification.vgg.VGGLayer(in_features: int, out_features: int, block: torch.nn.modules.module.Module = functools.partial(<class 'glasses.nn.blocks.ConvBnAct'>, normalization=None, bias=True, kernel_size=3), pool: torch.nn.modules.module.Module = <class 'torch.nn.modules.pooling.MaxPool2d'>, depth: int = 1, **kwargs)[source]¶
Bases:
torch.nn.modules.container.Sequential
This class implements a VGG layer, which is composed by a number of blocks (default is VGGBasicBlock, which is a simple convolution-activation transformation) eventually followed by maxpooling.
- Parameters
in_channels (int) – [description]
out_channels (int) – [description]
block (nn.Module, optional) – [description]. Defaults to VGGBasicBlock.
n (int, optional) – [description]. Defaults to 1.
maxpool (nn.Module, optional) – [description]. Defaults to nn.MaxPool2d.
Initializes internal Module state, shared by both nn.Module and ScriptModule.