deepali.data.transforms.item
#
Generic wrappers and mix-ins for data transforms.
Module Contents#
Classes#
Transform only specified item/field of dict, named tuple, tuple, list, or dataclass. |
|
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]#
-
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’, applytransform
to all items in the inputdata
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 bykey
is replaced by its transformed value. IfTrue
, a deep copy of all inputdata
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 ofself.key
replaced by its transformed value. Ifself.key is None
, all values in the inputdata
are transformed. By default, a shallow copy ofdata
is made unlessself.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.