tltorch.factorized_conv
.CPConv
-
class
tltorch.factorized_conv.
CPConv
(*args, **kwargs)[source] Create a Factorized CP convolution of arbitrary order.
Parameters: - in_channelsint
- out_channelsint
- kernel_sizeint or int list
if int, order MUST be specified if int list, then the conv will use order = len(kernel_size)
- rankint
rank of the factorized kernel
- orderint, optional if kernel_size is a list
see kernel_size
- implementation = {‘factorized’, ‘reconstructed’, ‘mobilenet’}
Strategy to use for the forward pass. Options are:
- factorized : the CP conv is expressed as a series of 1D convolutions
- reconstructedfull kernel is reconstructed from the decomposition.
- the reconstruction is used to perform a regular forward pass
- mobilenet : the equivalent formulation of CP as a MobileNet block is used
- strideint, default is 1
- paddingint, default is 0
- dilationint, default is 0
See also
TuckerConv
TTConvs
References
[1] Vadim Lebedev, Yaroslav Ganin, Maksim Rakhuba, Ivan V.Oseledets, and Victor S. Lempitsky. Speeding-up convolu-tional neural networks using fine-tuned cp-decomposition. InICLR, 2015. [2] Jean Kossaifi, Antoine Toisoul, Adrian Bulat, Yannis Panagakis, Timothy M. Hospedales, Maja Pantic; Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), 2020, pp. 6060-6069 Attributes: - kernel_shapeint tuple
shape of the kernel weight parametrizing the full convolution
- rankint
rank of the CP decomposition
Methods
get_decomposition
([return_bias])Returns a CP Tensor parametrizing the convolution init_from_decomposition
(cp_tensor[, bias])Transpose the factors from a CP Tensor to the factorized version init_from_random
([decompose_full_weight])Initialize the factorized convolution’s parameter randomly init_from_tensor
(kernel_tensor[, bias, …])Initialize the factorized convolutional layer from a full tensor transduct
(kernel_size[, mode, padding, stride])Transduction of the factorized convolution to add a new dimension -
init_from_random
(decompose_full_weight=True)[source] Initialize the factorized convolution’s parameter randomly
Parameters: - decompose_full_weightbool
If True, a full weight is randomly created and decomposed to intialize the parameters (slower) Otherwise, the parameters are initialized directly (faster) so the reconstruction has a set variance.
-
init_from_decomposition
(cp_tensor, bias=None)[source] Transpose the factors from a CP Tensor to the factorized version
Parameters: - factorscp_tensor
-
init_from_tensor
(kernel_tensor, bias=None, decomposition_kwargs={})[source] Initialize the factorized convolutional layer from a full tensor
-
get_decomposition
(return_bias=False)[source] Returns a CP Tensor parametrizing the convolution
Parameters: - return_biasbool, default is False
if True also return the bias
Returns: - weights, factors, bias
-
transduct
(kernel_size, mode=0, padding=0, stride=1)[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