Skip to content
abstract

Transform

extendsABC
Transform(p: float = 1.0)

Abstract base for a transform parameterized by its sample-params P.

Parameters

pfloat= 1.0
Probability 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

2
dunder

__init__

→None
__init__(p: float = 1.0)
dunder

__call__

→object
__call__(inputs: object)

Transform a tensor, a typed target, or a nested sample.

Instance methods

1
abstract

make_params

→P
make_params(img: Tensor)

Sample the per-call parameters from the reference image.