Models#

AlexNet#

class archai.supergraph.models.alexnet.AlexNet(num_classes=1000, init_weights='True')[source]#
init_weights()[source]#
forward(x)[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#
archai.supergraph.models.alexnet.alexnet(pretrained=False, progress=True, device='cpu', **kwargs)[source]#

AlexNet architecture implemented from the paper “ImageNet Classification with Deep Convolutional Neural Networks” <https://papers.nips.cc/paper/4824-imagenet-classification-with-deep-convolutional-neural-networks>

Parameters:
  • pretrained (bool) – If True, returns a pre-trained model. In that case, the ‘init_weights’ argument of ‘AlexNet’ class is set to False

  • progress (bool) – If True, displays a progress bar of the download to stderr

  • device – default is ‘cpu’

DenseNet#

class archai.supergraph.models.densenet.DenseNet(growth_rate=32, block_config=(6, 12, 24, 16), num_init_features=64, bn_size=4, drop_rate=0, num_classes=10)[source]#

Densenet-BC model class, based on “Densely Connected Convolutional Networks”

Parameters:
  • growth_rate (int) - how many filters to add each layer (k in paper) –

  • block_config (list of 4 ints) –

  • num_init_features (int) –

  • bn_size (int) – (i.e. bn_size * k features in the bottleneck layer)

  • drop_rate (float) –

  • num_classes (int) –

forward(x)[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#
archai.supergraph.models.densenet.densenet121(pretrained=False, progress=True, device='cpu', **kwargs)[source]#

Densenet-121 model from “Densely Connected Convolutional Networks”

Parameters:
  • pretrained (bool) – If True, returns a model pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

archai.supergraph.models.densenet.densenet169(pretrained=False, progress=True, device='cpu', **kwargs)[source]#

Densenet-169 model from “Densely Connected Convolutional Networks”

Parameters:
  • pretrained (bool) – If True, returns a model pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

archai.supergraph.models.densenet.densenet201(pretrained=False, progress=True, device='cpu', **kwargs)[source]#

Densenet-201 model from “Densely Connected Convolutional Networks”

Parameters:
  • pretrained (bool) – If True, returns a model pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

archai.supergraph.models.densenet.densenet161(pretrained=False, progress=True, device='cpu', **kwargs)[source]#

Densenet-161 model from “Densely Connected Convolutional Networks”

Parameters:
  • pretrained (bool) – If True, returns a model pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

GoogleNet#

class archai.supergraph.models.googlenet.GoogLeNet(num_classes=10, aux_logits=False, transform_input=False)[source]#
forward(x)[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#
archai.supergraph.models.googlenet.googlenet(pretrained=False, progress=True, device='cpu', **kwargs)[source]#

GoogLeNet (Inception v1) model architecture from “Going Deeper with Convolutions”.

Parameters:
  • pretrained (bool) – If True, returns a model pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

  • aux_logits (bool) – If True, adds two auxiliary branches that can improve training. Default: False when pretrained is True otherwise True

  • transform_input (bool) – If True, preprocesses the input according to the method with which it was trained on ImageNet. Default: False

Inception#

class archai.supergraph.models.inception.Inception3(num_classes=10, aux_logits=False, transform_input=False)[source]#
forward(x)[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#
archai.supergraph.models.inception.inception_v3(pretrained=False, progress=True, device='cpu', **kwargs)[source]#

Inception v3 model architecture from “Rethinking the Inception Architecture for Computer Vision”.

Note

Important: In contrast to the other models the inception_v3 expects tensors with a size of N x 3 x 299 x 299, so ensure your images are sized accordingly.

Parameters:
  • pretrained (bool) – If True, returns a model pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

  • aux_logits (bool) – If True, add an auxiliary branch that can improve training. Default: True

  • transform_input (bool) – If True, preprocesses the input according to the method with which it was trained on ImageNet. Default: False

MobileNetV2#

class archai.supergraph.models.mobilenetv2.MobileNetV2(num_classes=10, width_mult=1.0)[source]#
forward(x)[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#
archai.supergraph.models.mobilenetv2.mobilenet_v2(pretrained=False, progress=True, device='cpu', **kwargs)[source]#

Constructs a MobileNetV2 architecture from “MobileNetV2: Inverted Residuals and Linear Bottlenecks”.

Parameters:
  • pretrained (bool) – If True, returns a model pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

PyramidNet#

archai.supergraph.models.pyramidnet.conv3x3(in_planes, out_planes, stride=1)[source]#

3x3 convolution with padding

class archai.supergraph.models.pyramidnet.BasicBlock(inplanes, planes, stride=1, downsample=None, p_shakedrop=1.0)[source]#
outchannel_ratio = 1#
forward(x)[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 archai.supergraph.models.pyramidnet.Bottleneck(inplanes, planes, stride=1, downsample=None, p_shakedrop=1.0)[source]#
outchannel_ratio = 4#
forward(x)[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 archai.supergraph.models.pyramidnet.PyramidNet(dataset, depth, alpha, n_classes, bottleneck=True)[source]#
training: bool#
pyramidal_make_layer(block, block_depth, stride=1)[source]#
forward(x)[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.

ResNet#

class archai.supergraph.models.resnet.ResNet(block, layers, num_classes=10, zero_init_residual=False, groups=1, width_per_group=64, replace_stride_with_dilation=None, norm_layer=None)[source]#
forward(x)[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#
archai.supergraph.models.resnet.resnet18(pretrained=False, progress=True, device='cpu', **kwargs)[source]#

Constructs a ResNet-18 model.

Parameters:
  • pretrained (bool) – If True, returns a model pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

archai.supergraph.models.resnet.resnet34(pretrained=False, progress=True, device='cpu', **kwargs)[source]#

Constructs a ResNet-34 model.

Parameters:
  • pretrained (bool) – If True, returns a model pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

archai.supergraph.models.resnet.resnet50(pretrained=False, progress=True, device='cpu', **kwargs)[source]#

Constructs a ResNet-50 model.

Parameters:
  • pretrained (bool) – If True, returns a model pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

archai.supergraph.models.resnet.resnet101(pretrained=False, progress=True, device='cpu', **kwargs)[source]#

Constructs a ResNet-101 model.

Parameters:
  • pretrained (bool) – If True, returns a model pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

archai.supergraph.models.resnet.resnet152(pretrained=False, progress=True, device='cpu', **kwargs)[source]#

Constructs a ResNet-152 model.

Parameters:
  • pretrained (bool) – If True, returns a model pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

archai.supergraph.models.resnet.resnext50_32x4d(pretrained=False, progress=True, device='cpu', **kwargs)[source]#

Constructs a ResNeXt-50 32x4d model.

Parameters:
  • pretrained (bool) – If True, returns a model pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

archai.supergraph.models.resnet.resnext101_32x8d(pretrained=False, progress=True, device='cpu', **kwargs)[source]#

Constructs a ResNeXt-101 32x8d model.

Parameters:
  • pretrained (bool) – If True, returns a model pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

ResNet (Original)#

archai.supergraph.models.resnet_orig.resnet_orig(pretrained=False, device='cpu')[source]#

ResNet (Paper)#

Properly implemented ResNet-s for CIFAR10 as described in paper [1].

The implementation and structure of this file is hugely influenced by [2] which is implemented for ImageNet and doesn’t have option A for identity. Moreover, most of the implementations on the web is copy-paste from torchvision’s resnet and has wrong number of params.

Proper ResNet-s for CIFAR10 (for fair comparision and etc.) has following number of layers and parameters:

name | layers | params ResNet20 | 20 | 0.27M ResNet32 | 32 | 0.46M ResNet44 | 44 | 0.66M ResNet56 | 56 | 0.85M ResNet110 | 110 | 1.7M ResNet1202| 1202 | 19.4m

which this implementation indeed has.

Reference: [1] Kaiming He, Xiangyu Zhang, Shaoqing Ren, Jian Sun. Deep Residual Learning for Image Recognition. arXiv:1512.03385 [2] https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py

If you use this implementation in you work, please don’t forget to mention the author, Yerlan Idelbayev.

class archai.supergraph.models.resnet_paper.ResNet(block, num_blocks, num_classes=10)[source]#
forward(x)[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#
archai.supergraph.models.resnet_paper.resnet20()[source]#
archai.supergraph.models.resnet_paper.resnet32()[source]#
archai.supergraph.models.resnet_paper.resnet44()[source]#
archai.supergraph.models.resnet_paper.resnet56()[source]#
archai.supergraph.models.resnet_paper.resnet110()[source]#
archai.supergraph.models.resnet_paper.resnet1202()[source]#

ShakeDrop#

class archai.supergraph.models.shakedrop.ShakeDropFunction(*args, **kwargs)[source]#
static forward(ctx, x, training=True, p_drop=0.5, alpha_range=[-1, 1])[source]#

This function is to be overridden by all subclasses. There are two ways to define forward:

Usage 1 (Combined forward and ctx):

@staticmethod
def forward(ctx: Any, *args: Any, **kwargs: Any) -> Any:
    pass
  • It must accept a context ctx as the first argument, followed by any number of arguments (tensors or other types).

  • See combining-forward-context for more details

Usage 2 (Separate forward and ctx):

@staticmethod
def forward(*args: Any, **kwargs: Any) -> Any:
    pass

@staticmethod
def setup_context(ctx: Any, inputs: Tuple[Any, ...], output: Any) -> None:
    pass
  • The forward no longer accepts a ctx argument.

  • Instead, you must also override the torch.autograd.Function.setup_context() staticmethod to handle setting up the ctx object. output is the output of the forward, inputs are a Tuple of inputs to the forward.

  • See extending-autograd for more details

The context can be used to store arbitrary data that can be then retrieved during the backward pass. Tensors should not be stored directly on ctx (though this is not currently enforced for backward compatibility). Instead, tensors should be saved either with ctx.save_for_backward() if they are intended to be used in backward (equivalently, vjp) or ctx.save_for_forward() if they are intended to be used for in jvp.

static backward(ctx, grad_output)[source]#

Defines a formula for differentiating the operation with backward mode automatic differentiation (alias to the vjp function).

This function is to be overridden by all subclasses.

It must accept a context ctx as the first argument, followed by as many outputs as the forward() returned (None will be passed in for non tensor outputs of the forward function), and it should return as many tensors, as there were inputs to forward(). Each argument is the gradient w.r.t the given output, and each returned value should be the gradient w.r.t. the corresponding input. If an input is not a Tensor or is a Tensor not requiring grads, you can just pass None as a gradient for that input.

The context can be used to retrieve tensors saved during the forward pass. It also has an attribute ctx.needs_input_grad as a tuple of booleans representing whether each input needs gradient. E.g., backward() will have ctx.needs_input_grad[0] = True if the first input to forward() needs gradient computated w.r.t. the output.

class archai.supergraph.models.shakedrop.ShakeDrop(p_drop=0.5, alpha_range=[-1, 1])[source]#
forward(x)[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#

VGG#

class archai.supergraph.models.vgg.VGG(features, num_classes=10, init_weights=True)[source]#
forward(x)[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#
archai.supergraph.models.vgg.vgg11(pretrained=False, progress=True, **kwargs)[source]#

VGG 11-layer model (configuration “A”)

Parameters:
  • pretrained (bool) – If True, returns a model pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

archai.supergraph.models.vgg.vgg11_bn(pretrained=False, progress=True, device='cpu', **kwargs)[source]#

VGG 11-layer model (configuration “A”) with batch normalization

Parameters:
  • pretrained (bool) – If True, returns a model pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

archai.supergraph.models.vgg.vgg13(pretrained=False, progress=True, **kwargs)[source]#

VGG 13-layer model (configuration “B”)

Parameters:
  • pretrained (bool) – If True, returns a model pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

archai.supergraph.models.vgg.vgg13_bn(pretrained=False, progress=True, device='cpu', **kwargs)[source]#

VGG 13-layer model (configuration “B”) with batch normalization

Parameters:
  • pretrained (bool) – If True, returns a model pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

archai.supergraph.models.vgg.vgg16(pretrained=False, progress=True, **kwargs)[source]#

VGG 16-layer model (configuration “D”)

Parameters:
  • pretrained (bool) – If True, returns a model pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

archai.supergraph.models.vgg.vgg16_bn(pretrained=False, progress=True, device='cpu', **kwargs)[source]#

VGG 16-layer model (configuration “D”) with batch normalization

Parameters:
  • pretrained (bool) – If True, returns a model pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

archai.supergraph.models.vgg.vgg19_bn(pretrained=False, progress=True, device='cpu', **kwargs)[source]#

VGG 19-layer model (configuration ‘E’) with batch normalization

Parameters:
  • pretrained (bool) – If True, returns a model pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

archai.supergraph.models.vgg.vgg19(pretrained=False, progress=True, **kwargs)[source]#

VGG 19-layer model (configuration “E”)

Parameters:
  • pretrained (bool) – If True, returns a model pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

Wide ResNet#

archai.supergraph.models.wideresnet.conv3x3(in_planes, out_planes, stride=1)[source]#
archai.supergraph.models.wideresnet.conv_init(m)[source]#
class archai.supergraph.models.wideresnet.WideBasic(in_planes, planes, dropout_rate, stride=1)[source]#
forward(x)[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 archai.supergraph.models.wideresnet.WideResNet(depth, widen_factor, dropout_rate, n_classes)[source]#
forward(x)[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#