Copy#
- class Copy(keys_dict=None)[source]#
Bases:
objectDuplicate keys in the sample dict under new names.
For each
source -> destinationentry, deep-copiesdata_dict[source]intodata_dict[destination]in place. Numpy arrays are.copy()-ed, torch tensors are.clone().detach()-ed, and anything else iscopy.deepcopy-ed, so the destination is independent of the source. The two canonical uses are preserving a pristine copy of a key before augmentation mutates it (e.g.coord -> origin_coordfor test-time re-mapping) and remapping a dataset-specific label into the conventionalsegmentname (e.g.segment_motif -> segment). Returns the samedata_dict. Registered asCopy– use this string as thetypein atransform=[...]config list.- Parameters:
keys_dict (dict, optional) – mapping of source key to destination key. Each source must already exist in the sample. Defaults to
dict(coord="origin_coord", segment="origin_segment").
Note
Requires every source key to be present in
data_dict.Example
>>> import numpy as np >>> from pimm.datasets.transform import Copy >>> data = {"segment_motif": np.array([2, 3, 2])} >>> out = Copy(keys_dict={"segment_motif": "segment"})(data) >>> sorted(out) # source remains; an independent "segment" copy is added ['segment', 'segment_motif'] >>> out["segment"] array([2, 3, 2])