get_transform

class get_transform(trafo_config: DictConfig, custom={})

Bases:

Initializes a supported transform instance from a DictConfig object.

The DictConfig object should contain the following keys:

  1. name: The name of the transform to initialize

  2. __init__: The name of the classmethod to use for initialization (optional)

  3. arg1: The first argument to pass to the transform (optional)

  4. arg2: The second argument to pass to the transform (optional)

Examples

Example 1: Consider the following DictConfig configuration for a normalization transformation expressed in YAML:

name: normalize
mean: (0.0, 0.5)
std: (0.278, 1.023)
inplace: false

This is equivalent to:

lambda x: normalize(x,
    mean=(0.0, 0.5),
    std=(0.278, 1.023),
    inplace=False
)

Example 2: Consider the following DictConfig configuration for a normalization transformation expressed in YAML:

name: Normalize
__init__: __init__
mean: (0.0, 0.5)
std: (0.278, 1.023)
inplace: false

This is equivalent to:

Normalize(
    mean=(0.0, 0.5),
    std=(0.278, 1.023),
    inplace=False
)
Parameters:
  • transform (DictConfig) –

    A dictionary configuration providing the name of the transform object and arguments to pass at initialization. The name can refer to

    1. a method (e.g. torchvision.transforms.normalize) or

    2. a callable class (e.g. torchvision.transforms.Normalize).

    In the second case, you can also pass the '__init__' parameter as part of the config to specify what classmethod to use for initialization. Default: '__init__'.

  • custom (dict, optional) – A dict mapping name -> transform, where the transform is a custom transform defined outside the scope of the UDM, by default {}

Raises:

KeyError – If the name provided for the transform does not correspond to any known module

Note

If the name of a transform refers to a function, its signature MUST satisfy the following pattern: [torch.Tensor, *args] -> torch.Tensor.