Skip to content

Quickstart

Start with the native builder. It needs no Kornia, TorchVision, or Albumentations installation and makes the package's actual input contract explicit: a floating BCHW tensor.

import torch

from fuse_augmentations import Compose, ReorderPolicy

torch.manual_seed(7)

augment = Compose.from_params(
    rotation=(-15.0, 15.0),
    scale=(0.9, 1.1),
    translate_x=(-8.0, 8.0),
    hflip_p=0.5,
    reorder=ReorderPolicy.NONE,
)

images = torch.rand(4, 3, 128, 128, dtype=torch.float32)
augmented, matrix = augment(images, return_matrix=True)

assert augmented.shape == images.shape
assert augmented.dtype == images.dtype
assert matrix is not None and matrix.shape == (4, 3, 3)

print(augment.fusion_plan)
print(augment.n_warps_saved)
Quickstart fusion plan and saved warp count
fused(_DirectParamTransform, _DirectFlipTransform)
1

return_matrix=True is unambiguous here because this pipeline has one matrix-producing segment. In a pipeline with backend changes, projective boundaries, or passthrough operations, the returned matrix represents only the last matrix-producing segment.

What this example guarantees

  • Rotation, scale, translation, and the supported flip are sampled independently per image on the direct-parameter path.
  • Compatible geometry is represented in homogeneous pixel-space matrices.
  • The declared order is preserved because ReorderPolicy.NONE is explicit.
  • Output remains a BCHW tensor on the same torch device.

It does not guarantee pixel identity with any native backend. Native libraries may use different centers, fill rules, interpolation kernels, clipping, or random-number streams.

Inspect before you benchmark

Use the plan to confirm that your intended operations formed a useful segment:

for segment in augment.fusion_plan_descriptors:
    print(segment.kind, segment.transforms, segment.backend, segment.split_reason)
Quickstart segment kind, transforms, backend, and split reason
fused ('_DirectParamTransform', '_DirectFlipTransform') None None

Fewer planned resampling passes are structural. Faster execution is not: benchmark the exact device, image shape, batch size, dtype, and transform mix. See Benchmarks.

Next steps