torchoutil.nn.functional.segments module¶
- activity_to_segments(
- x: Tensor,
Extracts segments start and end positions from a boolean activity/mask tensor.
Example 1¶
>>> x = torch.as_tensor([0, 1, 1, 0, 0, 1, 1, 1, 1, 0]).bool() >>> starts, ends = extract_segments(x) >>> starts ... tensor([1, 5]) >>> ends ... tensor([3, 9])
Example 2¶
>>> x = torch.as_tensor([[1, 1, 1, 0], [1, 0, 0, 1]]).bool() >>> indices, starts, ends = extract_segments(x) >>> indices ... tensor([0, 1, 1]) >>> starts ... tensor([0, 0, 3]) >>> ends ... tensor([3, 1, 4])
- Args:
x: (…, N) bool tensor containing D dims
- Returns:
- segments: (D+1, M) tensor, where M is the total number of segments
When D > 1, segments also contains indices of the source column for each start and end value. See Example 2 for details.
- extract_segments(
- x: Tensor,
Extracts segments start and end positions from a boolean activity/mask tensor.
Example 1¶
>>> x = torch.as_tensor([0, 1, 1, 0, 0, 1, 1, 1, 1, 0]).bool() >>> starts, ends = extract_segments(x) >>> starts ... tensor([1, 5]) >>> ends ... tensor([3, 9])
Example 2¶
>>> x = torch.as_tensor([[1, 1, 1, 0], [1, 0, 0, 1]]).bool() >>> indices, starts, ends = extract_segments(x) >>> indices ... tensor([0, 1, 1]) >>> starts ... tensor([0, 0, 3]) >>> ends ... tensor([3, 1, 4])
- Args:
x: (…, N) bool tensor containing D dims
- Returns:
- segments: (D+1, M) tensor, where M is the total number of segments
When D > 1, segments also contains indices of the source column for each start and end value. See Example 2 for details.
- segments_list_to_activity(
- segments_list: List[Tuple[int, int]] | Tensor | list,
- maxsize: int | None = None,
- device: device | None | Literal['default', 'cuda_if_available'] | str | int = None,
- segments_to_activity(
- x: Tensor,