glasses.models.classification.alexnet package¶
Module contents¶
- class glasses.models.classification.alexnet.AlexNet(encoder: torch.nn.modules.module.Module = <class 'glasses.models.classification.alexnet.AlexNetEncoder'>, head: torch.nn.modules.module.Module = <class 'glasses.models.classification.alexnet.AlexNetHead'>, **kwargs)[source]¶
Bases:
glasses.models.classification.base.ClassificationModule
Implementation of AlexNet proposed in ImageNet Classification with Deep Convolutional Neural Networks, according to the variation implemented in torchvision.
net = AlexNet()
Examples
# change activation AlexNet(activation = nn.SELU) # change number of classes (default is 1000 ) AlexNet(n_classes=100) # pass a different block AlexNet(block=SENetBasicBlock)
- Parameters
in_channels (int, optional) – Number of channels in the input Image (3 for RGB and 1 for Gray). Default is 3.
n_classes (int, optional) – Number of classes. Default is 1000.
Initializes internal Module state, shared by both nn.Module and ScriptModule.
- training: bool¶
- class glasses.models.classification.alexnet.AlexNetEncoder(in_channels: int = 3, stem: torch.nn.modules.module.Module = <class 'glasses.models.classification.alexnet.AlexNetStem'>, widths: List[int] = [192, 384, 256, 256], activation: torch.nn.modules.module.Module = functools.partial(<class 'torch.nn.modules.activation.ReLU'>, inplace=True), block: torch.nn.modules.module.Module = functools.partial(<class 'glasses.nn.blocks.ConvBnAct'>, normalization=None, bias=True))[source]¶
Bases:
glasses.models.base.Encoder
AlexNet encoder
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.alexnet.AlexNetHead(in_features: int, n_classes: int, drop_p: float = 0.5)[source]¶
Bases:
torch.nn.modules.container.Sequential
This class represents the classifier of AlexNet. 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.
Initializes internal Module state, shared by both nn.Module and ScriptModule.
- class glasses.models.classification.alexnet.AlexNetStem(in_channels: int = 3, out_features: int = 192)[source]¶
Bases:
torch.nn.modules.container.Sequential
AlexNet stem which decreases the resolution of the filters by means of stride and bigger kernels.
Initializes internal Module state, shared by both nn.Module and ScriptModule.