U Ph @sdZddlmZddlmZmZmZddlZddl Z ddl m Z m Z ddl mZddlmZddlmZdd lmZmZdd lmZd d d dddgZGdd 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_repFromMetaTensordFromMetaTensorDFromMetaTensorDict ToMetaTensord ToMetaTensorDToMetaTensorDictcs\eZdZdZejejejgZdddddfdd Z d d d d dZ d d d ddZ 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": ...}`. tensorFrzSequence[str] | strbool)keys data_typeallow_missing_keyscs2t||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).0drr]/home/dell461/cl/sdc2/HISourceFinder-master-l/src/monai/transforms/meta_utility/dictionary.py ?sz+FromMetaTensord.__init__..N)super__init__tupler lenras_tensor_output)selfrrr __class__rrr4s zFromMetaTensord.__init__"Mapping[Hashable, NdarrayOrTensor]dict[Hashable, NdarrayOrTensor]datareturncCsXt|}|||jD]<\}}||}||j||r:tjntjd| ||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) __name__ __module__ __qualname____doc__r TORCHNUMPYCUPYbackendrr8rA __classcell__rrr$rr*s c@s@eZdZdZejejejgZdddddZ dddddZ 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(cCsjt|}||D]R}|||||}|t|d}|t|d}t|||d}|||<q|Sr9)r,r-r4r=r r:r>r)r#r)rr5r7r:r>rrrr8cs  zToMetaTensord.__call__cCsLt|}||D]4}|||}||}||||||q|S)N)r,r-r<r.r/r?)r#r)rr5r@r7rrrrAns zToMetaTensord.inverseN) rBrCrDrEr rFrGrHrIr8rArrrrrYs )rE __future__rcollections.abcrrrnumpyr2r0monai.config.type_definitionsrrmonai.data.meta_tensorrmonai.transforms.inverser monai.transforms.transformr monai.utils.enumsr r monai.utils.miscr __all__rrrrrrrrrr s*      /"