espnet2.gan_tts.vits.flow.FlipFlow
espnet2.gan_tts.vits.flow.FlipFlow
class espnet2.gan_tts.vits.flow.FlipFlow(*args, **kwargs)
Bases: Module
FlipFlow is a flip flow module that applies a simple flipping operation on
the input tensor during forward propagation. This module is part of the VITS architecture used for generative adversarial networks in text-to-speech tasks.
None
- Parameters:
- x (torch.Tensor) – Input tensor of shape (B, channels, T).
- inverse (bool) – Whether to perform the inverse operation. Default is False.
- Returns:
- If inverse is False: : - Tensor: Flipped tensor of shape (B, channels, T).
- Tensor: Log-determinant tensor for negative log-likelihood (NLL) of shape (B,).
- If inverse is True: : - Tensor: The original input tensor after flipping.
- If inverse is False: : - Tensor: Flipped tensor of shape (B, channels, T).
- Return type: Union[torch.Tensor, Tuple[torch.Tensor, torch.Tensor]]
####### Examples
>>> flip_flow = FlipFlow()
>>> x = torch.randn(4, 3, 5) # Example input tensor
>>> flipped, logdet = flip_flow(x) # Forward operation
>>> original = flip_flow(x, inverse=True) # Inverse operation
NOTE
This module assumes that the input tensor has at least 3 dimensions corresponding to the batch size, number of channels, and sequence length.
Initialize internal Module state, shared by both nn.Module and ScriptModule.
forward(x: Tensor, *args, inverse: bool = False, **kwargs) → Tensor | Tuple[Tensor, Tensor]
Calculate forward propagation.
This method performs the forward pass of the FlipFlow module, which applies a flipping transformation to the input tensor. It can also perform the inverse operation based on the inverse flag.
- Parameters:
- x (torch.Tensor) – Input tensor of shape (B, channels, T).
- *args – Additional positional arguments (unused).
- inverse (bool , optional) – Whether to inverse the flow. Defaults to False.
- **kwargs – Additional keyword arguments (unused).
- Returns:
- If inverse is False, returns a tuple containing: : - Flipped tensor of shape (B, channels, T).
- Log-determinant tensor for negative log-likelihood (NLL) of shape (B,).
- If inverse is True, returns the tensor after applying the inverse transformation.
- If inverse is False, returns a tuple containing: : - Flipped tensor of shape (B, channels, T).
- Return type: Union[torch.Tensor, Tuple[torch.Tensor, torch.Tensor]]
####### Examples
>>> flip_flow = FlipFlow()
>>> input_tensor = torch.randn(5, 3, 10) # Example input
>>> output_tensor, logdet = flip_flow(input_tensor)
>>> inverted_tensor = flip_flow(input_tensor, inverse=True)