U Ph"@sddlmZddlZddlZddlZddlmZddlmZddl m Z e d\Z Z ddd d d d gZ d ZdZdZdZeZdddiedeedddddediddddiidd Zdgdd d!d"d#d$d%d&d'd(d)d*d+d)d*d,d)d*d-d)d.d/gd0d1d2d3d4d5d6d7d8dd9d:d;id'dd?d@d=d>dAgd0dBdCdDdEdFidGgdHd.dIdFdJdKdLdMdNgdOZdPdQdRdSdTdRdUdVdRdWZedXdYdZdd>d[d\d]d^d_d`dad>d>dbdcd>dd d\d]d^d_d`d8ded\d]d^d_d`dad8d>dfdg dhZdieiZdjdjdkdkdldmdnZdS)o) annotationsN)Any)get_config_values)optional_importyaml ID_REF_KEY ID_SEP_KEYEXPR_KEY MACRO_KEYDEFAULT_MLFLOW_SETTINGSDEFAULT_EXP_MGMT_SETTINGS@z::$%z0.0.1zInitial versionMONAIPytorch+aNumpyz"Describe what the network predictszQA longer description of what the network does, use context, inputs, outputs, etc.zYour Name HerezCopyright (c) Your Name Here)inputsoutputs) version changelogZ monai_versionZpytorch_version numpy_versionZoptional_packages_versiontask descriptionauthors copyrightZnetwork_data_formatz $import globz?$torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')z"$@bundle_root + '/models/model.pt'z/workspace/dataz2$list(sorted(glob.glob(@dataset_dir + '/*.jpeg')))z???)_target_ spatial_dimsz$@network_def.to(@device)Compose LoadImagedimage)rkeysEnsureChannelFirstdScaleIntensityd EnsureTypedz@device)rr$device)r transformsDatasetz"$[{'image': i} for i in @datalist]z@preprocessing)rdata transform DataLoaderz@datasetF)rdataset batch_sizeshuffle num_workersrZ SimpleInferer ActivationsdpredT)rr$softmax AsDiscreted)rr$argmaxZCheckpointLoaderz$not os.path.exists(@ckpt_path)z @ckpt_pathmodelz@network)r _disabled_ load_path load_dictZSupervisedEvaluatorz @dataloaderz@infererz@postprocessingz @handlers)rr(Zval_data_loadernetworkinfererpostprocessingZ val_handlersz$@evaluator.run())Zimportsr( ckpt_path dataset_dirdatalistZ network_defr<Z preprocessingr/ dataloaderr=r>handlers evaluatorZ evaluatingz train#trainerztrain#handlers)idrCzvalidate#evaluatorzvalidate#handlersrDrC)trainer validatorrDz$@bundle_root + '/eval'z1$monai.utils.path_to_uri(@output_dir) + '/mlruns'Zmonai_experimentz}$torch.distributed.is_available() and torch.distributed.is_initialized() and torch.distributed.get_rank() > 0Z MLFlowHandlerz @is_not_rank0z @tracking_uriz@experiment_namez @run_namez@save_execute_config train_lossz1$monai.handlers.from_engine(['loss'], first=True)) rr9 tracking_uriexperiment_namerun_name artifacts iteration_logZ epoch_logZtag_nameZoutput_transformclose_on_complete)rr9rIrJrKrM)rr9rIrJrKrLrMrN) output_dirrIrJrKZsave_execute_configZ is_not_rank0rFrGrD)Z handlers_idconfigsmlflowstrr) bundle_path config_names load_kw_argsreturncOsddlm}|}tj|s.td|dtj|rg}|jfdtj|ddi||D]:}tj|d|}tj|std|d| |qb|j fd|i|ntj tj |\}} t |d } | } |d } | | kr|d } n|d } |d } t| | }|j|d|D]|}| |}|| krXtd|d| |}|drtj|f|}n|drtj|f|}|j |dq2|S)a Load the metadata and nominated configuration files from a MONAI bundle without loading the network itself. This function will load the information from the bundle, which can be a directory or a zip file containing a directory or a Torchscript bundle, and return the parser object with the information. This saves having to load the model if only the information is wanted, and can work on any sort of bundle format. Args: bundle_path: path to the bundle directory or zip file config_names: names of configuration files with extensions to load, should not be full paths but just name+ext load_kw_args: keyword arguments to pass to the ConfigParser object when loading Returns: ConfigParser object containing the parsed information r) ConfigParserz#Cannot find bundle file/directory ''frPz metadata.jsonzCannot find config file 'rz/configs/metadata.jsonz /configs/z/extra/metadata.jsonz/extra/)rYjson)rZyml)monai.bundle.config_parserrWospathexists ValueErrorisdirZ read_metajoinappend read_configsplitextbasenamezipfileZipFilenamelistr[loadsreadlowerendswithr safe_load)rSrTrUrWparserZ conf_datacnameZcpathname_archive all_filesZ zip_meta_nameprefixZ meta_jsonZ full_cnameZardatacdatarwG/home/dell461/cl/sdc2/HISourceFinder-master-l/src/monai/bundle/utils.pyload_bundle_configsD              ry) __future__rr[r]rgtypingrmonai.config.deviceconfigr monai.utilsrrrr__all__rrr r Z _conf_valuesrRsplitZDEFAULT_METADATAZDEFAULT_INFERENCEZDEFAULT_HANDLERS_IDr r ryrwrwrwrx s            6 4