PluginTransform

class PluginTransform(transforms: Mapping[str, Callable[[Tensor], Tensor]], **kwargs)

Bases: DictTransform

A class defining the transforms to be applied to TensorDict sampled from a DataPlugin.

This is a special case of a DictTransform, where the transforms are applied to the respective, same-name components of the TensorDict.

Example

>>> dtrafo = DictTransform({'c1': AnyIn(whitelist=[1, 2]), 'c2': AllPass()})
>>> value = {
...     'c1': torch.tensor([[1], [2], [3]]),
...     'c2': torch.tensor([[4], [5], [6]])
... }
>>> dtrafo(value)
{'c1': tensor([True, True, False]), 'c2': tensor([True, True, True])}
__call__(item: Dict[str, Tensor]) Dict[str, Tensor]

Given a TensorDict, applies the transforms to the same-name components and returns the transformed item.”

Parameters:

item (TensorDict) – A dictionary of tensors on which to apply the transforms.

Returns:

The dictionary item after applying the transforms to the same-name components.

Return type:

TensorDict

__init__(transforms: Mapping[str, Callable[[Tensor], Tensor]], **kwargs)

Given a mapping component_name : str -> trafo : TensorTransform, initializes a PluginTransform object.

Parameters:

transforms (Mapping[str, DictTransform]) – A mapping of keys to DictTransforms.