Abstract base for a transform parameterized by its sample-params P.
Parameters
pfloat= 1.0Probability of applying the transform; otherwise the input
passes through unchanged.
Examples
Every transform here is one of these. Subclassing means supplying
apply for each target the transform touches — an image, a mask,
boxes, keypoints — and inheriting the probability handling, the
parameter sampling and the composition machinery:
>>> import lucid, lucid.utils.transforms as T
>>> class Halve(T.Transform):
... def make_params(self, img):
... return {}
... def _apply_image(self, img, params):
... return img * 0.5
>>> tuple(Halve(p=1.0)(T.Image(lucid.rand(3, 8, 8))).data.shape)
(3, 8, 8)
Two methods, not one. make_params samples whatever this call
decides — an angle, a crop box — and is handed the image so it can
sample against its size; _apply_image is then given the same
parameters, which is what keeps a random transform consistent across
everything in one sample. A geometric transform needs three more —
_apply_mask, _apply_boxes and _apply_keypoints — because
it has to carry the same change through to whatever travels beside
the image.Used by 4
Constructors
2Wrap fn so it satisfies the nn.Module contract.
Parameters
fncallableThe plain callable the user passed to
compile.
Stored unwrapped; invoked verbatim on every forward.Transform a tensor, a typed target, or a nested sample.