o  i @sdZddlmZddlmZmZmZddlZddl Z ddl m Z m Z ddl mZddlmZddlmZdd lmZmZdd lmZgd ZGd d d eeZGdddeeZeZZeZZdS)z A collection of dictionary-based wrappers for moving between MetaTensor types and dictionaries of data. These can be used to make backwards compatible code. Class names are ended with 'd' to denote dictionary-based transforms. ) annotations)HashableMappingSequenceN)KeysCollectionNdarrayOrTensor) MetaTensor)InvertibleTransform) MapTransform)PostFixTransformBackends)ensure_tuple_rep)FromMetaTensordFromMetaTensorDFromMetaTensorDict ToMetaTensord ToMetaTensorDToMetaTensorDictcsJeZdZdZejejejgZ ddfd d Z dddZ dddZ Z S)rz Dictionary-based transform to convert MetaTensor to a dictionary. If input is `{"a": MetaTensor, "b": MetaTensor}`, then output will have the form `{"a": torch.Tensor, "a_meta_dict": dict, "a_transforms": list, "b": ...}`. tensorFkeysr data_typeSequence[str] | strallow_missing_keysboolcs2t||tddt|t|jD|_dS)aD Args: keys: keys of the corresponding items to be transformed. See also: :py:class:`monai.transforms.compose.MapTransform` data_type: target data type to convert, should be "tensor" or "numpy". allow_missing_keys: don't raise exception if key is missing. css|]}|dkVqdS)rN).0drrj/home/dell461/cl/sdc2/last_ska_mid/HISourceFinder-master-l/src/monai/transforms/meta_utility/dictionary.py ?sz+FromMetaTensord.__init__..N)super__init__tupler lenras_tensor_output)selfrrr __class__rrr 4s $zFromMetaTensord.__init__data"Mapping[Hashable, NdarrayOrTensor]returndict[Hashable, NdarrayOrTensor]cCsXt|}|||jD]\}}||}||j||rtjntjd| ||q |S)N) output_type) dict key_iteratorr#updateas_dicttorchTensornpndarraypush_transform)r$r'rkeytimrrr__call__As  zFromMetaTensord.__call__cCsvt|}||D]/}|||}||}|t|d}|t|d}t|||d}|||<|||q |SN)metaapplied_operations) r,r-get_most_recent_transformpopr r: transformsr pop_transform)r$r'rr5_r7r:r>rrrinverseIs zFromMetaTensord.inverse)rF)rrrrrrr'r(r)r*) __name__ __module__ __qualname____doc__r TORCHNUMPYCUPYbackendr r8rA __classcell__rrr%rr*s rc@s4eZdZdZejejejgZd ddZ d dd Z d S) rz Dictionary-based transform to convert a dictionary to MetaTensor. If input is `{"a": torch.Tensor, "a_meta_dict": dict, "b": ...}`, then output will have the form `{"a": MetaTensor, "b": MetaTensor}`. r'r(r)r*cCsjt|}||D])}|||||}|t|d}|t|d}t|||d}|||<q |Sr9)r,r-r4r=r r:r>r)r$r'rr5r7r:r>rrrr8cs  zToMetaTensord.__call__cCsLt|}||D]}|||}||}||||||q |S)N)r,r-r<r.r/r?)r$r'rr5r@r7rrrrAns zToMetaTensord.inverseNrB) rCrDrErFr rGrHrIrJr8rArrrrrYs   r)rF __future__rcollections.abcrrrnumpyr2r0monai.config.type_definitionsrrmonai.data.meta_tensorrmonai.transforms.inverser monai.transforms.transformr monai.utils.enumsr r monai.utils.miscr __all__rrrrrrrrrrs       /"