Models

The Models module contains a list of model that can be used for Classification, Segmentation and Generation.

Modules

AlexNet

For network information, see AlexNet paper.

Parameters:

  • intial_feature_map_size (int,required): The input tensor size.
  • num_classes (int,required): The number of class in the data.
  • in_channels (int,required): The number of channels in the input tensor.
  • strides (list,default = [1,2,1,1,1]): The strides in each convolutional layer of the AlexNet.
  • channels (list,default = [1,2,2,2,1]): The channels in each convolutional layer of the AlexNet.
  • kernel_size (list,default = [3,5,3,3,1]): The size of kernels in each convolutional layer of the AlexNet.
  • padding (list,default = [0,1,1,1,1]): The padding in each convolutional layer of the AlexNet.
  • demographic (list,default = []): The list demographic factors to be used for classification.

Usage:

from niftytorch.models.alexnet import alexnet
import torch
initial_feature_map = 128
num_classes = 2
in_channels = 1
demographic = ['factor1','factor2']
strides = [1,2,1,1,1]
channels = [1,2,2,2,1]
kernel_size = [3,5,3,3,1]
padding = [0,1,1,1,1]
input = torch.rand(64,in_channels,initial_feature_map,initial_feature_map,initial_feature_map)
model = alexnet(initial_feature_map,num_classes = num_classes,in_channels = in_channels,strides = strides,channels = channels,kernel_size = kernel_size,padding = padding,demographic = demographic)

VGGNet

For network information, see VGGNet paper.

Parameters for VGG_Net: image_scale, cfgs, version, features, num_classes,init_weights

  • image_scale (int,requried): The input tensor size along width size.
  • cfgs (int,required): The configuration of VGG_Net
  • version (str,required): The version can be 'A','B','D' or 'E'.
  • features (torch.Tensor,required): The features from convolution layers.
  • num_classes (int,default = 2): The classes in the dataset.
  • init_weights (bool,default = False): The if true weights are initialzed using kaiming normal or else it is initialized randomly.
  • demographic (list,default = []): The list demographic factors to be used for classification.

Parameters for make_layers:

  • cfg (list,required): The configuration for VGG Net (cfgs[version]).
  • in_channels (int,default = 1): The number of channels in the input tensor.
  • batchnorm (boolean,default = True): This boolean variable is used to inidicated whether the batchnorm layer is required.

Usage:

from niftytorch.models.vggnet import vggnet
import torch
image_scale = 128
demographic = ['factor1','factor2']
cfgs = {'A':[32,32,32,'M',64,64,64]}
version = 'A'
in_channels = 1
num_classes = 2
init_weights = True
input = torch.rand(64,in_channels,image_scale,image_scale,image_scale)
model = vggnet(image_scale,cfgs = cfgs,version = version,num_classes = num_classes,init_weights = init_weights,demographic = demographic)

ResNet

For network information, see ResNet paper.

Parameters:

  • block (model,required): The block can be BasicBlock or BottleNeck Layers.
  • layers (int,required): The number of layers in the block layers.
  • stride (int,required): The stride at each layer the size of stride is same as the number of layers.
  • in_channels (int,required): The number of channels in the input data.
  • num_classes (int,required): The number of class in the data.
  • zero_init_residual (bool,default = False): This variable decides whether the batchnorm layer is to be initialized.
  • groups (int,default = 1): The number of groups to be considered in the block layer.
  • width_per_group (int,default = 64): The number of channels in each block layer.
  • replace_stride_with_dilation (bool,default = False): The dilation at each block layer.
  • norm_layer (torch.nn,default = None): The type of norm layer to be used.
  • demographic (list,default = []): The list demographic factors to be used for classification.

Usage:

from niftytorch.models.resnet import resnet
import torch
import torch.nn as nn
from niftytorch.layers.layers import bottleneck
block = bottleneck
demographic = ['factor1','factor2']
layers = [1,2,1,1,2]
stride = [1,1,1,1,1]
num_classes = 2
zero_init_residual = True
groups = 1
replace_stride_with_dilation = [2,2,2,2,2]
norm_layer = nn.Batchnorm3d
in_channels = 1
input = torch.rand(64,in_channels,32,32,32)
model = resnet(block = block,layers = layers,stride = stride,in_channels = 1,num_classes = num_classes,zero_init_residual = zero_init_residual,groups = groups,replace_stride_with_dilation = replace_stride_with_dilation,norm_layer = norm_layer,demographic = demographic)

