credit.models.crossformer_ensemble#
Attributes#
Classes#
CrossFormer variant with pixel-wise noise injection in both encoder and decoder stages. |
|
A module that injects noise into feature maps, with a per-pixel and per-channel style modulation. |
Module Contents#
- class credit.models.crossformer_ensemble.CrossFormerWithNoise(noise_latent_dim=128, encoder_noise_factor=0.05, decoder_noise_factor=0.275, encoder_noise=True, freeze=True, **kwargs)#
Bases:
credit.models.crossformer.CrossFormerCrossFormer variant with pixel-wise noise injection in both encoder and decoder stages.
- noise_latent_dim#
Dimensionality of the noise vector.
- Type:
int
- encoder_noise_factor#
Initial scaling factor for encoder noise injection.
- Type:
float
- decoder_noise_factor#
Initial scaling factor for decoder noise injection.
- Type:
float
- encoder_noise#
Whether to apply noise injection in the encoder.
- Type:
bool
- freeze#
Whether to freeze pre-trained model weights.
- Type:
bool
- noise_latent_dim = 128#
- encoder_noise = True#
- noise_inject1#
- noise_inject2#
- noise_inject3#
- forward(x, noise=None, forecast_step=None)#
Forward pass through the CrossFormer with noise injection.
- Parameters:
x (Tensor) – Input tensor of shape (batch_size, channels, height, width).
noise (Tensor, optional) – External noise tensor. If None, noise is sampled internally. Defaults to None.
- Returns:
Output tensor after passing through the model.
- Return type:
Tensor
- class credit.models.crossformer_ensemble.PixelNoiseInjection(noise_dim, feature_channels, noise_factor=0.1)#
Bases:
torch.nn.ModuleA module that injects noise into feature maps, with a per-pixel and per-channel style modulation.
- noise_transform#
A linear transformation to map latent noise to the feature map’s channels.
- Type:
nn.Linear
- modulation#
A learnable scaling factor applied to the noise.
- Type:
nn.Parameter
- noise_factor#
A scaling factor for controlling the intensity of the injected noise.
- Type:
float
- forward(feature_map, noise)#
Adds noise to the feature map, modulated by style and the modulation parameter.
- noise_transform#
- modulation#
- noise_factor#
- forward(feature_map, noise)#
Injects noise into the feature map.
- Parameters:
feature_map (torch.Tensor) – The input feature map (batch, channels, height, width).
noise (torch.Tensor) – The latent noise tensor (batch, noise_dim), used for modulating the injected noise.
- Returns:
The feature map with injected noise.
- Return type:
torch.Tensor
- credit.models.crossformer_ensemble.logger#