Menu

Helper Module for Deep Learning.

Import classifier models defined in torchvision.

class pynet.models.torchvisnet.DenseNet(growth_rate, block_config, num_init_features, num_classes, bn_size=4, drop_rate=0, memory_efficient=False)[source]

DenseNet.

__init__(growth_rate, block_config, num_init_features, num_classes, bn_size=4, drop_rate=0, memory_efficient=False)[source]

Class initilization.

Parameters

growth_rate: int

how many filters to add each layer (‘k’ in paper).

block_config: 1-uplet

how many layers in each pooling block.

num_init_features: int

the number of filters to learn in the first convolution layer.

num_classes: int

number of classification classes.

bn_size: int, default 4

multiplicative factor for number of bottle neck layers (i.e. bn_size * k features in the bottleneck layer).

drop_rate: float, default 0

dropout rate after each dense layer.

memory_efficient: bool, default False

if True, uses checkpointing. Much more memory efficient, but slower.

class pynet.models.torchvisnet.DenseNet121(num_classes, bn_size=4, drop_rate=0, memory_efficient=False)
block_config = (6, 12, 24, 16)
growth_rate = 32
num_init_features = 64
class pynet.models.torchvisnet.DenseNet161(num_classes, bn_size=4, drop_rate=0, memory_efficient=False)
block_config = (6, 12, 36, 24)
growth_rate = 48
num_init_features = 96
class pynet.models.torchvisnet.DenseNet169(num_classes, bn_size=4, drop_rate=0, memory_efficient=False)
block_config = (6, 12, 32, 32)
growth_rate = 32
num_init_features = 64
class pynet.models.torchvisnet.DenseNet201(num_classes, bn_size=4, drop_rate=0, memory_efficient=False)
block_config = (6, 12, 48, 32)
growth_rate = 32
num_init_features = 64
class pynet.models.torchvisnet.Inception3(num_classes, aux_logits=True, transform_input=False)[source]

Inception v3 by Google.

__init__(num_classes, aux_logits=True, transform_input=False)[source]

Class initilization.

Parameters

num_classes: int

number of classification classes.

aux_logits: bool, default False

auxiliary classifier for the training.

transform_input: bool, default False

normalize the data.

class pynet.models.torchvisnet.ResNet(block, layers, num_classes, zero_init_residual=False, groups=1, width_per_group=64, replace_stride_with_dilation=None, norm_layer=None)[source]

Residual Neural Network (ResNet) by Kaiming He et al.

__init__(block, layers, num_classes, zero_init_residual=False, groups=1, width_per_group=64, replace_stride_with_dilation=None, norm_layer=None)[source]

Class initilization.

Parameters

block: nn Module

one block architecture.

layers: 4-uplet

control the number of element in each layer.

num_classes: int

number of classification classes.

zero_init_residual: bool, default False

zero-initialize the last BN in each residual branch, so that the residual branch starts with zeros, and each residual block behaves like an identity.

groups: int, default 1

controls the connections between inputs and outputs during convolution.

width_per_group: int, default 64

control the number of input and output channels during convolution.

replace_stride_with_dilation: uplet, default None

each element in the tuple indicates if we should replace the 2x2 stride with a dilated convolution instead.

norm_layer: nn Module, default None

use the specified normalization module, by default use batch normalization.

