Compose
Run several transforms in order, threading one generator through them.
One generator, not one each: two transforms seeded independently draw the same numbers whenever their call counts line up, which is the classic way correlated "randomness" gets into an augmentation pipeline.
Three transforms ship, not a library. Compose, RandomHorizontalFlip and RandomCrop are the standard CIFAR augmentation, and between them they exercise every part of the contract: composition, a per-sample random decision, and a shape-changing spatial operation. Anything else is a five-line function with the same signature, and a transform zoo would be a maintenance surface built ahead of a user.
Every shipped transform decides per sample, not per batch. A flip that draws one coin for the whole batch is not augmentation — it doubles the dataset instead of multiplying it, and it correlates every sample in a step.
How that decision is applied was decided by measurement, and the usual rule lost. "Vectorise, never loop in Python" gave a crop 3.8× slower than sixty-four contiguous slices and a flip 3.3× slower than reversing only the chosen rows — both because the vectorised form does the work for samples it then discards. The output is byte-identical either way; only the cost differs.
Construction¶
__init__¶
Call¶
__call__¶
Internals¶
__repr__¶
See also DataLoader, ArrayDataset