tltorch.factorized_layers.FactorizedConv

class tltorch.factorized_layers.FactorizedConv(in_channels, out_channels, kernel_size, order=None, stride=1, padding=0, dilation=1, bias=False, has_bias=False, n_layers=1, factorization='cp', rank='same', implementation='factorized', fixed_rank_modes=None)[source]

Create a factorized convolution of arbitrary order

Methods

extra_repr()

Set the extra representation of the module

forward(x[, indices])

Defines the computation performed at every call.

from_conv(conv_layer[, rank, …])

Create a Factorized convolution from a regular convolutional layer

get_conv(indices)

Returns a sub-convolutional layer from the joint parametrize main-convolution

set(indices[, stride, padding, dilation, bias])

Sets the parameters of the conv self[indices]

transduct(kernel_size[, mode, padding, …])

Transduction of the factorized convolution to add a new dimension

from_conv_list

from_factorization

forward(x, indices=0)[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.

set(indices, stride=1, padding=0, dilation=1, bias=None)[source]

Sets the parameters of the conv self[indices]

get_conv(indices)[source]

Returns a sub-convolutional layer from the joint parametrize main-convolution

The parametrization of sub-convolutional layers is shared with the main one.

classmethod from_conv(conv_layer, rank='same', implementation='reconstructed', factorization='CP', decompose_weights=True, decomposition_kwargs={}, fixed_rank_modes=None, **kwargs)[source]

Create a Factorized convolution from a regular convolutional layer

Parameters
conv_layertorch.nn.ConvND
rankrank of the decomposition, default is ‘same’
implementationstr, default is ‘reconstructed’
decomposed_weightsbool, default is True

if True, the convolutional kernel is decomposed to initialize the factorized convolution otherwise, the factorized convolution’s parameters are initialized randomly

decomposition_kwargsdict

parameters passed directly on to the decompoosition function if decomposed_weights is True

Returns
New instance of the factorized convolution with equivalent weightss
transduct(kernel_size, mode=0, padding=0, stride=1, dilation=1, fine_tune_transduction_only=True)[source]

Transduction of the factorized convolution to add a new dimension

Parameters
kernel_sizeint

size of the additional dimension

modewhere to insert the new dimension, after the channels, default is 0

by default, insert the new dimensions before the existing ones (e.g. add time before height and width)

paddingint, default is 0
strideint: default is 1
Returns
self
extra_repr()[source]

Set the extra representation of the module

To print customized extra information, you should re-implement this method in your own modules. Both single-line and multi-line strings are acceptable.