glasses.models.classification.wide_resnet package¶
Module contents¶
- class glasses.models.classification.wide_resnet.WideResNet(encoder: torch.nn.modules.module.Module = <class 'glasses.models.classification.resnet.ResNetEncoder'>, head: torch.nn.modules.module.Module = <class 'glasses.models.classification.resnet.ResNetHead'>, **kwargs)[source]¶
Bases:
glasses.models.classification.resnet.ResNet
Implementation of Wide ResNet proposed in “Wide Residual Networks”
Create a default model
WideResNet.wide_resnet50_2() WideResNet.wide_resnet101_2() # create a wide_resnet18_4 WideResNet.resnet18(block=WideResNetBottleNeckBlock, width_factor=4)
Examples
# change activation WideResNet.resnext50_32x4d(activation = nn.SELU) # change number of classes (default is 1000 ) WideResNet.resnext50_32x4d(n_classes=100) # pass a different block WideResNet.resnext50_32x4d(block=SENetBasicBlock) # change the initial convolution model = WideResNet.resnext50_32x4d model.encoder.gate.conv1 = nn.Conv2d(3, 64, kernel_size=3) # store each feature x = torch.rand((1, 3, 224, 224)) model = WideResNet.wide_resnet50_2() features = [] x = model.encoder.gate(x) for block in model.encoder.layers: x = block(x) features.append(x) print([x.shape for x in features]) # [torch.Size([1, 64, 56, 56]), torch.Size([1, 128, 28, 28]), torch.Size([1, 256, 14, 14]), torch.Size([1, 512, 7, 7])]
- 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 wide_resnet101_2(*args, **kwargs) glasses.models.classification.wide_resnet.WideResNet [source]¶
Creates a wide_resnet50_2 model
- Returns
A wide_resnet50_2 model
- Return type
- classmethod wide_resnet50_2(*args, **kwargs) glasses.models.classification.wide_resnet.WideResNet [source]¶
Creates a wide_resnet50_2 model
- Returns
A wide_resnet50_2 model
- Return type
- class glasses.models.classification.wide_resnet.WideResNetBottleNeckBlock(in_features: int, out_features: int, width_factor: int = 2, reduction: int = 4, **kwargs)[source]¶
Bases:
glasses.models.classification.resnet.ResNetBottleneckBlock
Wide resnet bottle neck block, you can control the width of the inner features with the width_factor parameter :param in_features: [description] :type in_features: int :param out_features: [description] :type out_features: int :param width_factor: Scales the 3x3 conv features in the bottle neck block. Defaults to 2. :type width_factor: int, optional
Initializes internal Module state, shared by both nn.Module and ScriptModule.
- training: bool¶