Advanced API¶
Most applications should use Compose. The objects on this page expose implementation-level building blocks for research, inspection, and controlled integrations. Their contracts are narrower and more likely to evolve than the core pipeline API.
Stability levels¶
| Level | Surface | Guidance |
|---|---|---|
| Public | Compose, TransformSpec, descriptors, converters, target functions, enums |
Preferred application API |
| Advanced | Segment classes, adapter/converter protocols, build_segments |
Use when the low-level contract is understood and pinned by tests |
| Experimental/internal | _backend.register_adapter, entry-point loading, private segment subclasses |
Do not treat as stable production extension API |
Segment objects are torch.nn.Module implementations, but the top-level pipeline directly dispatches their forward methods for speed. Forward hooks registered on individual segment modules are therefore bypassed; register hooks on the pipeline or execute the segment directly when hook observation is required.
Geometric segments¶
FusedAffineSegment¶
Composes one compatible affine/exact run. Its adapter must classify transforms, sample canonical parameters, and build forward pixel matrices.
FusedAffineSegment ¶
FusedAffineSegment(transforms: list[object], adapter: TransformAdapter, interpolation: InterpolationStr | None = None, padding_mode: PaddingModeStr | None = None, randomness: RandomnessPolicy = BACKEND, *, compile_warp: bool = False, mask_interpolation: MaskInterpolationStr = 'nearest')
Bases: _BaseAffineSegment
Fused affine segment that composes geometric transforms into one grid_sample call.
Accumulates per-sample (B, 3, 3) forward affine matrices for every transform in the segment, inverts the
composed matrix once, and applies a single grid_sample warp. All operations are vectorised over the batch
dimension -- no Python loop per sample.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transforms
|
list[object]
|
List of geometric transform objects to fuse. |
required |
adapter
|
TransformAdapter
|
A |
required |
interpolation
|
InterpolationStr | None
|
Optional interpolation mode override ( |
None
|
padding_mode
|
PaddingModeStr | None
|
Optional padding mode override ( |
None
|
mask_interpolation
|
MaskInterpolationStr
|
Sampling mode for auxiliary masks. |
'nearest'
|
Initialize FusedAffineSegment.
forward ¶
forward(image: Tensor, aux_targets: dict[str, Tensor] | None = None) -> Tensor | tuple[Tensor, dict[str, Tensor]]
Apply the fused affine transform chain via a single grid_sample call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Tensor
|
|
required |
aux_targets
|
dict[str, Tensor] | None
|
Optional dict of auxiliary targets to transform alongside
the image ( |
None
|
Returns:
| Type | Description |
|---|---|
Tensor | tuple[Tensor, dict[str, Tensor]]
|
Bare |
Tensor | tuple[Tensor, dict[str, Tensor]]
|
|
ExactAffineSegment¶
Executes an exact-only run without interpolation. Supported discrete operations and auxiliary-target behavior depend on the adapter.
ExactAffineSegment ¶
ExactAffineSegment(transforms: list[object], adapter: TransformAdapter, randomness: RandomnessPolicy = BACKEND)
Bases: Module
Lossless segment for GEOMETRIC_EXACT-only chains.
Used when a run of consecutive geometric transforms consists entirely of GEOMETRIC_EXACT operations, such as
flips and other discrete, lossless image-space transforms supported by the active adapter (for example 90-degree
rotations or transpose-like ops). Applies each transform via :meth:TransformAdapter.exact_apply instead of
grid_sample, introducing zero interpolation error.
Per-sample probability masking is implemented by sampling a boolean mask of shape (B,) from each transform's
application probability and applying the exact transform only to active samples. The fused engine prefers a prob
attribute when present and falls back to backend p for native transform objects.
Auxiliary-target routing: masks route for every exact op (a non-flip op's mask is transformed by the same
lossless rotation applied to the image, sharing its per-sample sampling); boxes/keypoints route for flips via
:meth:TransformAdapter.exact_flip_dims. A geometric run that combines a non-flip exact op with box/keypoint
targets is built as a :class:FusedAffineSegment (grid path) instead, so those targets are always routed --
build_segments receives that hint via its route_coords_via_grid flag.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transforms
|
list[object]
|
List of |
required |
adapter
|
TransformAdapter
|
A |
required |
randomness
|
RandomnessPolicy
|
Batch randomness policy. |
BACKEND
|
Examples:
>>> import torch
>>> import kornia.augmentation as K
>>> from fuse_augmentations.affine.segment import ExactAffineSegment
>>> from fuse_augmentations.adapters.kornia import KorniaAdapter
>>> t = K.RandomHorizontalFlip(p=1.0)
>>> seg = ExactAffineSegment([t], KorniaAdapter())
>>> out = seg(torch.zeros(1, 3, 8, 8))
>>> out.shape
torch.Size([1, 3, 8, 8])
Initialize ExactAffineSegment.
last_matrix
property
¶
Return None always (ExactAffineSegment does not compute a matrix).
forward ¶
forward(image: Tensor, aux_targets: dict[str, Tensor] | None = None) -> Tensor | tuple[Tensor, dict[str, Tensor]]
Apply exact transforms losslessly with per-sample masking.
For each transform, draws a per-sample boolean mask from the transform's
prob probability, applies :meth:TransformAdapter.exact_apply only to
active samples, and scatters the transformed subset back into the batch.
Auxiliary-target routing is currently supported only for flip-compatible
exact ops exposed through :meth:TransformAdapter.exact_flip_dims.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Tensor
|
Input image batch. Shape: |
required |
aux_targets
|
dict[str, Tensor] | None
|
Optional dict of auxiliary targets to transform alongside
the image ( |
None
|
Returns:
| Type | Description |
|---|---|
Tensor | tuple[Tensor, dict[str, Tensor]]
|
Bare |
Tensor | tuple[Tensor, dict[str, Tensor]]
|
|
ProjectiveSegment¶
Composes consecutive projective homographies. It is a separate segment from adjacent affine geometry.
ProjectiveSegment ¶
ProjectiveSegment(transforms: list[object], adapter: TransformAdapter, interpolation: InterpolationStr | None = None, padding_mode: PaddingModeStr | None = None, randomness: RandomnessPolicy = BACKEND, *, compile_warp: bool = False, mask_interpolation: MaskInterpolationStr = 'nearest')
Bases: _BaseAffineSegment
Fused projective segment that composes homography matrices into one grid_sample call.
Identical to :class:FusedAffineSegment in accumulation and auxiliary-target
handling -- both share the :class:_BaseAffineSegment composition engine --
but overrides :meth:_apply_grid to use
:func:~fuse_augmentations.affine.matrix.perspective_grid instead of
F.affine_grid so the full 3x3 homography (including perspective
division) is applied correctly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transforms
|
list[object]
|
List of projective transform objects to fuse. |
required |
adapter
|
TransformAdapter
|
A |
required |
interpolation
|
InterpolationStr | None
|
Optional interpolation mode override ( |
None
|
padding_mode
|
PaddingModeStr | None
|
Optional padding mode override ( |
None
|
forward ¶
forward(image: Tensor, aux_targets: dict[str, Tensor] | None = None) -> Tensor | tuple[Tensor, dict[str, Tensor]]
Apply the fused projective transform chain via a single grid_sample call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Tensor
|
|
required |
aux_targets
|
dict[str, Tensor] | None
|
Optional dict of auxiliary targets to transform alongside
the image ( |
None
|
Returns:
| Type | Description |
|---|---|
Tensor | tuple[Tensor, dict[str, Tensor]]
|
Bare |
Tensor | tuple[Tensor, dict[str, Tensor]]
|
|
CropResizeSegment¶
Runs a standalone fixed-output crop-resize. On torch paths, an immediately preceding affine run may instead be represented by a private combined geo-crop segment; that private implementation is intentionally not an API object.
CropResizeSegment ¶
CropResizeSegment(transform: object, adapter: TransformAdapter, interpolation: InterpolationStr | None = None, padding_mode: PaddingModeStr | None = None, randomness: RandomnessPolicy = BACKEND, *, antialias: bool = False, mask_interpolation: MaskInterpolationStr = 'nearest')
Bases: Module
Segment for a single CROP_RESIZE_FIXED transform.
Samples the random crop region, builds the forward affine matrix, normalizes it
via :func:~fuse_augmentations.affine.matrix.normalize_matrix_io (which accounts
for different input and output spatial dimensions), and applies exactly one
grid_sample call at the target (H_out, W_out) dimensions.
Unlike :class:FusedAffineSegment, the output shape is (batch_size, channels, height_out, width_out)
which generally differs from the input shape (batch_size, channels, height_in, width_in).
.. note::
Per-sample probability prob is not applied: shape-changing transforms must produce a consistent
output size for all batch elements, so the crop is always applied. Use prob=1.0 (the standard default)
when constructing RandomResizedCrop transforms.
.. note::
Auxiliary targets ("mask", "bbox_xyxy", "bbox_xywh", "keypoints") are
warped through the crop affine matrix at the target output size. Masks use nearest-neighbour
sampling to preserve integer class labels; boxes and keypoints are transformed via the forward
affine matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transform
|
object
|
A single |
required |
adapter
|
TransformAdapter
|
A |
required |
interpolation
|
InterpolationStr | None
|
Interpolation mode ( |
None
|
padding_mode
|
PaddingModeStr | None
|
Padding mode ( |
None
|
mask_interpolation
|
MaskInterpolationStr
|
Sampling mode for auxiliary masks. |
'nearest'
|
Initialize CropResizeSegment.
forward ¶
forward(image: Tensor, aux_targets: dict[str, Tensor] | None = None) -> Tensor | tuple[Tensor, dict[str, Tensor]]
Apply the crop-resize via a single grid_sample call at target output size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Tensor
|
|
required |
aux_targets
|
dict[str, Tensor] | None
|
Optional dict of auxiliary targets to transform alongside the image.
Supported keys: |
None
|
Returns:
| Type | Description |
|---|---|
Tensor | tuple[Tensor, dict[str, Tensor]]
|
|
Tensor | tuple[Tensor, dict[str, Tensor]]
|
|
Color segments¶
FusedColorSegment accepts transforms that the adapter can express as homogeneous (4 \times 4) color matrices. It cannot represent nonlinear saturation/hue or arbitrary intermediate clamps.
FusedColorSegment ¶
FusedColorSegment(transforms: list[object], adapter: TransformAdapter, clip_output: bool = True, randomness: RandomnessPolicy = BACKEND, clip_policy: ClipPolicyStr = 'final', *, compile_color: bool = False)
Bases: Module
Fused colour-space segment that composes POINTWISE_LINEAR transforms into one matrix multiply.
Accumulates per-sample (B, 4, 4) homogeneous colour-space affine matrices for every transform in the
segment, multiplies all pixels by the composed matrix, and clamps the result to [0, 1]. All operations are
vectorised over the batch dimension.
Colour transforms do not affect spatial layout, so auxiliary targets (masks, bounding boxes, keypoints) are returned unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transforms
|
list[object]
|
List of |
required |
adapter
|
TransformAdapter
|
A |
required |
clip_output
|
bool
|
When |
True
|
Initialize FusedColorSegment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transforms
|
list[object]
|
|
required |
adapter
|
TransformAdapter
|
Adapter providing |
required |
clip_output
|
bool
|
Whether to clamp the final output to |
True
|
randomness
|
RandomnessPolicy
|
Batch randomness policy. |
BACKEND
|
clip_policy
|
ClipPolicyStr
|
|
'final'
|
compile_color
|
bool
|
Compile only the pure color matrix application on non-CPU devices. |
False
|
forward ¶
forward(image: Tensor, aux_targets: dict[str, Any] | None = None) -> Tensor | tuple[Tensor, dict[str, Any]]
Apply the fused colour matrix to the image batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Tensor
|
|
required |
aux_targets
|
dict[str, Any] | None
|
Optional dict of auxiliary targets. Colour transforms do not affect spatial layout, so these are returned unchanged. |
None
|
Returns:
| Type | Description |
|---|---|
Tensor | tuple[Tensor, dict[str, Any]]
|
Bare |
Tensor | tuple[Tensor, dict[str, Any]]
|
|
Segmentation helper¶
build_segments is exported for advanced use but is an implementation-oriented planner. It expects an adapter instance and returns a heterogeneous list of segment modules and passthrough transforms. Prefer Compose unless a custom planner is being tested directly.
build_segments ¶
build_segments(transforms: list[object], adapter: TransformAdapter, interpolation: InterpolationStr | None = None, padding_mode: PaddingModeStr | None = None, randomness: RandomnessPolicy = BACKEND, *, use_numpy: bool = False, route_coords_via_grid: bool = False, route_crop_aux: bool = False, execution: ExecutionStr = 'cv2', compile_warp: bool = False, per_transform_padding: bool = False, antialias: bool = False, clip_policy: ClipPolicyStr = 'final', mask_interpolation: MaskInterpolationStr = 'nearest') -> list[object]
Split a transform list into fused segments and passthrough transforms.
Walks the transforms left to right and groups consecutive geometric transforms (GEOMETRIC_INTERP or
GEOMETRIC_EXACT) into a single segment. Any SPATIAL_KERNEL, POINTWISE, or POINTWISE_LINEAR
transform breaks the current geometric group and is returned as-is.
After grouping, each accumulated geometric run is classified:
- EXACT-only - if the run contains only
GEOMETRIC_EXACTops (e.g. flips, 90-degree rotations, transpose-like discrete ops), it becomes an :class:ExactAffineSegmentthat uses adapter-provided exact image operations with zero interpolation error. - Mixed / INTERP - if any op in the run is
GEOMETRIC_INTERP, the whole run becomes a :class:FusedAffineSegmentthat composes matrices and applies onegrid_samplecall.
When ReorderPolicy.POINTWISE is active in
:class:~fuse_augmentations.compose.FusedCompose, reorder_pointwise
is called first to bubble pointwise ops out of geometric chains, and
build_segments then classifies the reordered list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transforms
|
list[object]
|
List of transform objects (already reordered if a reorder policy applies). |
required |
adapter
|
TransformAdapter
|
A |
required |
interpolation
|
InterpolationStr | None
|
Interpolation mode override forwarded to each
:class: |
None
|
padding_mode
|
PaddingModeStr | None
|
Padding mode override forwarded to each
:class: |
None
|
use_numpy
|
bool
|
When |
False
|
randomness
|
RandomnessPolicy
|
Batch randomness policy for fused PyTorch segments. |
BACKEND
|
route_coords_via_grid
|
bool
|
When |
False
|
route_crop_aux
|
bool
|
When |
False
|
execution
|
ExecutionStr
|
Execution strategy forwarded to the Albumentations fused segments
( |
'cv2'
|
compile_warp
|
bool
|
When |
False
|
per_transform_padding
|
bool
|
When |
False
|
antialias
|
bool
|
When |
False
|
clip_policy
|
ClipPolicyStr
|
Clamp policy forwarded to each :class: |
'final'
|
mask_interpolation
|
MaskInterpolationStr
|
Sampling mode for routed masks. |
'nearest'
|
Returns:
| Name | Type | Description |
|---|---|---|
list[object]
|
Flat list where each element is a :class: |
|
list[object]
|
(mixed/INTERP geometric run), an :class: |
|
list[object]
|
(EXACT-only geometric run; auxiliary targets remain flip-only), |
|
a |
list[object]
|
class: |
list[object]
|
PyTorch path), a :class: |
|
list[object]
|
run where the adapter supports |
|
list[object]
|
original transform object (passthrough for |
|
list[object]
|
|
|
list[object]
|
unsupported |
Protocols¶
Transform adapters¶
The protocol describes classification, parameter sampling, matrix building, exact execution, color-matrix building, and native passthrough. Conformance alone does not register an adapter with Compose.
TransformAdapter ¶
Bases: Protocol
Adapter between a backend transform and the fused affine engine.
Implementations bridge framework-specific transforms (Kornia, Albumentations, TorchVision) to the canonical parameter representation used by FusedAffineSegment.
Optional descriptive members (read via fuse_augmentations._backend.adapter_capabilities and direct
getattr, so absence is tolerated for backwards compatibility):
capabilities: frozenset[str]— canonical op names (see :data:~fuse_augmentations.resolver.SUPPORTED_OPS) the adapter can build.sampling_semantics: SamplingSemantics— whether the adapter draws one parameter set per sample or one per batch.
These are intentionally not declared as Protocol members: doing so would make @runtime_checkable
isinstance require them, breaking adapters that predate the attributes. Instead they are read defensively via
fuse_augmentations._backend.adapter_capabilities and getattr, so absence is tolerated. isinstance
therefore continues to check only the methods below.
category ¶
category(transform: object) -> TransformCategory
Return the TransformCategory of the given transform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transform
|
object
|
The backend transform object. |
required |
Returns:
| Type | Description |
|---|---|
TransformCategory
|
The category classification for the transform. |
sample_params ¶
sample_params(transform: object, input_shape: tuple[int, int, int, int], device: device) -> dict[str, Tensor]
Sample random parameters for a batch of images.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transform
|
object
|
The backend transform object. |
required |
input_shape
|
tuple[int, int, int, int]
|
(batch_size, channels, height, width) tuple. |
required |
device
|
device
|
Target device for parameter tensors. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Tensor]
|
Dict mapping canonical parameter names to (batch_size,) tensors. |
build_matrix ¶
Build a (batch_size, 3, 3) pixel-space forward affine matrix from sampled params.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transform
|
object
|
The backend transform object. |
required |
params
|
dict[str, Tensor]
|
Canonical-unit parameter dict from sample_params(). |
required |
height
|
int
|
Image height in pixels. |
required |
width
|
int
|
Image width in pixels. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Tensor of shape (batch_size, 3, 3). |
exact_flip_dims ¶
Return the tensor dimensions to flip for a GEOMETRIC_EXACT transform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transform
|
object
|
The backend transform object (must be GEOMETRIC_EXACT category). |
required |
Returns:
| Type | Description |
|---|---|
list[int]
|
List of dimension indices passed to |
list[int]
|
e.g. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the adapter does not support ExactAffineSegment. |
exact_apply ¶
Apply a GEOMETRIC_EXACT transform losslessly to an image batch.
Implementers must provide this method for adapters that are used with :class:ExactAffineSegment.
A typical implementation flips the image along the dims returned by :meth:exact_flip_dims.
Adapters that support non-flip discrete ops (e.g. 90-degree rotations, transposes) can instead dispatch via
torch.rot90, .permute, etc.
Warning
Implementations for stochastic discrete ops (RandomRotate90, D4) draw their own random
parameters internally, independent of :meth:sample_params. Never combine an exact_apply
image path with a :meth:sample_params-derived matrix for the SAME transform in one forward —
the two draws are unrelated and image vs coordinate outputs would diverge. Current segments keep
these paths mutually exclusive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transform
|
object
|
The backend transform object (GEOMETRIC_EXACT category). |
required |
image
|
Tensor
|
|
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Transformed |
call_nonfused ¶
Apply a non-fusible transform directly via its native backend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transform
|
object
|
The backend transform object. |
required |
image
|
Tensor
|
Input image tensor. |
required |
**kwargs
|
object
|
Additional keyword arguments forwarded to the transform. |
{}
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Transformed image tensor. |
build_color_matrix ¶
build_color_matrix(transform: object, params: dict[str, Tensor], mean: Tensor | None = None) -> Tensor
Build a (batch_size, 4, 4) homogeneous color-space affine matrix from sampled params.
Adapters that support POINTWISE_LINEAR fusion must override this method to return a (batch_size, 4, 4)
matrix encoding the per-channel linear colour transform (3x3 colour matrix + 3-element bias in homogeneous
form). The default implementation raises NotImplementedError so that adapters without colour-fusion
support fall back to passthrough segmentation automatically.
Accuracy caveats vs native backends (inherent to single-matrix fusion):
- No intermediate clamping: native backends clamp to
[0, 1]after EACH op; a fused matrix cannot represent clamping between ops, so out-of-gamut intermediates diverge from native. :class:~fuse_augmentations.affine.segment.FusedColorSegmentclamps only the FINAL result (clip_output=Truedefault). Seeclip_policyon :class:~fuse_augmentations.compose.FusedComposefor a per-op-parity split option. - Contrast midpoint: TorchVision/Kornia
ColorJittercontrast is relative to the per-image mean luminance (c' = cf*c + (1-cf)*luma_mean). Whenmeanis provided (the fused segment supplies the per-image luminance of the transform's input), that mean is used, matching native. WhenmeanisNone(a bare, out-of-context call), a fixed midpoint of0.5is used so the returned matrix is well-defined without an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transform
|
object
|
The backend transform object ( |
required |
params
|
dict[str, Tensor]
|
Canonical parameter dict from :meth: |
required |
mean
|
Tensor | None
|
Optional per-image luminance of the image reaching this transform, shape
|
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Tensor of shape |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the adapter does not support colour-space matrix fusion for this transform. |
build_lut ¶
Apply a POINTWISE_LUT transform's per-channel intensity map to a grid of values.
Adapters that support static POINTWISE_LUT fusion (gamma, solarize, posterize) must override
this to evaluate the transform's pointwise, per-channel scalar map on values using its
own backend function (never a re-derived formula), returning the mapped intensities. The
default implementation raises NotImplementedError so adapters without lookup-fusion
support fall back to passthrough segmentation automatically.
:class:~fuse_augmentations.affine.segment.FusedLUTSegment composes a contiguous run of
such ops by threading a domain grid through each op in order: values starts as a
uniform grid over [0, 1] and each op maps it in place, so after the run values
holds the composed function sampled on that grid — one lookup table applied once. Because
each op is evaluated exactly on the running values (not re-interpolated between ops), the
composition itself introduces no error.
Accuracy caveats vs native backends:
- uint8 / 256-entry path (exact). When the segment enumerates the map over all 256
byte values, the composed table is bit-exact against a native sequential chain: each op
is a deterministic
0..255 -> 0..255map and integer composition loses nothing. - float / K-entry interp path (approximate). For a floating image the composed table
is sampled on a uniform
K-point grid (defaultK = 1024) and applied bygather+ linear interpolation. This is exact-ish only for smooth maps: a steep region (e.g.gamma < 1near black) can differ from native by ~2 uint8 levels, and a discontinuous map (solarize threshold, posterize step) uses a detected sharp step instead of a linear ramp, but its inferred breakpoint can still differ by part of a grid cell. Do not claim the float path beats native precision; gate float-path parity at a documented interpolation tolerance, never as>=native.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transform
|
object
|
The backend transform object ( |
required |
params
|
dict[str, Tensor]
|
Canonical parameter dict from :meth: |
required |
values
|
Tensor
|
|
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Tensor of shape |
Tensor
|
transform's per-channel intensity map, clamped to |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the adapter does not support lookup-table fusion for this transform. |
Backend converters¶
Converters translate the pipeline's primary output representation. Coordinate-target conversion is deliberately separate from image layout conversion.
BackendConverter ¶
Bases: Protocol
Protocol for output format converters used with output_backend=.
Implementations convert the pipeline's native torch.Tensor output to a target backend format (e.g. NumPy
ndarray).
convert ¶
Convert tensor to target backend format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tensor
|
Any
|
The input tensor to convert. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Converted object in the target backend format. |
Experimental adapter registration¶
The private fuse_augmentations._backend module contains register_adapter and lazy loading for the fuse_augmentations.adapters entry-point group. This surface is explicitly experimental.
The current registry provides detection metadata. A default third-party adapter registered as Backend.UNKNOWN is not yet an end-to-end Compose execution path: composition dispatch only constructs one of the three built-in adapters. A production plugin should wait for a public contract with an integration test covering registration, construction, forward execution, and serialization.
Do not map a third-party adapter to a built-in backend enum as a workaround. Composition would retrieve the built-in adapter, not the registered third-party instance.
When to stay at the core API¶
Use Compose instead of direct segments when any of these are needed:
- mixed-backend routing;
- output conversion;
data_keysvalidation and assembly;- passthrough safety checks;
- structured plan descriptors;
- serialization compatibility;
- stable handling of future segment implementations.