ShuffleNet

For network information, see ShuffleNet paper.

Parameters:

  • stage_repeats (list,required): The number of times each stage is repeated
  • groups (int, deafult = 3): number of groups to be used in grouped 1x1 convolutions in each ShuffleUnit.
  • in_channels (int, deafult = 1): number of channels in the input tensor.
  • num_classes (int, default = 2): number of classes to predict.
  • demographic (list,default = []): The list demographic factors to be used for classification.

Usage:

from niftytorch.models.shufflenet import shufflenet
import torch
import torch.nn as nn
stage_repeats  = [3,7,3]
groups = 5
num_classes = 2
demographic = ['factor1','factor2']
in_channels = 1
model = shufflenet(stage_repeats = stage_repeats,groups = groups,in_channels = 1,num_classes = num_classes,demographic = demographic)

SqueezeNet

For network information, see SqueezeNet paper.

Parameters:

  • version (str,default = '1_0'): The version of shuffleNet to be used.
  • num_classes (str, deafult = 2): Number of classes in the dataset.
  • in_channels (int, deafult = 1): number of channels in the input tensor.

Usage:

from niftytorch.models.squeeznet import squeezenet
import torch
import torch.nn as nn
version  = '1_1'
num_classes = 2
in_channels = 1
model = squeezenet(version = version,num_classes = 2,in_channels = 1)

XNOR-Net

For network information, see XNOR-Net paper.

Parameters:

  • image_scale: The input tensor size along width size.
  • num_classes: Number of classes in the dataset.
  • in_channels: number of channels in the input tensor.
  • channels: The channels in each convolutional layer of the AlexNet.
  • kernel_size: The size of kernels in each convolutional layer of the AlexNet.
  • strides: The strides in each convolutional layer of the AlexNet.
  • padding: The padding in each convolutional layer of the AlexNet.
  • groups: The number of groups to be considered in the block layer.
  • demographic (list,default = []): The list demographic factors to be used for classification.

Usage:

from niftytorch.models.xnornet import alexnet
image_scale = 128
num_classes = 2
in_channels = 1
demographic = ['factor1','factor2']
channels = [8,16,24,32,32,32]
kernel_size = [11, 5, 3, 3, 3]
strides = [4, 1, 1, 1, 1]
padding = [0, 2, 1, 1, 1]
groups = [1, 1, 1, 1, 1]
model = alexnet(image_scale = image_scale,num_classes = num_classes,in_channels = in_channels,channels = channels,kernel_size = kernel_size,strides = strides,padding = padding,groups = groups,demographic = demographic)

U-Net

Parameters:

  • in_channels(int,required): The number of channels in the input data.
  • out_channels(int,required): The number of channels in the output data.
  • init_features(int,required): The number of initial features to which the upsampling and downsampling operations are applied to.
  • norm_layer (torch.nn,default = None): The type of norm layer to be used.
  • kernel_size(list,default=[]): The size of kernels in each convolutional layer of the UNet.
  • strides(list,default=[]): The strides in each convolutional layer of the UNet.
  • padding(list,default=[]): The padding in each convolutional block of the UNet.

in_channels, out_channels, stride, init_features, bias, kernel_size, padding, groups = 1, norm_layer = None

Usage:

from niftytorch.models.Unet import UNet
import torch
in_channels = 1
out_channels = 3
stride = [1,1,1,2,2,2,1,1]
init_features = 16
bias = [True,True,True,True,False]
groups = 1
kernel_size = [3,3,3,5,5,5,5,3,3,3,3]
norm_layer = torch.nn.BatchNorm3d
kernel_size = [3,3,5,5,5,5,4,4,5,4,1]
stride = [2,2,2,2,2,2,2,2]
padding = [1,1]
input = torch.rand(64,1,32,32,32)
model = UNet(in_channels = in_channels,out_channels = out_channels,stride = stride,init_features = init_features,bias = bias,kernel_size = kernel_size,padding = padding,groups = groups,norm_layer = norm_layer)
output = model(input)