Skip to content
abstract

TransformsPreset

extends_NoParamsTransform[Empty]ABC
TransformsPreset(p: float = 1.0)

Abstract base for task-specific preprocessing presets.

A preset is a thin wrapper over an internal Compose pipeline (assembled in __init__ from the preset's task- specific defaults) plus a serialisation contract. Subclasses must:

  1. Set the preset_type class variable to a unique short string used in config.json.
  2. Declare the constructor's typed kwargs (no **kwargs — enforces the schema explicitly).
  3. Build self._pipeline (a Compose) inside __init__.
  4. Implement _init_kwargs returning the dict of constructor arguments needed to reconstruct an identical instance.

Parameters

pfloat= 1.0
Probability of applying the transform; otherwise the input passes through unchanged.

Attributes

preset_typeClassVar[str]
Short identifier (e.g. "ImageClassification") used as the preprocessor_type key in to_dict / from_dict.

Examples

The base of the ready-made pipelines — ImageClassification,
ImageClassificationAugment, Detection,
Segmentation, Pose, VideoClassification.
Each is the preprocessing its task expects, so a caller reaches for
one rather than assembling resize, crop and normalise by hand:
>>> import lucid.utils.transforms as T
>>> sorted(c.__name__ for c in T.TransformsPreset.__subclasses__())
['Detection', 'ImageClassification', 'ImageClassificationAugment', 'Pose', 'Segmentation', 'VideoClassification']

Used by 1

Constructors

1
dunder

__call__

→object
__call__(inputs: object)

Class methods

1
cls

from_dict

→TransformsPreset
from_dict(cfg: dict[str, object])

Reconstruct a preset instance from a to_dict payload.

When called on the base TransformsPreset, dispatches to the registered subclass named by cfg["preprocessor_type"]; when called on a concrete subclass, verifies the key matches and constructs that subclass directly.

Parameters

cfgdict
{"preprocessor_type": ..., "init_kwargs": {...}}.

Returns

TransformsPreset

New instance of the named subclass.

Raises

KeyError
If preprocessor_type is not in the registry.
ValueError
If cfg is missing required keys or preprocessor_type disagrees with the class from_dict was called on.

Instance methods

2
fn

make_params

→Emptyfrom _NoParams
make_params(img: Tensor)
fn

to_dict

→dict
to_dict()

Serialise the preset to a JSON-friendly dict.

Mirrors Hugging Face's preprocessor_config.json shape: {"preprocessor_type": <class-key>, "init_kwargs": {…}}.

Returns

dict

Two-key dict suitable for json.dump and AutoTransformsPreset.from_dict round-trip.

Dunder methods

1