deepali.data.transforms.item#

Generic wrappers and mix-ins for data transforms.

Module Contents#

Classes#

ItemTransform

Transform only specified item/field of dict, named tuple, tuple, list, or dataclass.

ItemwiseTransform

Mix-in for data preprocessing and augmentation transforms.

class ItemTransform(transform: Callable, key: Optional[Union[int, str, collections.abc.KeysView, Iterable[Union[int, str]]]] = None, copy: bool = False, ignore_meta: bool = True, ignore_missing: bool = False)[source]#
Inheritance diagram of deepali.data.transforms.item.ItemTransform

Transform only specified item/field of dict, named tuple, tuple, list, or dataclass.

Initialize item transformation.

Parameters
  • transform – Item value transformation.

  • key – Index, key, or field name of item to transform. If None, empty string, or ‘all’, apply transform to all items in the input data object. Can be a nested key with dot (‘.’) character as subkey delimiters, and contain indices to access list or tuple items. For example, “a.b.c”, “a.b.2”, “a.b.c[1]”, “a[1][0]”, “a[0].c”, and “a.0.c”, are all valid keys as long as the data to transform has the appropriate entries and (nested) container types.

  • copy – Whether to copy all input items. By default, a shallow copy of the input data is made and only the item specified by key is replaced by its transformed value. If True, a deep copy of all input data items is made.

  • ignore_missing – Whether to skip processing of items with value None.

  • ignore_meta – Preserve ‘meta’ dictionary key value as is (cf. MetaDataset).

forward(data: Any) Any[source]#

Apply transformation.

Parameters

data – Input value, dict, tuple, list, or dataclass.

Returns

Copy of data with value of self.key replaced by its transformed value. If self.key is None, all values in the input data are transformed. By default, a shallow copy of data is made unless self.copy == True.

class ItemwiseTransform[source]#

Mix-in for data preprocessing and augmentation transforms.

classmethod item(key: Union[int, str, collections.abc.KeysView, Iterable[Union[int, str]]], *args, ignore_meta: bool = True, ignore_missing: bool = False, **kwargs) ItemTransform[source]#

Apply transform to specified item only.