vis4d.data.transforms.base

Basic data augmentation class.

Functions

compose(transforms)

Compose transformations.

Classes

RandomApply(*[, in_keys, out_keys, sensors, ...])

Randomize the application of a given set of transformations.

Transform(in_keys, out_keys[, sensors, ...])

Transforms Decorator.

class RandomApply(*, in_keys=['data'], out_keys=['data'], sensors=None, same_on_batch=True, **kwargs)[source]

Randomize the application of a given set of transformations.

__call__(batch)[source]

Apply transforms with a given probability.

Return type:

list[Dict[str, Any]]

class Transform(in_keys, out_keys, sensors=None, same_on_batch=True)[source]

Transforms Decorator.

This class stores which in_keys are input to a transformation function and which out_keys are overwritten in the data dictionary by the output of this transformation. Nested keys in the data dictionary can be accessed via key.subkey1.subkey2 If any of in_keys is ‘data’, the full data dictionary will be forwarded to the transformation. If the only entry in out_keys is ‘data’, the full data dictionary will be updated with the return value of the transformation. For the case of multi-sensor data, the sensors that the transform should be applied can be set via the ‘sensors’ attribute. By default, we assume a transformation is applied to all sensors. This class will add a ‘apply_to_data’ method to a given Functor which is used to call it on a DictData object. NOTE: This is an issue for static checking and is not recognized by pylint. It will usually be called in the compose() function and will not be called directly.

Example

>>> @Transform(in_keys="images", out_keys="images")
>>> class MyTransform:
>>>     def __call__(images: list[np.array]) -> list[np.array]:
>>>         images = do_something(images)
>>>         return images
>>> my_transform = MyTransform()
>>> data = my_transform.apply_to_data(data)

Creates an instance of Transform.

Parameters:
  • in_keys (Sequence[str] | str) – Specifies one or multiple (if any) input keys of the data dictionary which should be remapeed to another key. Defaults to None.

  • out_keys (Sequence[str] | str) – Specifies one or multiple (if any) output keys of the data dictionary which should be remaped to another key. Defaults to None.

  • sensors (Sequence[str] | str | None, optional) – Specifies the sensors this transformation should be applied to. If None, it will be applied to all available sensors. Defaults to None.

  • same_on_batch (bool, optional) – Whether to use the same transformation parameters to all sensors / view. Defaults to True.

__call__(transform)[source]

Add in_keys / out_keys / sensors / apply_to_data attributes.

Parameters:

transform (TFunctor) – A given Functor.

Returns:

The decorated Functor.

Return type:

TFunctor

compose(transforms)[source]

Compose transformations.

This function composes a given set of transformation functions, i.e. any functor decorated with Transform, into a single transform.

Return type:

Callable[[list[Dict[str, Any]]], list[Dict[str, Any]]]