U ®PÓh ã@sVddlmZddlmZmZddlmZddlmZddl m Z dddd œd d „Z d S) é)Ú annotations)ÚCallableÚHashable)ÚAny)ÚKeysCollection©Ú ensure_tuplerÚstrzCallable[[Any], Any])ÚkeysÚ nested_keyÚreturncst|ƒ‰‡‡fdd„}|S)aÑ Since the output of HoVerNet is a dictionary, this function is to extend `monai.handlers.from_engine` to work with HoVerNet. If data is a list of nested dictionaries after decollating, extract nested value with expected keys and construct lists respectively, for example, if data is `[{"A": {"C": 1, "D": 2}, "B": {"C": 2, "D": 2}}, {"A": {"C": 3, "D": 2}, "B": {"C": 4, "D": 2}}]`, from_engine_hovernet(["A", "B"], "C"): `([1, 3], [2, 4])`. Here is a simple example:: from monai.handlers import MeanDice, from_engine_hovernet metric = MeanDice( include_background=False, output_transform=from_engine_hovernet(keys=["pred", "label"], nested_key=HoVerNetBranch.NP.value) ) Args: keys: specified keys to extract data from dictionary or decollated list of dictionaries. nested_key: specified key to extract nested data from dictionary or decollated list of dictionaries. csntˆtƒr"t‡‡fdd„ˆDƒƒStˆtƒrjtˆdtƒrj‡‡fdd„ˆDƒ}t|ƒdkrbt|ƒS|dSdS)Nc3s|]}ˆ|ˆVqdS)N©)Ú.0Úk©Údatar r úX/home/dell461/cl/sdc2/HISourceFinder-master-l/src/monai/apps/pathology/handlers/utils.pyÚ 1sz9from_engine_hovernet.._wrapper..rcs g|]‰‡‡fdd„ˆDƒ‘qS)csg|]}|ˆˆ‘qSr r )rÚi)rr r rÚ 4szEfrom_engine_hovernet.._wrapper...r )rr)rrr4sz:from_engine_hovernet.._wrapper..é)Ú isinstanceÚdictÚtupleÚlistÚlen)rÚret©Ú_keysr )rrÚ_wrapper/s  z&from_engine_hovernet.._wrapperr)r r rr rrÚfrom_engine_hovernetsr N) Ú __future__rÚcollections.abcrrÚtypingrÚ monai.configrÚ monai.utilsrr r r r rÚ s