thelper.nn package

Neural network and model package.

This package contains classes that define blocks and modules used in various neural network architectures. Most of these classes have been adapted from external sources; see their individual headers for more information.

Submodules

thelper.nn.common module

class thelper.nn.common.ConvBlock(input_size, output_size, kernel_size=4, stride=2, padding=1, bias=True, activation='relu', norm='batch', groups=1, prelu_params=1)[source]

Bases: sphinx.ext.autodoc.importer._MockObject

__init__(input_size, output_size, kernel_size=4, stride=2, padding=1, bias=True, activation='relu', norm='batch', groups=1, prelu_params=1)[source]

Initialize self. See help(type(self)) for accurate signature.

forward_act_bn(x)[source]
forward_bn_act(x)[source]
class thelper.nn.common.DeconvBlock(input_size, output_size, kernel_size=4, stride=2, padding=1, bias=True, activation='relu', norm='batch')[source]

Bases: sphinx.ext.autodoc.importer._MockObject

__init__(input_size, output_size, kernel_size=4, stride=2, padding=1, bias=True, activation='relu', norm='batch')[source]

Initialize self. See help(type(self)) for accurate signature.

forward(x)[source]
class thelper.nn.common.DenseBlock(input_size, output_size, bias=True, activation='relu', norm='batch')[source]

Bases: sphinx.ext.autodoc.importer._MockObject

__init__(input_size, output_size, bias=True, activation='relu', norm='batch')[source]

Initialize self. See help(type(self)) for accurate signature.

forward(x)[source]
class thelper.nn.common.PSBlock(input_size, output_size, scale_factor, kernel_size=3, stride=1, padding=1, bias=True, activation='relu', norm='batch')[source]

Bases: sphinx.ext.autodoc.importer._MockObject

__init__(input_size, output_size, scale_factor, kernel_size=3, stride=1, padding=1, bias=True, activation='relu', norm='batch')[source]

Initialize self. See help(type(self)) for accurate signature.

forward(x)[source]
class thelper.nn.common.ResNetBlock(num_filter, kernel_size=3, stride=1, padding=1, bias=True, activation='relu', norm='batch')[source]

Bases: sphinx.ext.autodoc.importer._MockObject

__init__(num_filter, kernel_size=3, stride=1, padding=1, bias=True, activation='relu', norm='batch')[source]

Initialize self. See help(type(self)) for accurate signature.

forward(x)[source]
class thelper.nn.common.Upsample2xBlock(input_size, output_size, bias=True, upsample='deconv', activation='relu', norm='batch')[source]

Bases: sphinx.ext.autodoc.importer._MockObject

__init__(input_size, output_size, bias=True, upsample='deconv', activation='relu', norm='batch')[source]

Initialize self. See help(type(self)) for accurate signature.

forward(x)[source]
thelper.nn.common.shave(imgs, border_size=0)[source]
thelper.nn.common.weights_init_kaiming(m)[source]
thelper.nn.common.weights_init_xavier(m)[source]

thelper.nn.coordconv module

class thelper.nn.coordconv.AddCoords(centered=True, normalized=True, noise=None, radius_channel=False, scale=None)[source]

Bases: sphinx.ext.autodoc.importer._MockObject

Creates a torch-compatible layer that adds intrinsic coordinate layers to input tensors.

__init__(centered=True, normalized=True, noise=None, radius_channel=False, scale=None)[source]

Initialize self. See help(type(self)) for accurate signature.

forward(in_tensor)[source]
class thelper.nn.coordconv.CoordConv2d(in_channels, *args, centered=True, normalized=True, noise=None, radius_channel=False, scale=None, **kwargs)[source]

Bases: sphinx.ext.autodoc.importer._MockObject

CoordConv-equivalent of torch’s default Conv2d model layer.

See also

