compressai.layers#
MaskedConv2d#
- class compressai.layers.MaskedConv2d(*args: Any, mask_type: str = 'A', **kwargs: Any)[source]#
Masked 2D convolution implementation, mask future âunseenâ pixels. Useful for building auto-regressive network components.
Introduced in âConditional Image Generation with PixelCNN Decodersâ.
Inherits the same arguments as a nn.Conv2d. Use mask_type=âAâ for the first layer (which also masks the âcurrent pixelâ), mask_type=âBâ for the following layers.
GDN#
- class compressai.layers.GDN(in_channels: int, inverse: bool = False, beta_min: float = 1e-06, gamma_init: float = 0.1)[source]#
Generalized Divisive Normalization layer.
Introduced in âDensity Modeling of Images Using a Generalized Normalization Transformationâ, by Balle Johannes, Valero Laparra, and Eero P. Simoncelli, (2016).
\[y[i] = \frac{x[i]}{\sqrt{\beta[i] + \sum_j(\gamma[j, i] * x[j]^2)}}\]
GDN1#
- class compressai.layers.GDN1(in_channels: int, inverse: bool = False, beta_min: float = 1e-06, gamma_init: float = 0.1)[source]#
Simplified GDN layer.
Introduced in âComputationally Efficient Neural Image Compressionâ, by Johnston Nick, Elad Eban, Ariel Gordon, and Johannes BallÃĐ, (2019).
\[y[i] = \frac{x[i]}{\beta[i] + \sum_j(\gamma[j, i] * |x[j]|}\]
ResidualBlock#
ResidualBlockWithStride#
ResidualBlockUpsample#
- class compressai.layers.ResidualBlockUpsample(in_ch: int, out_ch: int, upsample: int = 2)[source]#
Residual block with sub-pixel upsampling on the last convolution.
- Parameters
in_ch (int) â number of input channels
out_ch (int) â number of output channels
upsample (int) â upsampling factor (default: 2)
AttentionBlock#
- class compressai.layers.AttentionBlock(N: int)[source]#
Self attention block.
Simplified variant from âLearned Image Compression with Discretized Gaussian Mixture Likelihoods and Attention Modulesâ, by Zhengxue Cheng, Heming Sun, Masaru Takeuchi, Jiro Katto.
- Parameters
N (int) â Number of channels)
QReLU#
- class compressai.layers.QReLU(*args, **kwargs)[source]#
Clamping input with given bit-depth range. Suppose that input data presents integer through an integer network otherwise any precision of input will simply clamp without rounding operation.
Pre-computed scale with gamma function is used for backward computation.
More details can be found in âInteger networks for data compression with latent-variable modelsâ, by Johannes BallÃĐ, Nick Johnston and David Minnen, ICLR in 2019
- Parameters
input â a tensor data
bit_depth â source bit-depth (used for clamping)
beta â a parameter for modeling the gradient during backward computation