NCSNpp#
- class deepinv.models.NCSNpp(img_resolution=64, in_channels=3, out_channels=3, label_dim=0, augment_dim=9, model_channels=128, channel_mult=[1, 2, 2, 2], channel_mult_emb=4, num_blocks=4, attn_resolutions=[16], dropout=0.10, label_dropout=0.0, embedding_type='fourier', channel_mult_noise=2, encoder_type='residual', decoder_type='standard', resample_filter=[1, 3, 3, 1], pretrained=None, device=None)[source]#
Bases:
Denoiser
Re-implementation of the DDPM++ and NCSN++ architectures from the paper: Score-Based Generative Modeling through Stochastic Differential Equations.
Equivalent to the original implementation by Song et al., available at the official implementation.
The architecture consists of a series of convolution layer, down-sampling residual blocks and up-sampling residual blocks with skip-connections of scale \(\sqrt{0.5}\). The model also supports an additional class condition model. Each residual block has a self-attention mechanism with multiple channels per attention head. The noise level can be embedded using either Positional Embedding or Fourier Embedding with optional augmentation linear layer.
- Parameters:
img_resolution (int) – Image spatial resolution at input/output.
in_channels (int) – Number of color channels at input.
out_channels (int) – Number of color channels at output.
label_dim (int) – Number of class labels, 0 = unconditional.
augment_dim (int) – Augmentation label dimensionality, 0 = no augmentation.
model_channels (int) – Base multiplier for the number of channels.
channel_mult (list) – Per-resolution multipliers for the number of channels.
channel_mult_emb (int) – Multiplier for the dimensionality of the embedding vector.
num_blocks (int) – Number of residual blocks per resolution.
attn_resolutions (list) – List of resolutions with self-attention.
dropout (float) – Dropout probability of intermediate activations.
label_dropout (float) – Dropout probability of class labels for classifier-free guidance.
embedding_type (str) – Timestep embedding type: ‘positional’ for DDPM++, ‘fourier’ for NCSN++.
channel_mult_noise (int) – Timestep embedding size: 1 for DDPM++, 2 for NCSN++.
encoder_type (str) – Encoder architecture: ‘standard’ for DDPM++, ‘residual’ for NCSN++.
decoder_type (str) – Decoder architecture: ‘standard’ for both DDPM++ and NCSN++.
resample_filter (list) – Resampling filter: [1,1] for DDPM++, [1,3,3,1] for NCSN++.
pretrained (str, None) – use a pretrained network. If
pretrained=None
, the weights will be initialized at random using Pytorch’s default initialization. Ifpretrained='download'
, the weights will be downloaded from an online repository (the default model trained on FFHQ at 64x64 resolution (ffhq64-uncond-ve
) with default architecture). Finally,pretrained
can also be set as a path to the user’s own pretrained weights. See pretrained-weights for more details.device (torch.device) – Instruct our module to be either on cpu or on gpu. Default to
None
, which suggests working on cpu.
- forward(x, sigma, class_labels=None, augment_labels=None)[source]#
Run the denoiser on noisy image.
- Parameters:
x (torch.Tensor) – noisy image
sigma (Union[torch.Tensor, float]) – noise level
class_labels (torch.Tensor) – class labels
augment_labels (torch.Tensor) – augmentation labels
- Return torch.Tensor:
denoised image.
Examples using NCSNpp
:#

Posterior Sampling for Inverse Problems with Stochastic Differential Equations modeling.