espnet2.gan_tts.utils.get_random_segments.get_segments
Less than 1 minute
espnet2.gan_tts.utils.get_random_segments.get_segments
espnet2.gan_tts.utils.get_random_segments.get_segments(x: Tensor, start_idxs: Tensor, segment_size: int) → Tensor
Function to get random segments.
This function retrieves random segments from a given tensor based on specified segment sizes and their respective lengths. The output consists of both the segmented tensor and the starting indices of these segments.
- Parameters:
- x (torch.Tensor) – Input tensor of shape (B, C, T) where:
- B: Batch size
- C: Number of channels
- T: Length of the sequence
- x_lengths (torch.Tensor) – Length tensor of shape (B,) indicating the valid lengths of each input tensor in the batch.
- segment_size (int) – The size of the segments to be extracted from the input tensor.
- x (torch.Tensor) – Input tensor of shape (B, C, T) where:
- Returns: A tuple containing: : - Tensor: Segmented tensor of shape (B, C, segment_size).
- Tensor: Start index tensor of shape (B,) representing the starting indices of each segment.
- Return type: Tuple[torch.Tensor, torch.Tensor]
Examples
>>> x = torch.randn(4, 2, 10) # A batch of 4 samples, 2 channels, 10 length
>>> x_lengths = torch.tensor([10, 8, 10, 5]) # Lengths of each sample
>>> segment_size = 5
>>> segments, start_idxs = get_random_segments(x, x_lengths, segment_size)
>>> segments.shape
torch.Size([4, 2, 5]) # Segmented tensor shape
>>> start_idxs.shape
torch.Size([4]) # Start index tensor shape