glasses.models.classification.resnetxt package

Module contents

class glasses.models.classification.resnetxt.ResNetXt(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 ResNetXt proposed in “Aggregated Residual Transformation for Deep Neural Networks”

Create a default model

ResNetXt.resnext50_32x4d()
ResNetXt.resnext101_32x8d()
# create a resnetxt18_32x4d
ResNetXt.resnet18(block=ResNetXtBottleNeckBlock, groups=32, base_width=4)

Examples

# change activation
ResNetXt.resnext50_32x4d(activation = nn.SELU)
# change number of classes (default is 1000 )
ResNetXt.resnext50_32x4d(n_classes=100)
# pass a different block
ResNetXt.resnext50_32x4d(block=SENetBasicBlock)
# change the initial convolution
model = ResNetXt.resnext50_32x4d
model.encoder.gate.conv1 = nn.Conv2d(3, 64, kernel_size=3)
# store each feature
x = torch.rand((1, 3, 224, 224))
model = ResNetXt.resnext50_32x4d()
# first call .features, this will activate the forward hooks and tells the model you'll like to get the features
model.encoder.features
model(torch.randn((1,3,224,224)))
# get the features from the encoder
features = model.encoder.features
print([x.shape for x in features])
#[torch.Size([1, 64, 112, 112]), torch.Size([1, 64, 56, 56]), torch.Size([1, 128, 28, 28]), torch.Size([1, 256, 14, 14])]
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.

classmethod resnext101_32x16d(*args, **kwargs) glasses.models.classification.resnetxt.ResNetXt[source]

Creates a resnext101_32x16d model

Returns

A resnext101_32x16d model

Return type

ResNet

classmethod resnext101_32x32d(*args, **kwargs) glasses.models.classification.resnetxt.ResNetXt[source]

Creates a resnext101_32x32d model

Returns

A resnext101_32x32d model

Return type

ResNet

classmethod resnext101_32x48d(*args, **kwargs) glasses.models.classification.resnetxt.ResNetXt[source]

Creates a resnext101_32x48d model

Returns

A resnext101_32x48d model

Return type

ResNet

classmethod resnext101_32x8d(*args, **kwargs) glasses.models.classification.resnetxt.ResNetXt[source]

Creates a resnext101_32x8d model

Returns

A resnext101_32x8d model

Return type

ResNet

classmethod resnext50_32x4d(*args, **kwargs) glasses.models.classification.resnetxt.ResNetXt[source]

Creates a resnext50_32x4d model

Returns

A resnext50_32x4d model

Return type

ResNet

training: bool
class glasses.models.classification.resnetxt.ResNetXtBottleNeckBlock(in_features: int, out_features: int, groups: int = 32, base_width: int = 4, reduction: int = 4, **kwargs)[source]

Bases: glasses.models.classification.resnet.ResNetBottleneckBlock

Basic ResNetXt block build on top of ResNetBottleneckBlock. It uses base_width to compute the inner features of the 3x3 conv.

Parameters
  • in_features (int) – Number of input features

  • out_features (int) – Number of output features

  • groups (int, optional) – [description]. Defaults to 32.

  • base_width (int, optional) – width factor uses to compute the inner features in the 3x3 conv. Defaults to 4.

training: bool