U PhB @sddlmZddlZddlmZddlmZmZddlm Z dddgZ dd d d ddddZ dddddZ d d dddZ dS)) annotationsN) BundleAlgo)algo_from_picklealgo_to_pickle)AlgoKeysimport_bundle_algo_historyexport_bundle_algo_historyget_name_from_algo_id.Tstrz str | Noneboollist) output_folder template_path only_trainedreturnc Csg}tt|D]}tj||}tj|s2qtj|d}tj|sNqt||d\}}|t j d} | dkrz | } Wnt k rYnX| dk } |r| s|s| t j|t j|t j | t j| iq|S)a import the history of the bundleAlgo objects as a list of algo dicts. each algo_dict has keys name (folder name), algo (bundleAlgo), is_trained (bool), Args: output_folder: the root path of the algorithms templates. template_path: the algorithm_template. It must contain algo.py in the follow path: ``{algorithm_templates_dir}/{network}/scripts/algo.py``. only_trained: only read the algo history if the algo is trained. zalgo_object.pklrN)sortedoslistdirpathjoinisdirisfilergetrSCORE get_score BaseExceptionappendIDALGO IS_TRAINED) rrrhistorynameZ write_path obj_filenamealgoalgo_meta_data best_metric is_trainedr)O/home/dell461/cl/sdc2/HISourceFinder-master-l/src/monai/apps/auto3dseg/utils.pyrs*    zlist[dict[str, BundleAlgo]]None)r"rcCs&|D]}|tj}t||jdqdS)z Save all the BundleAlgo in the history to algo_object.pkl in each individual folder Args: history: a List of Bundle. Typically, the history can be obtained from BundleGen get_history method rN)rr rr)r" algo_dictr%r)r)r*rDs )idrcCs|ddS)z Get the name of Algo from the identifier of the Algo. Args: id: identifier which follows a convention of "name_fold_other". Returns: name of the Algo. _r)split)r-r)r)r*r Ps )r NT) __future__rrmonai.apps.auto3dseg.bundle_genrmonai.auto3dsegrrmonai.utils.enumsr__all__rrr r)r)r)r* s    -