nn.modules package¶
nn.modules.actNorm module¶
-
class
nn.modules.actNorm.ActNorm(in_features, return_logdet=True, data_init=False)¶ Bases:
torch.nn.modules.module.ModuleActivation Normalization layer found in the Glow paper This was proposed to be used instead of batch-norm due to potentially low batch-sizes. Applies ‘normalization’ to each channel independently.
- Parameters
in_features (int) – Number of input feature channels, this is the dimension of w and b
return_logdet (bool, optional) – Return the log determinate, defaults to True
data_init (bool, optional) – if weight and bias terms have already been initialized, defaults to False
-
forward(x)¶ Forward pass of normalization layer \(w*x + b\).
- Parameters
x (torch.Tensor) – [B, C, H, W] normed mini-batch tensor of data
- Returns
y: [B, C, H, W] un-normed tensor
logdet: log determinate of normalization, optional
- Return type
(torch.Tensor, torch.Tensor)
-
reverse(y)¶ Backward pass of normalization layer \((x - b)/w\).
- Parameters
y – [B, C, H, W] un-normed mini-batch tensor of data
- Returns
x: [B, C, H, W] normed tensor
logdet: log determinate of normalization, optional
- Return type
(torch.Tensor, torch.Tensor)
-
training: bool¶
nn.modules.convLSTM module¶
-
class
nn.modules.convLSTM.ConvLSTMCell(input_dim, hidden_dim, kernel_size, bias=True)¶ Bases:
torch.nn.modules.module.ModuleConvolutional LSTM from the paper “Convolutional LSTM Network: A Machine Learning Approach for Precipitation Nowcasting” by Shi et al.
- Parameters
input_dim (int) – Number of channels of input tensor
hidden_dim (int) – Number of channels of hidden state
kernel_size (tuple) – Size of the convolutional kernel, e.g. (3, 3)
bias (bool, optional) – Use a bias term, defaults to True
- Note
Implementation base is based on https://github.com/ndrplz/ConvLSTM_pytorch
-
forward(input_tensor, cur_state)¶ Forward pass of LSTM cell
- Parameters
input_tensor (torch.Tensor) – [B, C, H, W] input feature tensor to the LSTM
cur_state (tuple) – tuple of LSTM states (hidden state, cell state)
- Returns
h_next: [B, hidden_dim, H, W] Output hidden state of the LSTM cell
c_next: [B, hidden_dim, H, W] Output cell state of the LSTM cell
- Return type
(torch.Tensor, torch.Tensor)
Default initialization for lstm cell and hidden state if none are provide. Both are initialized to zero arrays.
- Parameters
input_tensor (torch.tensor) – input feature to the LSTM
- Returns
h_cur: Hidden state of the LSTM cell
c_cur: Cell state of the LSTM cell
- Return type
(torch.Tensor, torch.Tensor)
-
training: bool¶
-
class
nn.modules.convLSTM.ResidLSTMBlock(input_dim, hidden_dim, output_dim, kernel_size, bias=True)¶ Bases:
torch.nn.modules.module.ModuleConvolutional LSTM Cell,
nn.modules.convLSTM.ConvLSTMCell, with a residual connection- Parameters
input_dim (int) – Number of channels of input tensor
hidden_dim (int) – Number of channels of hidden state
output_dim (int) – Number of channels of the output of the residual LSTM block
kernel_size (tuple) – Size of the convolutional kernel, e.g. (3, 3)
bias (bool, optional) – Use a bias term, defaults to True
-
forward(input_tensor, cur_state=None)¶ Forward pass
- Parameters
input_tensor (torch.Tensor) – [B, C, H, W] input feature tensor to the LSTM
cur_state (tuple, optional) – tuple of LSTM states (hidden state, cell state), defaults to None
- Returns
out: [B, output_dim, H, W] Output of residual connection
h_next: [B, hidden_dim, H, W] Output hidden state of the LSTM cell
c_next: [B, hidden_dim, H, W] Output cell state of the LSTM cell
- Return type
(torch.Tensor, torch.Tensor, torch.Tensor)
-
training: bool¶
nn.modules.denseBlock module¶
-
class
nn.modules.denseBlock.DenseBlock(num_layers, in_features, growth_rate, drop_rate, bn_size=4, bottleneck=False)¶ Bases:
torch.nn.modules.container.SequentialDense block with bottleneck design See Fig. 9 of paper: https://arxiv.org/abs/2006.04731
- Parameters
num_layers (int) – Number of dense layers in block
in_features (int) – Number of input feature channels
growth_rate (int) – Growth rate of channels in dense block
drop_rate (float, optional) – Dropout rate, defaults to 0.
bn_size (int, optional) – Number of features after bottleneck if enabled, defaults to 8
bottleneck (bool, optional) – Enable bottle next to reduce the number of feature channels, defaults to False
padding (int, optional) – Convolutional padding, defaults to 1
- Note
For additional information on dense blocks see “Densely Connected Convolutional Networks” by Huang et al. https://arxiv.org/abs/1608.06993v5
-
training: bool¶
-
class
nn.modules.denseBlock.NoNormDenseBlock(num_layers, in_features, growth_rate, drop_rate, bn_size=4, bottleneck=False)¶ Bases:
torch.nn.modules.container.SequentialDense block with bottleneck design and no batch-normalization See Fig. 9 of paper: https://arxiv.org/abs/2006.04731
- Parameters
num_layers (int) – Number of dense layers in block
in_features (int) – Number of input feature channels
growth_rate (int) – Growth rate of channels in dense block
drop_rate (float, optional) – dropout rate, defaults to 0.
bn_size (int, optional) – number of features after bottleneck if enabled, defaults to 8
bottleneck (bool, optional) – enable bottle next to reduce the number of feature channels, defaults to False
padding (int, optional) – convolutional padding, defaults to 1
- Note
For additional information on dense blocks see “Densely Connected Convolutional Networks” by Huang et al. https://arxiv.org/abs/1608.06993v5
-
training: bool¶
nn.modules.flowAffine module¶
-
class
nn.modules.flowAffine.AffineCouplingLayer(in_features, cond_features)¶ Bases:
torch.nn.modules.module.ModuleConditional invertable affine coupling layer. See Fig. 7 of paper: https://arxiv.org/abs/2006.04731
- Parameters
in_features (int) – Number of input feature channels
cond_features (int) – Number of conditional feature channels
- Note
For more information see “NICE: Non-linear Independent Components Estimation” by Dihn et al. https://arxiv.org/abs/1410.8516
- Note
Check Feistel cipher as this functions very similarly.
-
forward(x, cond)¶ Forward pass
- Parameters
x (torch.Tensor) – [B, in_features, H, W] input feature tensor
cond (torch.Tensor) – [B, cond_features, H, W] input feature tensor
- Returns
y: [B, in_features, H, W] Output feature tensor
logdet: log determinate of affine layer
- Return type
(torch.Tensor, torch.Tensor)
-
reverse(y, cond)¶ Backward pass
- Parameters
y (torch.Tensor) – [B, in_features, H, W] input feature tensor
cond (torch.Tensor) – [B, cond_features, H, W] input feature tensor
- Returns
x: [B, in_features, H, W] Output feature tensor
logdet: log determinate of affine layer
- Return type
(torch.Tensor, torch.Tensor)
-
training: bool¶
-
class
nn.modules.flowAffine.LSTMAffineCouplingLayer(in_features, cond_features, rec_features)¶ Bases:
torch.nn.modules.module.ModuleConditional LSTM invertable affine coupling layer. See Fig. 7 of paper: https://arxiv.org/abs/2006.04731
- Parameters
in_features (int) – Number of input feature channels
cond_features (int) – Number of conditional feature channels
rec_features (int) – Number of recurrent feature channels, output from
nn.modules.convLSTM.ResidLSTMBlock
- Note
For more information see “NICE: Non-linear Independent Components Estimation” by Dihn et al. https://arxiv.org/abs/1410.8516
- Note
Check Feistel cipher as this functions very similarly.
-
forward(x, cond, rec_states=None)¶ Forward pass
- Parameters
x (torch.Tensor) – [B, in_features, H, W] input feature tensor
cond (torch.Tensor) – [B, cond_features, H, W] input feature tensor
rec_states (tuple, optional) – tuple of LSTM states (hidden state, cell state), defaults to None
- Returns
y: [B, in_features, H, W] Output feature tensor
logdet: log determinate of affine layer
states_out: tuple of LSTM (cell, hidden) states
- Return type
(torch.Tensor, torch.Tensor, tuple)
-
reverse(y, cond, rec_states=None)¶ Backward pass
- Parameters
y (torch.Tensor) – [B, in_features, H, W] input feature tensor
cond (torch.Tensor) – [B, in_features, H, W] input feature tensor
rec_states (tuple, optional) – tuple of LSTM states (hidden state, cell state), defaults to None
- Returns
x: [B, in_features, H, W] Output feature tensor
logdet: log determinate of affine layer
states_out: tuple of LSTM (cell, hidden) states
- Return type
(torch.Tensor, torch.Tensor, tuple)
-
training: bool¶
nn.modules.flowLSTMBlock module¶
-
class
nn.modules.flowLSTMBlock.AffineCouplingBlock(in_features, cond_features, train_sampling=True, LUdecompose=False)¶ Bases:
torch.nn.modules.module.ModuleAn invertible affine coupling block consisting of an activation normalization, conditional affine coupling layer and a 1x1 convolution. See Fig. 6 of paper: https://arxiv.org/abs/2006.04731
- Parameters
in_features (int) – Number of input feature channels
cond_features (int) – Number of conditional feature channels
train_sampling (bool, optional) – train by sampling (1x1 conv. is inverted for the forward pass), defaults to True
LUdecompose (bool, optional) – Use the LU decomposition for 1x1 convolution, defaults to False
-
forward(x, cond)¶ Forward pass
- Parameters
x (torch.Tensor) – [B, in_features, H, W] input feature tensor
cond (torch.Tensor) – [B, cond_features, H, W] conditional feature tensor
- Returns
y: [B, in_features, H, W] Output feature tensor
logdet: log determinate of affine block
- Return type
(torch.Tensor, torch.Tensor)
-
reverse(y, cond)¶ Backward pass
- Parameters
y (torch.Tensor) – [B, in_features, H, W] input feature tensor
cond (torch.Tensor) – [B, cond_features, H, W] conditional feature tensor
- Returns
x: [B, in_features, H, W] Output feature tensor
logdet: log determinate of affine block
- Return type
(torch.Tensor, torch.Tensor)
-
training: bool¶
-
class
nn.modules.flowLSTMBlock.LSTMCouplingBlock(in_features, cond_features, rec_features, train_sampling=True, LUdecompose=False)¶ Bases:
torch.nn.modules.module.ModuleAn LSTM invertible affine coupling block consisting of an activation normalization, lstm affine coupling layer and a 1x1 convolution. See Fig. 6 of paper: https://arxiv.org/abs/2006.04731
- Parameters
in_features (int) – Number of input feature channels
cond_features (int) – Number of conditional feature channels
rec_features (int) – Number of recurrent feature channels in
nn.modules.convLSTM.LSTMAffineCouplingLayertrain_sampling (bool, optional) – train by sampling (1x1 conv. is inverted for the forward pass), defaults to True
LUdecompose (bool, optional) – Use the LU decomposition for 1x1 convolution, defaults to False
-
forward(x, cond, rec_states=None)¶ Forward pass
- Parameters
x (torch.Tensor) – [B, in_features, H, W] input feature tensor
cond (torch.Tensor) – [B, cond_features, H, W] conditional feature tensor
rec_states (tuple, optional) – tuple of LSTM states (hidden state, cell state), defaults to None
- Returns
y: [B, in_features, H, W] Output feature tensor
logdet: log determinate of affine block
states_out: tuple of LSTM (cell, hidden) states
- Return type
(torch.Tensor, torch.Tensor, tuple)
-
reverse(y, cond, rec_states=None)¶ Backward pass
- Parameters
y (torch.Tensor) – [B, in_features, H, W] input feature tensor
cond (torch.Tensor) – [B, cond_features, H, W] conditional feature tensor
rec_states (tuple, optional) – tuple of LSTM states (hidden state, cell state), defaults to None
- Returns
x: [B, in_features, H, W] Output feature tensor
logdet: log determinate of affine block
states_out: tuple of LSTM (cell, hidden) states
- Return type
(torch.Tensor, torch.Tensor, tuple)
-
training: bool¶
-
class
nn.modules.flowLSTMBlock.LSTMFLowBlock(in_features, cond_features, rec_features, n_layers, factor=2, LUdecompose=True, train_sampling=False, do_split=True, squeeze_type=0)¶ Bases:
torch.nn.modules.module.ModuleLSTM Conditional Flow block considting of an a stack of invertible affine layers. See Fig. 6 of paper: https://arxiv.org/abs/2006.04731
- Parameters
in_features (int) – Number of input feature channels
cond_features (int) – Number of conditional feature channels
rec_features (int) – Number of recurrent feature channels in LSTM
n_layers (int) – Number of affine layers in block
factor (int, optional) – Squeeze factor to reduce the dimensionality of the feature map, defaults to 2
train_sampling (bool, optional) – Train by sampling (1x1 conv. is inverted for the forward pass), defaults to True
LUdecompose (bool, optional) – Use the LU decomposition for 1x1 convolution, defaults to False
do_split (bool, optional) – Perform a split at the end of block, defaults to True. Refer to
nn.modules.flowUtils.Splitsqueeze_type (int, optional) – Type of squeeze method; 0 =
nn.modules.flowUtils.CheckerSqueeze, 1 =nn.modules.flowUtils.Squeeze, defaults to 0
-
forward(x, cond, rec_states, return_eps=False)¶ Forward pass
- Parameters
x (torch.Tensor) – [B, in_features, H, W] input feature tensor
cond (torch.Tensor) – [B, cond_features, H, W] conditional feature tensor
rec_states (tuple, optional) – tuple of LSTM states (hidden state, cell state), defaults to None
return_eps (bool, optional) – Return samples from latent densities, defaults to False
- Returns
y: [B, in_features, H, W] Output feature tensor
logdet: [B] log determinate of block + the log-likelihood of the latent variables
out_states: tuple of LSTM (cell, hidden) states
eps: [B, 2*in_features, H//2, W//2] (for factor=2) tensor of sampled latent variables from unit gaussian
- Return type
(torch.Tensor, torch.Tensor, tuple, torch.Tensor)
-
reverse(y, cond, rec_states, eps=None)¶ Backward pass
- Parameters
y (torch.Tensor) – [B, in_features, H, W] input feature tensor
cond (torch.Tensor) – [B, cond_features, H, W] conditional feature tensor
rec_states (tuple, optional) – tuple of LSTM states (hidden state, cell state), defaults to None
eps (torch.Tensor, optional) – [B, 2*in_features, H//2, W//2] (for factor=2) tensor of sampled latent variables from unit gaussian, defaults to None
- Returns
x: [B, in_features, H, W] Output feature tensor
logdet: log determinate block
out_states: tuple of LSTM (cell, hidden) states
- Return type
(torch.Tensor, torch.Tensor, tuple)
-
training: bool¶
-
class
nn.modules.flowLSTMBlock.UnNormedAffineCouplingBlock(in_features, cond_features, train_sampling=True, LUdecompose=False)¶ Bases:
torch.nn.modules.module.ModuleAn unnormalized invertible affine coupling block consisting of an conditional affine coupling layer and a 1x1 convolution. See Fig. 6 of paper: https://arxiv.org/abs/2006.04731
- Parameters
in_features (int) – Number of input feature channels
cond_features (int) – Number of conditional feature channels
train_sampling (bool, optional) – train by sampling (1x1 conv. is inverted for the forward pass), defaults to True
LUdecompose (bool, optional) – Use the LU decomposition for 1x1 convolution, defaults to False
-
forward(x, cond)¶ Forward pass
- Parameters
x (torch.Tensor) – [B, in_features, H, W] input feature tensor
cond (torch.Tensor) – [B, cond_features, H, W] conditional feature tensor
- Returns
y: [B, in_features, H, W] Output feature tensor
logdet: log determinate of affine block
- Return type
(torch.Tensor, torch.Tensor)
-
reverse(y, cond)¶ Backward pass
- Parameters
y (torch.Tensor) – [B, in_features, H, W] input feature tensor
cond (torch.Tensor) – [B, cond_features, H, W] conditional feature tensor
- Returns
x: [B, in_features, H, W] Output feature tensor
logdet: log determinate of affine block
- Return type
(torch.Tensor, torch.Tensor)
-
training: bool¶
nn.modules.flowUtils module¶
-
class
nn.modules.flowUtils.CheckerSqueeze(factor=2)¶ Bases:
torch.nn.modules.module.ModuleSqueezes feature map by reducing the dimensions of the feature and increasing channel number in a checkered pattern. See Fig. 8 of paper: https://arxiv.org/abs/2006.04731
- Parameters
factor (int, optional) – factor to reduce feature dimensions by, defaults to 2
- Note
This is the squeeze approached used in “Density estimation using real nvp” by Dinh et al. https://arxiv.org/abs/1605.08803
-
forward(x)¶ Forward pass
- Parameters
x (torch.Tensor) – [B, in_features, H, W] input feature tensor
- Returns
y: [B, factor**2 * in_features, H/factor, W/factor] Squeezed output feature tensor
- Return type
torch.Tensor
-
reverse(y)¶ Backward pass
- Parameters
y (torch.Tensor) – [B, factor**2 * in_features, H/factor, W/factor] Squeezed input feature tensor
- Returns
x: [B, in_features, H, W] Output feature tensor
- Return type
torch.Tensor
-
training: bool¶
-
class
nn.modules.flowUtils.Conv2dZeros(in_features, out_features, logscale_factor=1)¶ Bases:
torch.nn.modules.module.ModuleConvolution with weight and bias initialized to zero followed by channel-wise scaling \(x*exp(scale * logscale\_factor)\)
- Parameters
in_features (int) – Number of input feature channels
out_features (int) – Number of output feature channels
logscale_factor (int, optional) – log factor to scale output tensor by, defaults to 1
- Note
This is proposed in “Glow: Generative flow with invertible 1x1 convolutions” by Kingma et al. https://arxiv.org/abs/1807.03039. Appears to help with stability.
-
forward(x)¶ Forward pass.
- Parameters
x (torch.Tensor) – [B, in_features, H, W] input feature tensor
- Returns
out: [B, out_features, H, W] output feature tensor
- Return type
torch.Tensor
-
training: bool¶
-
class
nn.modules.flowUtils.GaussianDiag(mean, log_stddev)¶ Bases:
objectMulti-variate Gaussian class with diagonal covariance for representing the latent variables
- Parameters
mean (torch.Tensor) – [B, in_features, H, W] tensor of mean values
log_stddev (torch.Tensor) – [B, in_features, H, W] tensor of log sandard deviations
-
Log2PI= 1.8378770664093453¶
-
likelihood(x)¶ Computes the Gaussian log-likelihood of each element
- Parameters
x (torch.Tensor) – [B, in_features, H, W] input feature tensor
- Returns
like: [B, in_features, H, W] log-likelihood tensor
- Return type
torch.Tensor
-
log_prob(x)¶ Computes the log product (sum) of Gaussian likelihoods over the entire input feature tensor
- Parameters
x (torch.Tensor) – [B, in_features, H, W] input feature tensor
- Returns
likelihood: [B] sum log-likelihood over features
- Return type
torch.Tensor
-
sample(eps=None)¶ Samples latent variables from learned Gaussian density
- Parameters
eps – [B, in_features, H, W] Latent samples from the unit Gaussian to reconstruct specific latent variables.
If none are provided latent variables are sampled randomly from learned density, defaults to None :type eps: torch.Tensor, optional :return:
z: [B, in_features, H, W] sum log-likelihood over features
- Return type
torch.Tensor
-
class
nn.modules.flowUtils.LatentEncoder(in_features)¶ Bases:
torch.nn.modules.module.ModuleLatent encoder used to compute mu and std for Gaussian density from split feature map. See NN block in Fig. 8 of paper: https://arxiv.org/abs/2006.04731
- Parameters
in_features (int) – Number of input feature channels
-
forward(x)¶ Forward pass
- Parameters
x (torch.Tensor) – [B, in_features, H, W] input feature tensor
- Returns
gauss_diag: Gaussian prior
- Return type
-
training: bool¶
-
class
nn.modules.flowUtils.Split(in_features)¶ Bases:
torch.nn.modules.module.ModuleSplits input features into half features that are passed deeper in the model and the other half modeled as a Gaussian density. See NN block in Fig. 8 of paper: https://arxiv.org/abs/2006.04731
- Parameters
in_features (int) – Number of input feature channels
-
forward(z, return_eps=False)¶ Forward split
- Parameters
z (torch.Tensor) – [B, in_features, H, W] input feature tensor
return_eps (bool, optional) – Return samples from latent densities, defaults to False
- Returns
z1: [B, in_features//2, H, W] output feature tensor
log_prob_prior: [B] log-likelihood of split features
eps: [B, in_features//2, H, W] tensor of sampled latent variables from unit gaussian
- Return type
(torch.Tensor, torch.Tensor, torch.Tensor)
-
reverse(z1, eps=None)¶ Backward split
- Parameters
z1 (torch.Tensor) – [B, in_features//2, H, W] input split feature tensor
eps – [B, in_features//2, H, W] Latent samples from the unit Gaussian to reconstruct specific latent variables.
If none are provided latent variables are sampled randomly from learned density, defaults to None :type eps: torch.Tensor, optional :return:
z: [B, in_features, H, W] output reconstructed feature tensor
log_prob_prior: [B] log-likelihood of split features
- Return type
(torch.Tensor, torch.Tensor)
-
training: bool¶
-
class
nn.modules.flowUtils.Squeeze(factor=2)¶ Bases:
torch.nn.modules.module.ModuleSqueezes feature map by reducing the dimensions of the feature and increasing channel number in chunks.
- Parameters
factor (int, optional) – factor to reduce feature dimensions by, defaults to 2
- Note
This is the squeeze approached used in “Glow: Generative flow with invertible 1x1 convolutions” by Kingma et al. https://arxiv.org/abs/1807.03039
-
forward(x)¶ Forward pass
- Parameters
x (torch.Tensor) – [B, in_features, H, W] input feature tensor
- Returns
y: [B, factor**2 * in_features, H/factor, W/factor] Squeezed output feature tensor
- Return type
torch.Tensor
-
reverse(y)¶ Backward pass
- Parameters
y (torch.Tensor) – [B, factor**2 * in_features, H/factor, W/factor] Squeezed input feature tensor
- Returns
x: [B, in_features, H, W] Output feature tensor
- Return type
torch.Tensor
-
training: bool¶
nn.modules.glowConv module¶
-
class
nn.modules.glowConv.InvertibleConv1x1(in_features, train_sampling=True)¶ Bases:
torch.nn.modules.module.ModuleInvertible 1x1 Conv layer which supports two configuration, the standard version, train_sampling = False, requires a matrix inversion on the backwards pass. With train_sampling = True, the matrix inversion occurs on the forward pass. This can be used to avoid an expensive inversion during training.
- Parameters
in_features (int) – Number of input feature channels
train_sampling (bool, optional) – train by sampling (1x1 conv. is inverted for the forward pass), defaults to True
- Note
For additional information see “Glow: Generative Flow with Invertible 1×1 Convolutions” by Kingma et al. https://arxiv.org/abs/1807.03039
-
forward(x)¶ Forward pass
- Parameters
x (torch.Tensor) – [B, in_features, H, W] input feature tensor
- Returns
y: [B, in_features, H, W] Output feature tensor
logdet: [B] log determinate of block
- Return type
(torch.Tensor, torch.Tensor)
-
log_determinant(x, W)¶ Calculates the log determinate of convolution
- Parameters
x (torch.Tensor) – [B, in_features, H, W] input feature tensor
W (torch.Tensor) – [in_features, in_features] 1x1 convolutional weight tensor
- Returns
log_det: [B] log determinate
- Return type
torch.Tensor
-
reverse(y)¶ Backward pass
- Parameters
y (torch.Tensor) – [B, in_features, H, W] input feature tensor
- Returns
x: [B, in_features, H, W] Output feature tensor
logdet: [B] log determinate of block
- Return type
(torch.Tensor, torch.Tensor)
-
training: bool¶
-
class
nn.modules.glowConv.InvertibleConv1x1LU(in_channels, train_sampling=True)¶ Bases:
torch.nn.modules.module.ModuleInvertible 1x1 convolutional layer with a weight matrix modeled by an LU decompsition. The standard version, train_sampling = False, requires a matrix inversion on the backwards pass. With train_sampling = True, the matrix inversion occurs on the forward pass. This can be used to avoid an expensive inversion during training.
- Parameters
in_features (int) – Number of input feature channels
train_sampling (bool, optional) – train by sampling (1x1 conv. is inverted for the forward pass), defaults to True
- Note
For additional information see “Glow: Generative Flow with Invertible 1×1 Convolutions” by Kingma et al. https://arxiv.org/abs/1807.03039
-
forward(x)¶ Forward pass
- Parameters
x (torch.Tensor) – [B, in_features, H, W] input feature tensor
- Returns
y: [B, in_features, H, W] Output feature tensor
logdet: [B] log determinate of block
- Return type
(torch.Tensor, torch.Tensor)
-
inv_weight()¶ Gets the LU inverse of the 1x1 convolutional weight matrix
- Returns
inv_W: [in_features, in_features] inverse 1x1 convolutional weight matrix
- Return type
torch.Tensor
-
reverse(y)¶ Backward pass
- Parameters
y (torch.Tensor) – [B, in_features, H, W] input feature tensor
- Returns
x: [B, in_features, H, W] Output feature tensor
logdet: [B] log determinate of block
- Return type
(torch.Tensor, torch.Tensor)
-
training: bool¶
-
weight()¶ Gets the 1x1 convolutional weight matrix from LU representation :returns:
W: [in_features, in_features] 1x1 convolutional weight matrix
- Return type
torch.Tensor
nn.modules.misc module¶
-
class
nn.modules.misc.UpsamplingLinear(scale_factor=2.0)¶ Bases:
torch.nn.modules.module.ModuleBi-linear upscaling module for upscaling feature maps.
- Parameters
scale_factor (int, optional) – up scale factor, defaults to 2.
-
forward(x)¶ Forward pass
- Parameters
x (torch.Tensor) – [B, in_features, H, W] input feature tensor
- Returns
y: [B, in_features, scale_factor*H, scale_factor*W] Output feature tensor
- Return type
torch.Tensor
-
training: bool¶