BatchLabels¶
- class torchaug.ta_tensors.BatchLabels(data: Any, *, samples_ranges: List[Tuple[int, int]], dtype: dtype | None = None, device: device | str | int | None = None, requires_grad: bool | None = None)[source]¶
BatchLabelssubclass for concatenated labels.Useful for labels of bounding boxes or masks, where each sample can have a different number of labels.
- Parameters:
data – Any data that can be turned into a tensor with
torch.as_tensor().dtype – Desired data type. If omitted, will be inferred from
data.samples_ranges – Each element is the range of the indices of the labels for each sample.
device – Desired device. If omitted and
datais atorch.Tensor, the device is taken from it. Otherwise, the batch of tensor is constructed on the CPU.requires_grad – Whether autograd should record operations. If omitted and
datais aLabels, the value is taken from it. Otherwise, defaults toFalse.
- classmethod cat(labels_batches)[source]¶
Concatenates a sequence of
BatchLabelsalong the first dimension.- Parameters:
labels_batches (
Sequence[BatchLabels]) – A sequence ofBatchLabelsto concatenate.- Returns:
The concatenated
BatchLabels.
- get_chunk(chunk_indices)[source]¶
Get a chunk of the batch of tensors.
- Parameters:
chunk_indices (
Tensor) – The indices of the chunk to get.- Return type:
- Returns:
The chunk of the batch of tensors.
- classmethod masked_select(labels, mask)[source]¶
Remove labels from the batch of labels.
- Parameters:
labels (
BatchLabels) – The batch of labels to remove labels from.mask (
Tensor) – A boolean mask to keep labels.
- Return type:
- Returns:
The updated batch of labels.
- update_chunk_(chunk, chunk_indices)[source]¶
Update a chunk of the batch of labels.
- Parameters:
chunk (
BatchLabels) – The chunk update.chunk_indices (
Tensor) – The indices of the chunk to update.
- Return type:
- Returns:
The updated batch of labels.