class pynet.models.torchvisnet.ResNet101(num_classes, zero_init_residual=False, groups=1, width_per_group=64, replace_stride_with_dilation=None, norm_layer=None)
block = <MagicMock name='mock.resnet.Bottleneck' id='140325668611240'>
layers = [3, 4, 23, 3]
class pynet.models.torchvisnet.ResNet101Wide(num_classes, zero_init_residual=False, groups=1, width_per_group=64, replace_stride_with_dilation=None, norm_layer=None)
block = <MagicMock name='mock.resnet.Bottleneck' id='140325668611240'>
layers = [3, 4, 23, 3]
width_per_group = 128
class pynet.models.torchvisnet.ResNet101x32x8d(num_classes, zero_init_residual=False, groups=1, width_per_group=64, replace_stride_with_dilation=None, norm_layer=None)
block = <MagicMock name='mock.resnet.Bottleneck' id='140325668611240'>
groups = 32
layers = [3, 4, 23, 3]
width_per_group = 8
class pynet.models.torchvisnet.ResNet152(num_classes, zero_init_residual=False, groups=1, width_per_group=64, replace_stride_with_dilation=None, norm_layer=None)
block = <MagicMock name='mock.resnet.Bottleneck' id='140325668611240'>
layers = [3, 8, 36, 3]
class pynet.models.torchvisnet.ResNet18(num_classes, zero_init_residual=False, groups=1, width_per_group=64, replace_stride_with_dilation=None, norm_layer=None)
block = <MagicMock name='mock.resnet.BasicBlock' id='140325668540144'>
layers = [2, 2, 2, 2]
class pynet.models.torchvisnet.ResNet34(num_classes, zero_init_residual=False, groups=1, width_per_group=64, replace_stride_with_dilation=None, norm_layer=None)
block = <MagicMock name='mock.resnet.BasicBlock' id='140325668540144'>
layers = [3, 4, 6, 3]
class pynet.models.torchvisnet.ResNet50(num_classes, zero_init_residual=False, groups=1, width_per_group=64, replace_stride_with_dilation=None, norm_layer=None)
block = <MagicMock name='mock.resnet.Bottleneck' id='140325668611240'>
layers = [3, 4, 6, 3]
class pynet.models.torchvisnet.ResNet50Wide(num_classes, zero_init_residual=False, groups=1, width_per_group=64, replace_stride_with_dilation=None, norm_layer=None)
block = <MagicMock name='mock.resnet.Bottleneck' id='140325668611240'>
layers = [3, 4, 6, 3]
width_per_group = 128
class pynet.models.torchvisnet.ResNet50x32x4d(num_classes, zero_init_residual=False, groups=1, width_per_group=64, replace_stride_with_dilation=None, norm_layer=None)
block = <MagicMock name='mock.resnet.Bottleneck' id='140325668611240'>
groups = 32
layers = [3, 4, 6, 3]
width_per_group = 4
class pynet.models.torchvisnet.VGG(cfg, num_classes, batch_norm=False, init_weights=True, pretrained=None, make_layers=<MagicMock name='mock.vgg.make_layers' id='140325668569664'>)[source]

VGGNet (2014) by Simonyan and Zisserman.

__init__(cfg, num_classes, batch_norm=False, init_weights=True, pretrained=None, make_layers=<MagicMock name='mock.vgg.make_layers' id='140325668569664'>)[source]

Class initilization.

Parameters

cfg: list

the model features: output channels number for convolution or ‘M’ for max pooling.

num_classes: int

the number of classes to predict.

batch_norm: bool, default False

use batch normalization after each convolution.

init_weights: bool, default True

initialize the model weights.

pretrained: str, default None

update the weights of the model using this state information.

make_layers: @func

a function to create the feature layers: default 2d max pooling with kernel size 2 and stride 2, and convolution with kernel size 3 and padding 1.

class pynet.models.torchvisnet.VGG11(num_classes, batch_norm=False, init_weights=True)
cfg = [64, 'M', 128, 'M', 256, 256, 'M', 512, 512, 'M', 512, 512, 'M']
class pynet.models.torchvisnet.VGG13(num_classes, batch_norm=False, init_weights=True)
cfg = [64, 64, 'M', 128, 128, 'M', 256, 256, 'M', 512, 512, 'M', 512, 512, 'M']
class pynet.models.torchvisnet.VGG16(num_classes, batch_norm=False, init_weights=True)
cfg = [64, 64, 'M', 128, 128, 'M', 256, 256, 256, 'M', 512, 512, 512, 'M', 512, 512, 512, 'M']
class pynet.models.torchvisnet.VGG19(num_classes, batch_norm=False, init_weights=True)
cfg = [64, 64, 'M', 128, 128, 'M', 256, 256, 256, 256, 'M', 512, 512, 512, 512, 'M', 512, 512, 512, 512, 'M']
pynet.models.torchvisnet.class_factory(klass_name, klass_params, destination_module_globals)[source]

Dynamically overload a class.

In order to make the class publicly accessible, we assign the result of the function to a variable dynamically using globals().

Parameters

klass_name: str

the class name that will be created.

klass_params: dict

the class specific parameters.

Follow us

© 2019, pynet developers .
Inspired by AZMIND template.