Liu et al., An Intriguing Failing of Convolutional Neural Networks and the CoordConv Solution` <https://arxiv.org/abs/1807.03247>`_ [arXiv], 2018.
__init__(in_channels, *args, centered=True, normalized=True, noise=None, radius_channel=False, scale=None, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

forward(in_tensor)[source]
class thelper.nn.coordconv.CoordConvTranspose2d(in_channels, *args, centered=True, normalized=True, noise=None, radius_channel=False, scale=None, **kwargs)[source]

Bases: sphinx.ext.autodoc.importer._MockObject

CoordConv-equivalent of torch’s default ConvTranspose2d model layer.

See also

Liu et al., An Intriguing Failing of Convolutional Neural Networks and the CoordConv Solution` <https://arxiv.org/abs/1807.03247>`_ [arXiv], 2018.
__init__(in_channels, *args, centered=True, normalized=True, noise=None, radius_channel=False, scale=None, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

forward(in_tensor)[source]
thelper.nn.coordconv.get_coords_map(height, width, centered=True, normalized=True, noise=None, dtype=<sphinx.ext.autodoc.importer._MockObject object>)[source]

Returns a HxW intrinsic coordinates map tensor (shape=2xHxW).

thelper.nn.coordconv.make_conv2d(*args, coordconv=False, centered=True, normalized=True, noise=None, radius_channel=False, scale=None, **kwargs)[source]

Creates a 2D convolution layer with optional CoordConv support.

thelper.nn.coordconv.swap_coordconv_layers(module, centered=True, normalized=True, noise=None, radius_channel=False, scale=None)[source]

Modifies the provided module by swapping Conv2d layers for CoordConv-equivalent layers.

thelper.nn.densenet module

class thelper.nn.densenet.DenseNet(growth_rate=32, block_config=(6, 12, 24, 16), num_init_features=64, bn_size=4, drop_rate=0, num_classes=1000)[source]

Bases: sphinx.ext.autodoc.importer._MockObject

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) – how many layers in each pooling block
  • num_init_features (int) – the number of filters to learn in the first convolution layer
  • bn_size (int) – multiplicative factor for number of bottle neck layers (i.e. bn_size * k features in the bottleneck layer)
  • drop_rate (float) – dropout rate after each dense layer
  • num_classes (int) – number of classification classes
__init__(growth_rate=32, block_config=(6, 12, 24, 16), num_init_features=64, bn_size=4, drop_rate=0, num_classes=1000)[source]

Initialize self. See help(type(self)) for accurate signature.

forward(x)[source]
thelper.nn.densenet.densenet121(pretrained=False, **kwargs)[source]

Densenet-121 model from “Densely Connected Convolutional Networks”

Parameters:pretrained (bool) – If True, returns a model pre-trained on ImageNet
thelper.nn.densenet.densenet169(pretrained=False, **kwargs)[source]

Densenet-169 model from “Densely Connected Convolutional Networks”

Parameters:pretrained (bool) – If True, returns a model pre-trained on ImageNet
thelper.nn.densenet.densenet201(pretrained=False, **kwargs)[source]

Densenet-201 model from “Densely Connected Convolutional Networks”

Parameters:pretrained (bool) – If True, returns a model pre-trained on ImageNet
thelper.nn.densenet.densenet161(pretrained=False, **kwargs)[source]

Densenet-161 model from “Densely Connected Convolutional Networks”

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

thelper.nn.efficientnet module

class thelper.nn.efficientnet.EfficientNet(task, num, pretrained=False)[source]

Bases: thelper.nn.utils.Module

__init__(task, num, pretrained=False)[source]

Receives a task object to hold internally for model specialization.

forward(x)[source]

Transforms an input tensor in order to generate a prediction.

set_task(task)[source]

Adapts the model to support a new task, replacing layers if needed.

class thelper.nn.efficientnet.FCEfficientNet(task, ckptdata, map_location='cpu', avgpool_size=0)[source]

Bases: thelper.nn.efficientnet.EfficientNet

__init__(task, ckptdata, map_location='cpu', avgpool_size=0)[source]

Receives a task object to hold internally for model specialization.

forward(x)[source]

Transforms an input tensor in order to generate a prediction.

set_task(task)[source]

Adapts the model to support a new task, replacing layers if needed.

thelper.nn.fcn module

class thelper.nn.fcn.FCN32s(task, init_vgg16=True)[source]

Bases: thelper.nn.utils.Module

__init__(task, init_vgg16=True)[source]

Receives a task object to hold internally for model specialization.

forward(x)[source]

Transforms an input tensor in order to generate a prediction.

init_vgg16_params(vgg16, copy_fc8=True)[source]
set_task(task)[source]

Adapts the model to support a new task, replacing layers if needed.

thelper.nn.fcn.get_upsampling_weight(in_channels, out_channels, kernel_size)[source]

thelper.nn.inceptionresnetv2 module

class thelper.nn.inceptionresnetv2.BasicConv2d(in_planes, out_planes, kernel_size, stride, padding=0)[source]

Bases: sphinx.ext.autodoc.importer._MockObject

__init__(in_planes, out_planes, kernel_size, stride, padding=0)[source]

Initialize self. See help(type(self)) for accurate signature.

forward(x)[source]
class thelper.nn.inceptionresnetv2.Block17(scale=1.0)[source]

Bases: sphinx.ext.autodoc.importer._MockObject

__init__(scale=1.0)[source]

Initialize self. See help(type(self)) for accurate signature.

forward(x)[source]
class thelper.nn.inceptionresnetv2.Block35(scale=1.0)[source]

Bases: sphinx.ext.autodoc.importer._MockObject

__init__(scale=1.0)[source]

Initialize self. See help(type(self)) for accurate signature.

forward(x)[source]
class thelper.nn.inceptionresnetv2.Block8(scale=1.0, noReLU=False)[source]

Bases: sphinx.ext.autodoc.importer._MockObject

__init__(scale=1.0, noReLU=False)[source]

Initialize self. See help(type(self)) for accurate signature.

forward(x)[source]
class thelper.nn.inceptionresnetv2.InceptionResNetV2(task, input_channels=3)[source]

Bases: thelper.nn.utils.Module

__init__(task, input_channels=3)[source]

Receives a task object to hold internally for model specialization.

features(input)[source]
forward(input)[source]

Transforms an input tensor in order to generate a prediction.

logits(features)[source]
set_task(task)[source]

Adapts the model to support a new task, replacing layers if needed.

class thelper.nn.inceptionresnetv2.Mixed_5b[source]

Bases: sphinx.ext.autodoc.importer._MockObject

__init__()[source]

Initialize self. See help(type(self)) for accurate signature.

forward(x)[source]
class thelper.nn.inceptionresnetv2.Mixed_6a[source]

Bases: sphinx.ext.autodoc.importer._MockObject

__init__()[source]

Initialize self. See help(type(self)) for accurate signature.

forward(x)[source]
class thelper.nn.inceptionresnetv2.Mixed_7a[source]

Bases: sphinx.ext.autodoc.importer._MockObject

__init__()[source]

Initialize self. See help(type(self)) for accurate signature.

forward(x)[source]

thelper.nn.lenet module

class thelper.nn.lenet.LeNet(task, input_shape=(1, 28, 28), conv1_filters=6, conv2_filters=16, hidden1_size=120, hidden2_size=84, output_size=10)[source]

Bases: thelper.nn.utils.Module

LeNet CNN implementation.

See http://yann.lecun.com/exdb/lenet/ for more information.

This is NOT a modern architecture; it is only provided here for tutorial purposes.

__init__(task, input_shape=(1, 28, 28), conv1_filters=6, conv2_filters=16, hidden1_size=120, hidden2_size=84, output_size=10)[source]

Receives a task object to hold internally for model specialization.

forward(x)[source]

Transforms an input tensor in order to generate a prediction.

set_task(task)[source]

Adapts the model to support a new task, replacing layers if needed.

thelper.nn.mobilenet module

class thelper.nn.mobilenet.InvertedResidual(inp, oup, stride, expand_ratio)[source]

Bases: sphinx.ext.autodoc.importer._MockObject

__init__(inp, oup, stride, expand_ratio)[source]

Initialize self. See help(type(self)) for accurate signature.

forward(x)[source]
class thelper.nn.mobilenet.MobileNetV2(task, input_size=224, width_mult=1.0)[source]

Bases: thelper.nn.utils.Module

__init__(task, input_size=224, width_mult=1.0)[source]

Receives a task object to hold internally for model specialization.

forward(x)[source]

Transforms an input tensor in order to generate a prediction.

set_task(task)[source]

Adapts the model to support a new task, replacing layers if needed.

thelper.nn.mobilenet.conv_1x1_bn(inp, oup)[source]
thelper.nn.mobilenet.conv_bn(inp, oup, stride)[source]

thelper.nn.resnet module

class thelper.nn.resnet.AutoEncoderResNet(task, output_pads=None, **kwargs)[source]

Bases: thelper.nn.resnet.ResNet

Autoencoder-classifier architecture based on ResNet blocks+layers configurations.

__init__(task, output_pads=None, **kwargs)[source]

Receives a task object to hold internally for model specialization.

forward(input)[source]

Transforms an input tensor in order to generate a prediction.

class thelper.nn.resnet.AutoEncoderSkipResNet(task, output_pads=None, decoder_dropout=False, dropout_prob=0.1, **kwargs)[source]

Bases: thelper.nn.resnet.ResNet

Autoencoder-U-Net architecture based on ResNet blocks+layers configurations.

__init__(task, output_pads=None, decoder_dropout=False, dropout_prob=0.1, **kwargs)[source]

Receives a task object to hold internally for model specialization.

forward(input)[source]

Transforms an input tensor in order to generate a prediction.

class thelper.nn.resnet.BasicBlock(inplanes, planes, stride=1, downsample=None, coordconv=False, radius_channel=True, activation='relu')[source]

Bases: thelper.nn.resnet.Module

__init__(inplanes, planes, stride=1, downsample=None, coordconv=False, radius_channel=True, activation='relu')[source]

Initialize self. See help(type(self)) for accurate signature.

forward(x)[source]
class thelper.nn.resnet.Bottleneck(inplanes, planes, stride=1, downsample=None, coordconv=False, radius_channel=True, activation='relu')[source]

Bases: thelper.nn.resnet.Module

__init__(inplanes, planes, stride=1, downsample=None, coordconv=False, radius_channel=True, activation='relu')[source]

Initialize self. See help(type(self)) for accurate signature.

expansion = 4
forward(x)[source]
class thelper.nn.resnet.ConvTailNet(n_inputs, num_classes)[source]

Bases: sphinx.ext.autodoc.importer._MockObject

DEPRECATED. Will be removed in a future version.

__init__(n_inputs, num_classes)[source]

Initialize self. See help(type(self)) for accurate signature.

forward(x)[source]
class thelper.nn.resnet.FCResNet(task, ckptdata, map_location='cpu', avgpool_size=0)[source]

Bases: thelper.nn.resnet.ResNet

Fully Convolutional ResNet converter for pre-trained classification models.

__init__(task, ckptdata, map_location='cpu', avgpool_size=0)[source]

Receives a task object to hold internally for model specialization.

forward(x)[source]

Transforms an input tensor in order to generate a prediction.

set_task(task)[source]

Adapts the model to support a new task, replacing layers if needed.

class thelper.nn.resnet.FakeModule(*args, **kwargs)[source]

Bases: sphinx.ext.autodoc.importer._MockObject

forward(inputs)[source]
class thelper.nn.resnet.Module(inplanes, planes, stride=1, downsample=None, coordconv=False, radius_channel=True)[source]

Bases: sphinx.ext.autodoc.importer._MockObject

__init__(inplanes, planes, stride=1, downsample=None, coordconv=False, radius_channel=True)[source]

Initialize self. See help(type(self)) for accurate signature.

expansion = 1
class thelper.nn.resnet.ResNet(task, block='thelper.nn.resnet.BasicBlock', layers=[3, 4, 6, 3], strides=[1, 2, 2, 2], input_channels=3, flexible_input_res=False, pool_size=7, head_type=None, coordconv=False, radius_channel=True, activation='relu', skip_max_pool=False, pretrained=False, conv1_config=[7, 2, 3])[source]

Bases: thelper.nn.utils.Module

__init__(task, block='thelper.nn.resnet.BasicBlock', layers=[3, 4, 6, 3], strides=[1, 2, 2, 2], input_channels=3, flexible_input_res=False, pool_size=7, head_type=None, coordconv=False, radius_channel=True, activation='relu', skip_max_pool=False, pretrained=False, conv1_config=[7, 2, 3])[source]

Receives a task object to hold internally for model specialization.

forward(x)[source]

Transforms an input tensor in order to generate a prediction.

get_embedding(x, pool=True)[source]
set_task(task)[source]

Adapts the model to support a new task, replacing layers if needed.

class thelper.nn.resnet.ResNetFullyConv(task, block='thelper.nn.resnet.BasicBlock', layers=[3, 4, 6, 3], strides=[1, 2, 2, 2], input_channels=3, flexible_input_res=False, pool_size=7, coordconv=False, radius_channel=True, pretrained=False)[source]

Bases: thelper.nn.resnet.ResNet

DEPRECATED. Will be removed in a future version. Use the torchvision segmentation models or the ResNet above instead.

__init__(task, block='thelper.nn.resnet.BasicBlock', layers=[3, 4, 6, 3], strides=[1, 2, 2, 2], input_channels=3, flexible_input_res=False, pool_size=7, coordconv=False, radius_channel=True, pretrained=False)[source]

Receives a task object to hold internally for model specialization.

forward(x)[source]

Transforms an input tensor in order to generate a prediction.

set_task(task)[source]

Adapts the model to support a new task, replacing layers if needed.

class thelper.nn.resnet.SqueezeExcitationBlock(inplanes, planes, stride=1, downsample=None, reduction=16, coordconv=False, radius_channel=True, activation='relu')[source]

Bases: thelper.nn.resnet.Module

__init__(inplanes, planes, stride=1, downsample=None, reduction=16, coordconv=False, radius_channel=True, activation='relu')[source]

Initialize self. See help(type(self)) for accurate signature.

forward(x)[source]
class thelper.nn.resnet.SqueezeExcitationLayer(channel, reduction=16, activation='relu')[source]

Bases: sphinx.ext.autodoc.importer._MockObject

__init__(channel, reduction=16, activation='relu')[source]

Initialize self. See help(type(self)) for accurate signature.

forward(x)[source]
thelper.nn.resnet.get_activation_layer(name: AnyStr) → <sphinx.ext.autodoc.importer._MockObject object at 0x7f0c80a6e278>[source]

thelper.nn.srm module

class thelper.nn.srm.SRMWrapper(base_model: <sphinx.ext.autodoc.importer._MockObject object at 0x7f0c81825940>, input_channels: int = 3)[source]

Bases: sphinx.ext.autodoc.importer._MockObject

Wraps a base model for Steganalysis Rich Model (SRM)-based noise analysis.

__init__(base_model: <sphinx.ext.autodoc.importer._MockObject object at 0x7f0c81825940>, input_channels: int = 3)[source]

Creates a SRM analysis layer and prepares internal params.

forward(img: <sphinx.ext.autodoc.importer._MockObject object at 0x7f0c81825a90>) → <sphinx.ext.autodoc.importer._MockObject object at 0x7f0c81825518>[source]

Adds a stack of noise channels to the input tensor, and processes it using the base model.

thelper.nn.srm.setup_srm_layer(input_channels: int = 3) → <sphinx.ext.autodoc.importer._MockObject object at 0x7f0c81825da0>[source]

Creates a SRM convolution layer for noise analysis.

thelper.nn.srm.setup_srm_weights(input_channels: int = 3) → <sphinx.ext.autodoc.importer._MockObject object at 0x7f0c818255f8>[source]

Creates the SRM kernels for noise analysis.

thelper.nn.unet module

class thelper.nn.unet.BasicBlock(in_channels, out_channels, coordconv=False, kernel_size=3, padding=1)[source]

Bases: sphinx.ext.autodoc.importer._MockObject

Default (double-conv) block used in U-Net layers.

__init__(in_channels, out_channels, coordconv=False, kernel_size=3, padding=1)[source]

Initialize self. See help(type(self)) for accurate signature.

forward(x)[source]
class thelper.nn.unet.UNet(task, in_channels=3, mid_channels=512, coordconv=False, srm=False)[source]

Bases: thelper.nn.utils.Module

U-Net implementation. Not identical to the original.

This version includes batchnorm and transposed conv2d layers for upsampling. Coordinate Convolutions (CoordConv) can also be toggled on if requested (see thelper.nn.coordconv for more information).

__init__(task, in_channels=3, mid_channels=512, coordconv=False, srm=False)[source]

Receives a task object to hold internally for model specialization.

forward(x)[source]

Transforms an input tensor in order to generate a prediction.

set_task(task)[source]

Adapts the model to support a new task, replacing layers if needed.

thelper.nn.utils module

Neural network utility functions and classes.

This module contains base interfaces and utility functions used to define and instantiate neural network models.

class thelper.nn.utils.ExternalClassifModule(model_type, task, **kwargs)[source]

Bases: thelper.nn.utils.ExternalModule

External model interface specialization for classification tasks.

This interface will try to ‘rewire’ the last fully connected layer of the models it instantiates to match the number of classes to predict defined in the task object.

__init__(model_type, task, **kwargs)[source]

Receives a task object to hold internally for model specialization, and tries to rewire the last ‘fc’ layer.

set_task(task)[source]

Rewires the last fully connected layer of the wrapped network to fit the given number of classification targets.

class thelper.nn.utils.ExternalDetectModule(model_type, task, **kwargs)[source]

Bases: thelper.nn.utils.ExternalModule

External model interface specialization for object detection tasks.

This interface will try to ‘rewire’ the last fully connected layer of the models it instantiates to match the number of classes to predict defined in the task object.

__init__(model_type, task, **kwargs)[source]

Receives a task object to hold internally for model specialization, and tries to rewire the last ‘fc’ layer.

set_task(task)[source]

Rewires the last fully connected layer of the wrapped network to fit the given number of classification targets.

class thelper.nn.utils.ExternalModule(model_type, task, **kwargs)[source]

Bases: thelper.nn.utils.Module

Model inteface used to hold a task object for an external implementation.

This interface is built on top of torch.nn.Module and should remain fully compatible with it. It is automatically used when instantiating a model via thelper.nn.utils.create_model() that is not derived from thelper.nn.utils.Module. Its only purpose is to hold the task object, and redirect thelper.nn.utils.Module.forward() to the actual model’s transformation function. It can also be specialized to automatically adapt some external models after their construction using the knowledge contained in the task object.

__init__(model_type, task, **kwargs)[source]

Receives a task object to hold internally for model specialization.

forward(*input, **kwargs)[source]

Transforms an input tensor in order to generate a prediction.

get_name()[source]

Returns the name of this module (by default, the fully qualified class name of the external model).

load_state_dict(state_dict, strict=True)[source]

Loads the state dict of an external model.

set_task(task)[source]

Stores the new task internally.

Note that since this external module handler is generic, it does not know what to do with the task, so it just assumes that the model is already set up. Specialized external module handlers will instead attempt to modify the model they wrap.

state_dict(destination=None, prefix='', keep_vars=False)[source]

Returns the state dict of the external model.

summary()[source]

Prints a summary of the model using the thelper.nn logger.

class thelper.nn.utils.Module(task, **kwargs)[source]

Bases: sphinx.ext.autodoc.importer._MockObject

Model interface used to hold a task object.

This interface is built on top of torch.nn.Module and should remain fully compatible with it.

All models used in the framework should derive from this interface, and therefore expect a task object as the first argument of their constructor. Their implementation may decide to ignore this task object when building their internal layers, but using it should help specialize the network by specifying e.g. the number of classes to support.

__init__(task, **kwargs)[source]

Receives a task object to hold internally for model specialization.

forward(*input)[source]

Transforms an input tensor in order to generate a prediction.

get_name()[source]

Returns the name of this module (by default, its fully qualified class name).

set_task(task)[source]

Adapts the model to support a new task, replacing layers if needed.

summary()[source]

Prints a summary of the model using the thelper.nn logger.

thelper.nn.utils.create_model(config, task, save_dir=None, ckptdata=None)[source]

Instantiates a model based on a provided task object.

The configuration must be given as a dictionary object. This dictionary will be parsed for a ‘model’ field. This field is expected to be a dictionary itself. It may then specify a type to instantiate as well as the parameters to provide to that class constructor, or a path to a checkpoint from which a model should be loaded.

All models must derive from thelper.nn.utils.Module, or they must be instantiable through thelper.nn.utils.ExternalModule (or one of its specialized classes). The provided task object will be used to make sure that the model has the required input/output layers for the requested objective.

If checkpoint data is provided by the caller, the weights it contains will be loaded into the returned model.

Usage examples inside a session configuration file:

# ...
# the function will look for a 'model' field in the provided config dict
"model": {
    # the type provides the class name to instantiate an object from
    "type": "thelper.nn.mobilenet.MobileNetV2",
    # the parameters listed below are passed to the model's constructor
    "params": {
        # ...
    }
# ...
Parameters:
  • config – a session dictionary that provides a ‘model’ field containing a dictionary.
  • task – a task object that will be passed to the model’s constructor in order to specialize it. Can be None if a checkpoint is provided, and if the previous task is wanted instead of a new one.
  • save_dir – if not None, a log file containing model information will be created there.
  • ckptdata – raw checkpoint data loaded via torch.load(); the model will be given its previous state.
Returns:

The instantiated model, compatible with the interface of both thelper.nn.utils.Module and torch.nn.Module.

thelper.nn.utils.get_learnable_param_count(model: <sphinx.ext.autodoc.importer._MockObject object at 0x7f0c80db4898>) → int[source]

Returns the learnable (grad-enabled) parameter count in a module.