albumentations.core.tensor
CPU Tensor input contract and annotation bridge shared by Compose.
Members
- functionvalidate_tensor_input
- functiontensor_to_numpy_annotation
- functiontensor_to_numpy_spatial
- functionnumpy_to_tensor_spatial
- functionnumpy_to_tensor_annotation
validate_tensor_inputfunction
validate_tensor_input(
value: torch.Tensor,
data_name: str,
canonical_name: str
)Validate a CPU Tensor against target-specific Compose shape, dtype, device, layout, and autograd boundary rules before it reaches a transform helper. The CPU stage accepts explicit-channel image targets, spatial mask targets, and float32 annotation matrices. It preserves non-contiguous strides because each accepted capability later decides whether a contiguous copy is justified by its full-path benchmark.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| value | torch.Tensor | - | - |
| data_name | str | - | - |
| canonical_name | str | - | - |
tensor_to_numpy_annotationfunction
tensor_to_numpy_annotation(
value: torch.Tensor,
target: str
)Return a NumPy view of a validated Tensor bbox or keypoint matrix through the shared annotation bridge used by the existing geometry processors.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| value | torch.Tensor | - | - |
| target | str | - | - |
tensor_to_numpy_spatialfunction
tensor_to_numpy_spatial(
value: torch.Tensor,
target: str
)Convert a validated Tensor target to the channel-last NumPy layout that existing Compose preprocessing and transforms expect. The bridge owns every layout conversion. Transform helpers only receive their established NumPy layout and never decide whether to convert a caller's Tensor themselves.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| value | torch.Tensor | - | - |
| target | str | - | - |
numpy_to_tensor_spatialfunction
numpy_to_tensor_spatial(
value: NDArray[np.generic],
target: str
)Convert a NumPy result from Compose back to the caller-facing Tensor layout, copying only when negative strides require it. NumPy transforms may return a negative-stride view, such as after a reflection. PyTorch cannot share that storage, so materialize only that incompatible case before returning the Tensor result.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| value | NDArray[np.generic] | - | - |
| target | str | - | - |
numpy_to_tensor_annotationfunction
numpy_to_tensor_annotation(
value: NDArray[np.generic],
target: str
)Return a Tensor bbox or keypoint matrix from a processor result, materializing only negative-stride NumPy storage that PyTorch cannot safely share.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| value | NDArray[np.generic] | - | - |
| target | str | - | - |