espnet2.gan_tts.vits.flow.ElementwiseAffineFlow
espnet2.gan_tts.vits.flow.ElementwiseAffineFlow
class espnet2.gan_tts.vits.flow.ElementwiseAffineFlow(channels: int)
Bases: Module
Elementwise affine flow module.
This module applies an elementwise affine transformation to the input tensor. It allows for the modeling of complex distributions by learning parameters for affine transformations.
channels
Number of channels in the input tensor.
- Type: int
m
Learnable parameter for the affine transformation.
- Type: torch.nn.Parameter
logs
Learnable parameter for the logarithm of the scale in the affine transformation.
Type: torch.nn.Parameter
Parameters:channels (int) – Number of channels.
forward(x
torch.Tensor, x_mask: torch.Tensor, inverse: bool = False, : ``` **
<br/>
kwargs) -> Union[torch.Tensor, Tuple[torch.Tensor, torch.Tensor]]:
Calculate forward propagation.
* **Returns:**
If inverse is False, returns the transformed tensor and the log-determinant
for NLL. If inverse is True, returns the original input tensor.
* **Return type:**
Union[torch.Tensor, Tuple[torch.Tensor, torch.Tensor]]
####### Examples
```python
>>> flow = ElementwiseAffineFlow(channels=10)
>>> x = torch.randn(2, 10, 5) # (B, channels, T)
>>> x_mask = torch.ones(2, 1, 5) # (B, 1, T)
>>> output, logdet = flow(x, x_mask) # Forward transformation
>>> original = flow(x, x_mask, inverse=True) # Inverse transformation
NOTE
The log-determinant is useful for calculating the negative log-likelihood during training of generative models.
Initialize ElementwiseAffineFlow module.
- Parameters:channels (int) – Number of channels.
#
forward(x
Elementwise affine flow module.
This module implements an elementwise affine flow for transforming input tensors. It applies an affine transformation defined by learned parameters to the input tensor and optionally computes the log-determinant for use in normalizing flows.
channels
Number of channels for the input tensor.
- Type: int
m
Learnable parameter for the affine transformation.
- Type: torch.nn.Parameter
logs
Learnable parameter for the log scale.
Type: torch.nn.Parameter
Parameters:channels (int) – Number of channels.
Returns:
- Output tensor (B, channels, T) after the affine transformation.
- Log-determinant tensor for NLL (B,) if not inverse.
Return type: Union[torch.Tensor, Tuple[torch.Tensor, torch.Tensor]]
####### Examples
>>> flow = ElementwiseAffineFlow(channels=5)
>>> x = torch.randn(2, 5, 10) # Batch size of 2, 5 channels, length 10
>>> x_mask = torch.ones(2, 1, 10) # Mask for all timesteps
>>> y, logdet = flow(x, x_mask) # Forward transformation
>>> x_reconstructed = flow(y, x_mask, inverse=True) # Inverse transformation