Implementing the second generation ResNet with some tweaks presented in: https://arxiv.org/abs/1812.01187

ImageNet Dataset

I think we've been using MNIST for a little too long, to really test out the models going forward we're going to need to start using some bigger and harder datasets. Opting for another class, let's get Imagenet setup using FastAI's DataBlock API

get_imaggenette[source]

get_imaggenette()

Grabs imagenette dataset

Fundamental ResNet Modules

class Identity[source]

Identity() :: Module

Layer that doesn't do anything

class AutoConv[source]

AutoConv(in_channels, out_channels, kernel_size, **kwargs) :: Module

Base class for all neural network modules.

Your models should also subclass this class.

Modules can also contain other Modules, allowing to nest them in a tree structure. You can assign the submodules as regular attributes::

import torch.nn as nn
import torch.nn.functional as F

class Model(nn.Module):
    def __init__(self):
        super(Model, self).__init__()
        self.conv1 = nn.Conv2d(1, 20, 5)
        self.conv2 = nn.Conv2d(20, 20, 5)

    def forward(self, x):
        x = F.relu(self.conv1(x))
        return F.relu(self.conv2(x))

Submodules assigned in this way will be registered, and will have their parameters converted too when you call :meth:to, etc.

class ConvBatchLayer[source]

ConvBatchLayer(in_channels, out_channels, kernel_size=3, Activation='Identity', **kwargs) :: Module

Base class for all neural network modules.

Your models should also subclass this class.

Modules can also contain other Modules, allowing to nest them in a tree structure. You can assign the submodules as regular attributes::

import torch.nn as nn
import torch.nn.functional as F

class Model(nn.Module):
    def __init__(self):
        super(Model, self).__init__()
        self.conv1 = nn.Conv2d(1, 20, 5)
        self.conv2 = nn.Conv2d(20, 20, 5)

    def forward(self, x):
        x = F.relu(self.conv1(x))
        return F.relu(self.conv2(x))

Submodules assigned in this way will be registered, and will have their parameters converted too when you call :meth:to, etc.

class BaseRes[source]

BaseRes(expansion, n_in, n_h, stride=1, Activation='ReLU', **kwargs) :: Module

Base class for all neural network modules.

Your models should also subclass this class.

Modules can also contain other Modules, allowing to nest them in a tree structure. You can assign the submodules as regular attributes::

import torch.nn as nn
import torch.nn.functional as F

class Model(nn.Module):
    def __init__(self):
        super(Model, self).__init__()
        self.conv1 = nn.Conv2d(1, 20, 5)
        self.conv2 = nn.Conv2d(20, 20, 5)

    def forward(self, x):
        x = F.relu(self.conv1(x))
        return F.relu(self.conv2(x))

Submodules assigned in this way will be registered, and will have their parameters converted too when you call :meth:to, etc.

class XResnet[source]

XResnet(expansion, c_in, c_out, layer_depths, **kwargs) :: Module

Base class for all neural network modules.

Your models should also subclass this class.

Modules can also contain other Modules, allowing to nest them in a tree structure. You can assign the submodules as regular attributes::

import torch.nn as nn
import torch.nn.functional as F

class Model(nn.Module):
    def __init__(self):
        super(Model, self).__init__()
        self.conv1 = nn.Conv2d(1, 20, 5)
        self.conv2 = nn.Conv2d(20, 20, 5)

    def forward(self, x):
        x = F.relu(self.conv1(x))
        return F.relu(self.conv2(x))

Submodules assigned in this way will be registered, and will have their parameters converted too when you call :meth:to, etc.

getResnet[source]

getResnet(size, c_in, c_out, **kwargs)

class CudaCallback[source]

CudaCallback() :: Callback

Quick callback to put model onto the GPU

run = get_runner(get_learner(getResnet(18, 3, 10)), [ProgressCallback(), Stats([accuracy]), CudaCallback()])
run.fit(1, 1e-3)
epoch train_loss train_accuracy valid_loss valid_accuracy time
0 1.731658 0.417290 1.382680 0.539955 01:38
!python notebook2script.py XResNet.ipynb
Converted XResNet.ipynb to ModernArchitecturesFromPyTorch/nb_XResNet.py