o % i]@sXddlmZddlZddlZddlZddlZddlZddlZddlZddl m Z m Z ddl m Z ddlmZddlmZddlmZddlmZdd lmZmZddlZdd lmZdd lmZdd lmZm Z m!Z!m"Z"dd l#m$Z$ddl%m&Z&m'Z'm(Z(ddl)m*Z*m+Z+ddl,m-Z-ddl.m/Z/m0Z0ddl1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7ddl8m9Z9m:Z:m;Z;mZ>m?Z?e>ddd\Z@ZAe>ddd\ZBZAe>de9jCe=d\ZDZEe>d\ZFZGe>d\ZHZAe>d\ZIZAe"eJdZKejLMdd ZNd!ZOd"ZPd#ZQddd-d.ZReRZSdd1d2ZTdd6d7ZUdd:d;ZVdddCdDZWddIdJZXddMdNZYddPdQZZddRdSZ[ddTdUZ\dd dYdZZ]d d[d\Z^d d]d^Z_d d dbdcZ`d d dddeZad ddidjZb _ _ $dddmdnZc _ _ dddodpZdddqdrZeddudvZfddydzZgddd~dZhddddZidddZjd dddZkdddeNddd_d$df dddZlddddddeNdd_d$dddddddfdddZm ddddZn dd ddZo dd!ddZp  d"d#ddZq        d$d%ddZr dd&ddZs      d'd(ddÄZtd)d*ddȄZud+dd˄Zv         d,d-ddЄZwd.ddքZx          d/d0dd݄Zy          d/d0dd߄Zz                d1d2ddZ{    d3d4ddZ|ddZ}  $  d5d6ddZ~   d7d8ddZdd9ddZdS(:) annotationsN)MappingSequence)partial)Path)locate)copyfile)dedent)AnyCallable) is_available) get_versions) _basename download_url extractall get_logger) ConfigParser)DEFAULT_INFERENCEDEFAULT_METADATAmerge_kv)BundleWorkflowConfigWorkflow)PathLike)load_net_with_metadatasave_net_with_metadata)convert_to_onnxconvert_to_torchscriptconvert_to_trtcopy_model_stateget_state_dict save_state) IgniteInfocheck_parent_dir ensure_tupleget_equivalent_dtype min_versionoptional_import pprint_edgesZ jsonschemavalidatenamezjsonschema.exceptionsValidationErrorzignite.handlers Checkpointrequestsonnxhuggingface_hub) module_nameZBUNDLE_DOWNLOAD_SRC monaihostingz8https://api.ngc.nvidia.com/v2/models/nvidia/monaihostingz8https://api.ngc.nvidia.com/v2/models/nvidia/monaitoolkitTargsstr | dict | None ignore_noneboolkwargsr returndictcKst|tr|ni}t|trt|}t|ttfr7tdd|Dr7|\}}t||fit||fi|}t|ts>|S| D],\}}|rM|durMqBt|trht| |trht|||fi|||<qBt |||qB|S)a% Update the `args` dictionary with the input `kwargs`. For dict data, recursively update the content based on the keys. Example:: from monai.bundle import update_kwargs update_kwargs({'exist': 1}, exist=2, new_arg=3) # return {'exist': 2, 'new_arg': 3} Args: args: source `args` dictionary (or a json/yaml filename to read as dictionary) to update. ignore_none: whether to ignore input args with None value, default to `True`. kwargs: key=value pairs to be merged into `args`. css|]}t|tVqdSN) isinstancestr).0xr?V/home/dell461/cl/sdc2/last_ska_mid/HISourceFinder-master-l/src/monai/bundle/scripts.py `sz update_kwargs..N) r;r9r<rload_config_filetuplelistall update_kwargsitemsgetr)r3r5r7args_primary overrideskvr?r?r@rFKs      rFsrcrCcs,tfdd|Dfdd|DS)z{ Pop args from the `src` dictionary based on specified keys in `args` and (key, default value) pairs in `kwargs`. csg|]}|qSr?pop)r=irNr?r@ xsz_pop_args..csg|] \}}||qSr?rOr=rLrMrRr?r@rSx)rCrG)rNr3r7r?rRr@ _pop_argsss,rVtagr<Nonec CsNtd|d|D]\}}td|dt|tq tddS)Nz*--- input summary of monai.bundle.scripts.z ---z> z: z--- )loggerinforGr'PPRINT_CONFIG_N)rWr3r*valr?r?r@_log_input_summary{sr]expr list[str]cCst|}ddt|DS)z Parse the expression and discover what variables are present in it based on ast module. Args: expr: source expression to parse. cSsg|] }t|tjr|jqSr?)r;astNameid)r=mr?r?r@rSsz"_get_var_names..)r`parsewalk)r^treer?r?r@_get_var_namess rgshapeSequence[str | int]pintnanycCsg}|D]G}t|tr||qt|tr?|dkr ||qt|D]}|dvr2td|dq$|t|||dqtdt|d|dt|S)a2 Get spatial shape for fake data according to the specified shape pattern. It supports `int` number and `string` with formats like: "32", "32 * n", "32 ** p", "32 ** p *n". Args: shape: specified pattern for the spatial shape. p: power factor to generate fake data shape if dim of expected shape is "x**p", default to 1. p: multiply factor to generate fake data shape if dim of expected shape is "x*n", default to 1. any: specified size to generate fake data shape if dim of expected shape is "*", default to 1. *)rkrmz4only support variables 'p' and 'n' so far, but got: .z4spatial shape items must be int or string, but got:  ) r;rlappendr<rg ValueErrorevaltyperC)rirkrmrnretrQcr?r?r@_get_fake_spatial_shapes      rx repo_owner repo_nametag_namefilenamecCsd|d|d|d|S)Nzhttps://github.com//z/releases/download/r?)ryrzr{r|r?r?r@_get_git_release_urlsr~ model_nameversioncCstd|d|dS)Nr} /versions/z/files) NGC_BASE_URLlowerrrr?r?r@_get_ngc_bundle_urlsrrepocCs d|dS)Nzhttps://api.ngc.nvidia.com/v2/z/modelsr?)rr?r?r@_get_ngc_private_base_urls rcCst|d|d|dS)Nr}rz/zip)rrrrrr?r?r@_get_ngc_private_bundle_urlsrc Cs&td|d|d|d|d S)Nr}rz/files/_v.zip)MONAI_HOSTING_BASE_URLrrr?r?r@_get_monaihosting_bundle_urls&r download_pathrprogressc Cs\|d\}}}d|vr|d7}t||||d}||}t||d|dt||dddS)Nr}r)r{r|urlfilepathhash_valrTr output_dirhas_base)splitr~rr) rrr|rryrzr{rrr?r?r@_download_from_githubs rcCsBt||d}||d|d}t||d|dt||dddS)NrrrrTr)rrr)rr|rrrrr?r?r@_download_from_monaihostings rcCsdt||d}|std|d|d|d}||d|d}t||d|dt||d d dS) N) bundle_namerzBundle info not found for z vrpbrowser_download_urlrrrTr)get_bundle_inforsrr)rr|rr bundle_inforrr?r?r@_download_from_bundle_infos rmonai_r*prefixcCs||r|S||Sr:) startswithr*rr?r?r@_add_ngc_prefixs  rcCs||r |t|dS|Sr:)rlenrr?r?r@_remove_ngc_prefixs r request_urlheaders dict | NonecCsntstd|dur in|}tj||d}|t|j}t|t r(d|vr,td|d}dd|DS)N0requests package is required, please install it.rZ modelFileszFThe data is not a dictionary or it does not have the key 'modelFiles'.cSg|]}|dqS)pathr?)r=fr?r?r@rSz+_get_all_download_files..) has_requestsrsr-rHraise_for_statusjsonloadstextr;r9)rrresponse model_infoZ model_filesr?r?r@_get_all_download_filess r remove_prefix str | Nonec Cstt||d}t||d}|rt||d}||}|jdddt|D]}t|d||d|d|dq#dS)NrrT)parentsexist_okr}r)rrrmkdirrr) rr|rrrrrrfiler?r?r@_download_from_ngcs   &rc Cs t||d}t|||d}tr#|durin|}tj||d}|ntdtj|dd||d|d} t | d } | |j Wdn1sNwYt d | d |rdt||d}||} t| d } | | t d | d WddS1swYdS)Nrrrz5NGC API requires requests package. Please install it.T)rrrwbz Downloading: rprzWriting into directory: )rrrr-rHrrsosmakedirsopenwritecontentrYrZrzipfileZipFiler) rr|rrrrrrrzip_pathr extract_pathzr?r?r@_download_from_ngc_privates(      "rcCstd}dd|d}tr8tj||d}|js0|dkr,td|d|d t||d Std |d }|Sd S)zTry to connect to NGC.z*https://authn.nvidia.com/token?service=ngczapplication/jsonzApiKey )Accept Authorizationrz Retrying z time(s) to GET rprhz0NGC API response is not ok. Failed to get token.tokenN) rr-rHokrYrZ_get_ngc_token RuntimeErrorr)api_keyretryrrrrr?r?r@r(s r monai_versiontuple[bool, str]cCsht}|dd}|dkrdS|dkrdStdd|}tdd|}||kr2dd|d |d fSd S) zTExamine if the package version is compatible with the MONAI version in the metadata.r 0+unknown)Fz9Package version is not available. Skipping version check.)FzEMONAI version is not specified in the bundle. Skipping version check.zrc\d.*FzYour MONAI version is z+, but the bundle is built on MONAI version rp)Tr)r rHresub)r version_dictZpackage_versionr?r?r@_examine_monai_version9s r bundle_dirrcCst||dd}|std|ddSt| }t|}Wdn1s-wYt|dd\}}|sEt|dSdS)zvGet the `monai_version` from the metadata.json and compare if it is smaller than the installed `monai` package versionconfigs metadata.jsonzmetadata file not found in rpNrr) rexistsrYwarningrrloadrrH)rr*Z metadata_filermetadata is_compatiblemsgr?r?r@_check_monai_versionLs  rrdata max_versionscCst|tr d|vr td|d}t|tr(t|dks(d|dvs(d|dvr,tdt|ddd d }d d |d |DS)a* Extract the latest versions from the data dictionary. Args: data: the data dictionary. max_versions: the maximum number of versions to return. Returns: versions of the latest models in the reverse order of creation date, e.g. ['1.0.0', '0.9.0', '0.8.0']. Z modelVersionszIThe data is not a dictionary or it does not have the key 'modelVersions'.r createdDate versionIdzlThe model versions are not a list or it is empty or it does not have the keys 'createdDate' and 'versionId'.cSs|dS)Nrr?r>r?r?r@vsz'_list_latest_versions..T)keyreversecSr)rr?)r=rMr?r?r@rSwrz)_list_latest_versions..N)r;r9rsrDrsorted)rrZmodel_versionsZsorted_versionsr?r?r@_list_latest_versionsYs    rcCs|rt|nt}|d|d}tstdddi}|r#||tj||d}|t |j }t |}|D]B} |d|d| d} tj| |d}t |j } |t | d\} } | r|| |d krxtd |d d | d | Sq:|d S) Nr}rrzAccept-Encodingz gzip, deflaterz/files/configs/metadata.jsonrrzLatest version is z , but the compatible version is rp)rrrrrsupdater-rHrrrrrrrYrZ)r*rrbase_urlZversion_endpointZversion_headerresprZlatest_versionsrZ file_endpointrr_r?r?r@_get_latest_bundle_version_ngczs.    rsource'dict[str, list[str] | str] | Any | Nonec Ks|dkr t|}t|S|dkrt|ddddS|dkr.|di}t|}t|||d S|d krH|d \}}}t||d ||ddS|d kr|tj|d }t|jdkrpdd|jD} d| vrgdn| dgd} | Sdd|j Dd} | St d|d)Nngcr1Project-MONAI/model-zoodev)rrWlatest_version ngc_privater)rrgithubr}r/)repo_idrcSg|]}|jqSr?r))r=tr?r?r@rSz._get_latest_bundle_version..cSrr?r))r=br?r?r@rSrzZTo get the latest bundle version, source should be 'github', 'monaihosting' or 'ngc', got rp) rrget_bundle_versionsrPrr/Zlist_repo_refsrtagsZbranchesrs) rr*rr7rryrzr{refs all_versionsrr?r?r@_get_latest_bundle_versions.   rPathLike | NonecCsB|durtddd\}}|rt|d}t|Stdt|S)Nz torch.hubget_dirr)bundlezVbundle_dir=None, but no suitable default directory computed. Upgrade Pytorch to 1.6+ ?)r&rrs)rr has_homer?r?r@_process_bundle_dirsr r args_filec  Cs2t|||||||||d } td| dt| ddddddddd \} } } } }}}}t|}| durXtdd}td d}|durV| d krV|durPd |d |nd |} nd } t| ddvrm| d krmtd| dt| ddkr| dkrtd| dt| ddkr| dkrtd| d|dur|dur||d}n|t |}t ||d| dt ||ddni}|durtd| d|d krtdd}|durtdt |}d d!|i}|durt | || |d"}| dkr|durd#||gn|}t| ||| d$n| d%krVztj||}tjd&|||d'WngtjjtjjfyBt|||| d(YnPtjjyUt|||| d(Yn=w| d)kret|||| | d*n-| d krut|||| | |d+n| dkrtj||}tj| ||d'ntd,| dt||dS)-a download bundle from the specified source or url. The bundle should be a zip file and it will be extracted after downloading. This function refers to: https://pytorch.org/docs/stable/_modules/torch/hub.html Typical usage examples: .. code-block:: bash # Execute this module as a CLI entry, and download bundle from the model-zoo repo: python -m monai.bundle download --name --version "0.1.0" --bundle_dir "./" # Execute this module as a CLI entry, and download bundle from specified github repo: python -m monai.bundle download --name --source "github" --repo "repo_owner/repo_name/release_tag" # Execute this module as a CLI entry, and download bundle from ngc with latest version: python -m monai.bundle download --name --source "ngc" --bundle_dir "./" # Execute this module as a CLI entry, and download bundle from monaihosting with latest version: python -m monai.bundle download --name --source "monaihosting" --bundle_dir "./" # Execute this module as a CLI entry, and download bundle from Hugging Face Hub: python -m monai.bundle download --name "bundle_name" --source "huggingface_hub" --repo "repo_owner/repo_name" # Execute this module as a CLI entry, and download bundle via URL: python -m monai.bundle download --name --url # Execute this module as a CLI entry, and download bundle from ngc_private with latest version: python -m monai.bundle download --name --source "ngc_private" --bundle_dir "./" --repo "org/org_name" # Set default args of `run` in a JSON / YAML file, help to record and simplify the command line. # Other args still can override the default args at runtime. # The content of the JSON / YAML file is a dictionary. For example: # {"name": "spleen", "bundle_dir": "download", "source": ""} # then do the following command for downloading: python -m monai.bundle download --args_file "args.json" --source "github" Args: name: bundle name. If `None` and `url` is `None`, it must be provided in `args_file`. for example: "spleen_ct_segmentation", "prostate_mri_anatomy" in model-zoo: https://github.com/Project-MONAI/model-zoo/releases/tag/hosting_storage_v1. "monai_brats_mri_segmentation" in ngc: https://catalog.ngc.nvidia.com/models?filters=&orderBy=scoreDESC&query=monai. version: version name of the target bundle to download, like: "0.1.0". If `None`, will download the latest version (or the last commit to the `main` branch in the case of Hugging Face Hub). bundle_dir: target directory to store the downloaded data. Default is `bundle` subfolder under `torch.hub.get_dir()`. source: storage location name. This argument is used when `url` is `None`. In default, the value is achieved from the environment variable BUNDLE_DOWNLOAD_SRC, and it should be "ngc", "monaihosting", "github", "ngc_private", or "huggingface_hub". If source is "ngc_private", you need specify the NGC_API_KEY in the environment variable. repo: repo name. This argument is used when `url` is `None` and `source` is "github" or "huggingface_hub". If `source` is "github", it should be in the form of "repo_owner/repo_name/release_tag". If `source` is "huggingface_hub", it should be in the form of "repo_owner/repo_name". Please note that bundles for "monaihosting" source are also hosted on Hugging Face Hub, but the "repo_id" is always in the form of "MONAI/bundle_name", therefore, this argument is not required for "monaihosting" source. If `source` is "ngc_private", it should be in the form of "org/org_name" or "org/org_name/team/team_name", or you can specify the environment variable NGC_ORG and NGC_TEAM. url: url to download the data. If not `None`, data will be downloaded directly and `source` will not be checked. If `name` is `None`, filename is determined by `monai.apps.utils._basename(url)`. remove_prefix: This argument is used when `source` is "ngc" or "ngc_private". Currently, all ngc bundles have the ``monai_`` prefix, which is not existing in their model zoo contrasts. In order to maintain the consistency between these two sources, remove prefix is necessary. Therefore, if specified, downloaded folder name will remove the prefix. progress: whether to display a progress bar. args_file: a JSON or YAML file to provide default values for all the args in this function. so that the command line inputs can be simplified. ) r3r*rrrrrrrdownloadrWr3rrN)rrr*rrrZNGC_ORGZNGC_TEAMrzorg/z/team/z*Project-MONAI/model-zoo/hosting_storage_v1r})zSrepo should be in the form of `org/org_name/team/team_name` or `org/org_name`, got rprrzFrepo should be in the form of `repo_owner/repo_name/release_tag`, got rr/zKHugging Face Hub repo should be in the form of `repo_owner/repo_name`, got rrTrzTo download from source: z, `name` must be provided.Z NGC_API_KEYz+API key is required for ngc_private source.rBearer )rr*rrr)rrr|rr1zMONAI/)rrevision local_dir)rr|rrr)rr|rrr)rr|rrrrz|Currently only download from `url`, source 'github', 'monaihosting', 'huggingface_hub' or 'ngc' are implemented,got source: )rFr]rVr rgetenvrrrsrrrrrjoinrrr/Zsnapshot_downloaderrorsZRevisionNotFoundErrorZRepositoryNotFoundErrorrurlliberror HTTPErrorrrrNotImplementedErrorr)r*rrrrrrrr_argsZsource_Z progress_Zremove_prefix_Zrepo_name_Zversion_ bundle_dir_Zurl_Zorg_Zteam_rrrrZname_verrr?r?r@rsS   $        rtrainFr?modeltorch.nn.Module | None workflow_type model_fileload_ts_moduledevice key_in_ckpt config_files Sequence[str] workflow_namestr | BundleWorkflow | Nonecopy_model_args net_override1object | tuple[torch.nn.Module, dict, dict] | Anyc Cst|}|dur in|}|durin|}| durtrdnd} |dur0tjd|dur-dnd}|dkr@t|}| r@t|| d }tj|||}tj|sZt|||||| | |d |durht |t | | d St j |t | dd }t |tstd |dt|dt|}d}|dur||d|d}|rdd|D}td||t||d|}n td|d|S|durt|dstd|S|j}|| td|| dur|n|| d||S)a Load model weights or TorchScript module of a bundle. Args: name: bundle name. If `None` and `url` is `None`, it must be provided in `args_file`. for example: "spleen_ct_segmentation", "prostate_mri_anatomy" in model-zoo: https://github.com/Project-MONAI/model-zoo/releases/tag/hosting_storage_v1. "monai_brats_mri_segmentation" in ngc: https://catalog.ngc.nvidia.com/models?filters=&orderBy=scoreDESC&query=monai. "mednist_gan" in monaihosting: https://api.ngc.nvidia.com/v2/models/nvidia/monaihosting/mednist_gan/versions/0.2.0/files/mednist_gan_v0.2.0.zip model: a pytorch module to be updated. Default to None, using the "network_def" in the bundle. version: version name of the target bundle to download, like: "0.1.0". If `None`, will download the latest version. If `source` is "huggingface_hub", this argument is a Git revision id. workflow_type: specifies the workflow type: "train" or "training" for a training workflow, or "infer", "inference", "eval", "evaluation" for a inference workflow, other unsupported string will raise a ValueError. default to `train` for training workflow. model_file: the relative path of the model weights or TorchScript module within bundle. If `None`, "models/model.pt" or "models/model.ts" will be used. load_ts_module: a flag to specify if loading the TorchScript module. bundle_dir: directory the weights/TorchScript module will be loaded from. Default is `bundle` subfolder under `torch.hub.get_dir()`. source: storage location name. This argument is used when `model_file` is not existing locally and need to be downloaded first. In default, the value is achieved from the environment variable BUNDLE_DOWNLOAD_SRC, and it should be "ngc", "monaihosting", "github", or "huggingface_hub". repo: repo name. This argument is used when `url` is `None` and `source` is "github" or "huggingface_hub". If `source` is "github", it should be in the form of "repo_owner/repo_name/release_tag". If `source` is "huggingface_hub", it should be in the form of "repo_owner/repo_name". remove_prefix: This argument is used when `source` is "ngc". Currently, all ngc bundles have the ``monai_`` prefix, which is not existing in their model zoo contrasts. In order to maintain the consistency between these three sources, remove prefix is necessary. Therefore, if specified, downloaded folder name will remove the prefix. progress: whether to display a progress bar when downloading. device: target device of returned weights or module, if `None`, prefer to "cuda" if existing. key_in_ckpt: for nested checkpoint like `{"model": XXX, "optimizer": XXX, ...}`, specify the key of model weights. if not nested checkpoint, no need to set. config_files: extra filenames would be loaded. The argument only works when loading a TorchScript module, see `_extra_files` in `torch.jit.load` for more details. workflow_name: specified bundle workflow name, should be a string or class, default to "ConfigWorkflow". args_file: a JSON or YAML file to provide default values for all the args in "download" function. copy_model_args: other arguments for the `monai.networks.copy_model_state` function. net_override: id-value pairs to override the parameters in the network of the bundle, default to `None`. Returns: 1. If `load_ts_module` is `False` and `model` is `None`, return model weights if can't find "network_def" in the bundle, else return an instantiated network that loaded the weights. 2. If `load_ts_module` is `False` and `model` is not `None`, return an instantiated network that loaded the weights. 3. If `load_ts_module` is `True`, return a triple that include a TorchScript module, the corresponding metadata dict, and extra files dict. please check `monai.data.load_net_with_metadata` for more details. Ncuda:0cpumodelsTmodel.tsmodel.ptrr)r*rrrrrrr) map_locationmore_extra_files)r4 weights_onlyzthe state dictionary from z should be a dictionary but got rpr.jsoncSsi|] \}}d||qS)z network_def#r?)r=rvaluer?r?r@ rUzload..)r*r config_filer#zCannot find the config file: z, return state dict instead. network_defzINo available network definition in the bundle, return state dict instead.dstrNr?)r r rrrrrrrrtorchr&rr;rwarningswarnruris_filerGcreate_workflowr<hasattrr;tor)r*r!rr#r$r%rrrrrr&r'r(r*rr,r-r full_path model_dictZ _workflowZbundle_config_fileZ _net_overrider?r?r@rvspM       rrr auth_token$dict[str, dict[str, dict[str, Any]]]c Csptr3|dkr d|d}n d|d|d}|dur)dd|i}tj||d }nt|}|ntd t|j}t d }i}|dkr|D]<} | d |kr| d D]+} | | dd} | |vrii|| <| d | dd dd} t | || | <qV|SqJ|S| D](} | | d} | |vri|| <| | dd} | || dd|| | <q|S)NZhosting_storage_v1zhttps://api.github.com/repos/z /releasesz"https://raw.githubusercontent.com/r}z/models/model_info.jsonrrrrz_v\d*.r{Zassetsr*rrrrrr)r*r)rr-rHrrsrrrrcompilerreplacer9keys) rrWrGrrrZ releases_listZbundle_name_pattern bundles_inforeleaseZassetZ asset_nameZ asset_versionr?r?r@_get_all_bundles_infosD         rNlist[tuple[str, str]]cCsBt|||d}g}|D]}t||d}|||fq |S)a* Get all bundles names (and the latest versions) that are stored in the release of specified repository with the provided tag. If tag is "dev", will get model information from https://raw.githubusercontent.com/repo_owner/repo_name/dev/models/model_info.json. The default values of arguments correspond to the release of MONAI model zoo. In order to increase the rate limits of calling Github APIs, you can input your personal access token. Please check the following link for more details about rate limiting: https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting The following link shows how to create your personal access token: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token Args: repo: it should be in the form of "repo_owner/repo_name/". tag: the tag name of the release. auth_token: github personal access token. Returns: a list of tuple in the form of (bundle name, latest version). rrWrGr)rNrrKrr)rrWrGrLZ bundles_listrrr?r?r@get_all_bundles_list1s rQrdict[str, list[str] | str]cCsNt|||d}||vrtd|d|d||}t|}|d|dS)a Get the latest version, as well as all existing versions of a bundle that is stored in the release of specified repository with the provided tag. If tag is "dev", will get model information from https://raw.githubusercontent.com/repo_owner/repo_name/dev/models/model_info.json. In order to increase the rate limits of calling Github APIs, you can input your personal access token. Please check the following link for more details about rate limiting: https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting The following link shows how to create your personal access token: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token Args: bundle_name: bundle name. repo: it should be in the form of "repo_owner/repo_name/". tag: the tag name of the release. auth_token: github personal access token. Returns: a dictionary that contains the latest version and all versions of a bundle. rPbundle: z is not existing in repo: rpr)rrrNrsrrK)rrrWrGrLrrr?r?r@rSs  rdict[str, Any]cCslt|||d}||vrtd|d||}|dur#t|d}||vr2td|d|d||S)a Get all information (include "name" and "browser_download_url") of a bundle with the specified bundle name and version which is stored in the release of specified repository with the provided tag. In order to increase the rate limits of calling Github APIs, you can input your personal access token. Please check the following link for more details about rate limiting: https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting The following link shows how to create your personal access token: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token Args: bundle_name: bundle name. version: version name of the target bundle, if None, the latest version will be used. repo: it should be in the form of "repo_owner/repo_name/". tag: the tag name of the release. auth_token: github personal access token. Returns: a dictionary that contains the bundle's information. rPrSz is not existing.Nrz version: z of bundle: rT)rrrrWrGrLrr?r?r@rusrrun_idinit_idfinal_id meta_filestr | Sequence[str] | Noner: logging_filetrackingoverridec Ks4td||||||||d|} | | dS)aF Specify `config_file` to run monai bundle components and workflows. Typical usage examples: .. code-block:: bash # Execute this module as a CLI entry: python -m monai.bundle run --meta_file --config_file # Execute with specified `run_id=training`: python -m monai.bundle run training --meta_file --config_file # Execute with all specified `run_id=runtest`, `init_id=inittest`, `final_id=finaltest`: python -m monai.bundle run --run_id runtest --init_id inittest --final_id finaltest ... # Override config values at runtime by specifying the component id and its new value: python -m monai.bundle run --net#input_chns 1 ... # Override config values with another config file `/path/to/another.json`: python -m monai.bundle run --net %/path/to/another.json ... # Override config values with part content of another config file: python -m monai.bundle run --net %/data/other.json#net_arg ... # Set default args of `run` in a JSON / YAML file, help to record and simplify the command line. # Other args still can override the default args at runtime: python -m monai.bundle run --args_file "/workspace/data/args.json" --config_file Args: run_id: ID name of the expected config expression to run, default to "run". to run the config, the target config must contain this ID. init_id: ID name of the expected config expression to initialize before running, default to "initialize". it's optional for both configs and this `run` function. final_id: ID name of the expected config expression to finalize after running, default to "finalize". it's optional for both configs and this `run` function. meta_file: filepath of the metadata file, if it is a list of file paths, the content of them will be merged. Default to None. config_file: filepath of the config file, if `None`, must be provided in `args_file`. if it is a list of file paths, the content of them will be merged. logging_file: config file for `logging` module in the program. for more details: https://docs.python.org/3/library/logging.config.html#logging.config.fileConfig. Default to None. tracking: if not None, enable the experiment tracking at runtime with optionally configurable and extensible. If "mlflow", will add `MLFlowHandler` to the parsed bundle with default tracking settings where a set of common parameters shown below will be added and can be passed through the `override` parameter of this method. - ``"output_dir"``: the path to save mlflow tracking outputs locally, default to "/eval". - ``"tracking_uri"``: uri to save mlflow tracking outputs, default to "/output_dir/mlruns". - ``"experiment_name"``: experiment name for this run, default to "monai_experiment". - ``"run_name"``: the name of current run. - ``"save_execute_config"``: whether to save the executed config files. It can be `False`, `/path/to/artifacts` or `True`. If set to `True`, will save to the default path "/eval". Default to `True`. If other string, treat it as file path to load the tracking settings. If `dict`, treat it as tracking settings. Will patch the target config content with `tracking handlers` and the top-level items of `configs`. for detailed usage examples, please check the tutorial: https://github.com/Project-MONAI/tutorials/blob/main/experiment_management/bundle_integrate_mlflow.ipynb. args_file: a JSON or YAML file to provide default values for `run_id`, `meta_file`, `config_file`, `logging`, and override pairs. so that the command line inputs can be simplified. override: id-value pairs to override or add the corresponding config content. e.g. ``--net#input_chns 42``, ``--net %/data/other.json#net_arg``. )r:rrYr[rWrVrXr\Nr?rBrunfinalize) rVrWrXrYr:r[r\rr]Zworkflowr?r?r@r_sM  r_cKs(td||d|}||dS)a Specify `bundle workflow` to run monai bundle components and workflows. The workflow should be subclass of `BundleWorkflow` and be available to import. It can be MONAI existing bundle workflows or user customized workflows. Typical usage examples: .. code-block:: bash # Execute this module as a CLI entry with default ConfigWorkflow: python -m monai.bundle run_workflow --meta_file --config_file # Set the workflow to other customized BundleWorkflow subclass: python -m monai.bundle run_workflow --workflow_name CustomizedWorkflow ... Args: workflow_name: specified bundle workflow name, should be a string or class, default to "ConfigWorkflow". args_file: a JSON or YAML file to provide default values for this API. so that the command line inputs can be simplified. kwargs: arguments to instantiate the workflow class. )r*rNr?r^)r*rr7 workflow_r?r?r@ run_workflows rbr create_dir bool | Noner hash_typec Kstd||||||d|}td|dt|dddddd \}} } } } t|| d tj| d } | d }|durTensor) rsrZ prefix_keyrinput_channelsinput_spatial_shape input_dtypeoutput_channels output_dtyper?r?r@_get_net_io_infoVs          r|rcCs.t|d\}}}}}t|}d|g|R}|S)z Get a fake input shape e.g. [N, C, H, W] or [N, C, H, W, D], whose batch size is 1, from the given parser. Args: parser: a ConfigParser which contains the i/o information of a bundle. rsrh)r|rx)rsrwrxr spatial_shape input_shaper?r?r@_get_fake_input_shape{srnet_id int | Noneextra_forward_argsc ! Kstd|||||||||d | } td| dt| dddtr!dndd d d id \} } } }}}}}t}|j| d |j| d | D]\}}|||<qDt|d \}}}}}z | }| | |}Wnt yx}z t d |d|d}~ww| t {t||||d}t jd |g|R||d}|t jkr| dt d||fi|} Wdn1swY| |n||fi|} | jd |krtd| jd d|d| j|krtd| jd|dWdn1swYtddS)a Verify the input and output data shape and data type of network defined in the metadata. Will test with fake Tensor data according to the required data shape in `metadata`. Typical usage examples: .. code-block:: bash python -m monai.bundle verify_net_in_out network --meta_file --config_file Args: net_id: ID name of the network component to verify, it must be `torch.nn.Module`. meta_file: filepath of the metadata file to get network args, if `None`, must be provided in `args_file`. if it is a list of file paths, the content of them will be merged. config_file: filepath of the config file to get network definition, if `None`, must be provided in `args_file`. if it is a list of file paths, the content of them will be merged. device: target device to run the network forward computation, if None, prefer to "cuda" if existing. p: power factor to generate fake data shape if dim of expected shape is "x**p", default to 1. n: multiply factor to generate fake data shape if dim of expected shape is "x*n", default to 1. any: specified size to generate fake data shape if dim of expected shape is "*", default to 1. extra_forward_args: a dictionary that contains other args for the forward function of the network. Default to an empty dictionary. args_file: a JSON or YAML file to provide default values for `net_id`, `meta_file`, `config_file`, `device`, `p`, `n`, `any`, and override pairs. so that the command line inputs can be simplified. override: id-value pairs to override or add the corresponding config content. e.g. ``--_meta#network_data_format#inputs#image#num_channels 3``. ) r3rrYr:r&rkrmrnrverify_net_in_outrr:rYrr/r0rh)rr&rkrmrnrrr}zno_gradrxrandfloat16autocastrrirsrrYrZ)!rrYr:r&rkrmrnrrr]r config_file_rpnet_id_device_p_n_Zany_Zextra_forward_args_rsrLrMrwrxryrzr{rnetrqr~ test_dataoutputr?r?r@rsp)            r converterr saver ckpt_filecKs||} trtj|| i|dntj|dd} t| |dkr | n| |d|dd| i|} i} t|D](} tj | } tj | \} }| | vrQt d| dt t| | | <q5d d | D} |d d }|| ||| d td|dd S)a: Export a model defined in the parser to a new one specified by the converter. Args: converter: a callable object that takes a torch.nn.module and kwargs as input and converts the module to another type. saver: a callable object that accepts the converted model to save, a filepath to save to, meta values (extracted from the parser), and a dictionary of extra JSON files (name -> contents) as input. parser: a ConfigParser of the bundle to be converted. net_id: ID name of the network component in the parser, it must be `torch.nn.Module`. filepath: filepath to export, if filename has no extension, it becomes `.ts`. ckpt_file: filepath of the model checkpoint to load. config_file: filepath of the config file to save in the converted model,the saved key in the converted model is the config filename without extension, and the saved config value is always serialized in JSON format no matter the original file format is JSON or YAML. it can be a single file or a list of files. key_in_ckpt: for nested checkpoint like `{"model": XXX, "optimizer": XXX, ...}`, specify the key of model weights. if not nested checkpoint, no need to set. kwargs: key arguments for the converter. )Zto_load checkpointT)r6rr<r!zFilename part 'z.' is given multiple times in config file list.cSsi|] \}}|d|qS)r7r?rTr?r?r@r9%sz_export.._meta_N) meta_valuesr5zexported to file: rpr?)r has_igniter,Z load_objectsr>rrr#rrbasenamesplitextrsrdumpsrrBencoderGrHrPrYrZ)rrrsrrrr:r'r7rckpt extra_filesrQr|rrr?r?r@_exports"   r use_tracerSequence[int] | Noneconverter_kwargsMapping | Nonec  Kstd|||||||||| d | } td| dt| ddddddd did \ } } }}}}}}}t}|j|d |durB|j|d | D]\}}|||<qF|sVt|d }t |g}| ||d ddd}t t ||f|| | ||d|dS)a Export the model checkpoint to an onnx model. Typical usage examples: .. code-block:: bash python -m monai.bundle onnx_export network --filepath --ckpt_file ... Args: net_id: ID name of the network component in the config, it must be `torch.nn.Module`. filepath: filepath where the onnx model is saved to. ckpt_file: filepath of the model checkpoint to load. meta_file: filepath of the metadata file, if it is a list of file paths, the content of them will be merged. config_file: filepath of the config file that contains extract network information, key_in_ckpt: for nested checkpoint like `{"model": XXX, "optimizer": XXX, ...}`, specify the key of model weights. if not nested checkpoint, no need to set. use_trace: whether using `torch.jit.trace` to convert the pytorch model to torchscript model. input_shape: a shape used to generate the random input of the network, when converting the model to an onnx model. Should be a list like [N, C, H, W] or [N, C, H, W, D]. If not given, will try to parse from the `metadata` config. args_file: a JSON or YAML file to provide default values for all the parameters of this function, so that the command line inputs can be simplified. converter_kwargs: extra arguments that are needed by `convert_to_onnx`, except ones that already exist in the input parameters. override: id-value pairs to override or add the corresponding config content. e.g. ``--_meta#network_data_format#inputs#image#num_channels 3``. r3rrrYr:rr'rrr onnx_exportrrrr:rNF)rrYr'rrrrr}inputsronnx_objr filename_prefix_or_streamr<r7r8rXc[st||dSr:)r.save)rrr7r?r?r@ save_onnxszonnx_export..save_onnxrrrr:r'r?)rr rr<r7r r8rX) rFr]rVrrrrGrr>rrrr)rrrrYr:r'rrrrr]rro ckpt_file_rrrp key_in_ckpt_ use_trace_ input_shape_converter_kwargs_rsrLrMinputs_rr?r?r@r-sz*          rc  Kstd|||||||||| d | } td| dt| ddddddddid \ } } }}}}}}}| d t}t}|j| d |durLtj |d d n|}tj |rZ|j |d | D]\}}|||<q^| durstj |d dn| } |durtj |d dn|}tj |st d|d|durdn|}z||Wnty}z td|d| d|d}~ww|s|rt|d}|rt|gnd}|||dttddd}tt||f|| || |d|dS)a Export the model checkpoint to the given filepath with metadata and config included as JSON files. Typical usage examples: .. code-block:: bash python -m monai.bundle ckpt_export network --filepath --ckpt_file ... Args: net_id: ID name of the network component in the config, it must be `torch.nn.Module`. Default to "network_def". filepath: filepath to export, if filename has no extension it becomes `.ts`. Default to "models/model.ts" under "os.getcwd()" if `bundle_root` is not specified. ckpt_file: filepath of the model checkpoint to load. Default to "models/model.pt" under "os.getcwd()" if `bundle_root` is not specified. meta_file: filepath of the metadata file, if it is a list of file paths, the content of them will be merged. Default to "configs/metadata.json" under "os.getcwd()" if `bundle_root` is not specified. config_file: filepath of the config file to save in TorchScript model and extract network information, the saved key in the TorchScript model is the config filename without extension, and the saved config value is always serialized in JSON format no matter the original file format is JSON or YAML. it can be a single file or a list of files. if `None`, must be provided in `args_file`. key_in_ckpt: for nested checkpoint like `{"model": XXX, "optimizer": XXX, ...}`, specify the key of model weights. if not nested checkpoint, no need to set. use_trace: whether using `torch.jit.trace` to convert the PyTorch model to TorchScript model. input_shape: a shape used to generate the random input of the network, when converting the model to a TorchScript model. Should be a list like [N, C, H, W] or [N, C, H, W, D]. If not given, will try to parse from the `metadata` config. args_file: a JSON or YAML file to provide default values for all the parameters of this function, so that the command line inputs can be simplified. converter_kwargs: extra arguments that are needed by `convert_to_torchscript`, except ones that already exist in the input parameters. override: id-value pairs to override or add the corresponding config content. e.g. ``--_meta#network_data_format#inputs#image#num_channels 3``. r ckpt_exportrr:NrF)rrrrYr'rrr bundle_rootrrrr1r2r3zCheckpoint file "z7" not found, please specify it in argument "ckpt_file".r;zNetwork definition "z" cannot be found in "z'", specify name with argument "net_id".r}rinclude_config_valsappend_timestamprr?)rFr]rVrHrgetcwdrrrrrrrGFileNotFoundErrorrrsrr>rrrrrr)rrrrYr:r'rrrrr]rrrorrrprrrrrrsrLrMrqrsave_tsr?r?r@rs1           r precisiondynamic_batchsizeuse_onnxonnx_input_namesSequence[str] | Noneonnx_output_namesc&Ksdtdid|d|d|d|d|d|d|d|d |d |d | d | d | d| d| d||}td|dt|dddddddgdddddgdgid\}}}}}}}}}}}}}}} t}!|!j|d|duru|!j|d|D]\}"}#|#|!|"<qy|st|!d}||||||||d}$| |$t t ddd}%t t |%|!f|||||d| dS) a_ Export the model checkpoint to the given filepath as a TensorRT engine-based TorchScript. Currently, this API only supports converting models whose inputs are all tensors. Note: NVIDIA Volta support (GPUs with compute capability 7.0) has been removed starting with TensorRT 10.5. Review the TensorRT Support Matrix for which GPUs are supported. There are two ways to export a model: 1, Torch-TensorRT way: PyTorch module ---> TorchScript module ---> TensorRT engine-based TorchScript. 2, ONNX-TensorRT way: PyTorch module ---> TorchScript module ---> ONNX model ---> TensorRT engine ---> TensorRT engine-based TorchScript. When exporting through the first way, some models suffer from the slowdown problem, since Torch-TensorRT may only convert a little part of the PyTorch model to the TensorRT engine. However when exporting through the second way, some Python data structures like `dict` are not supported. And some TorchScript models are not supported by the ONNX if exported through `torch.jit.script`. Typical usage examples: .. code-block:: bash python -m monai.bundle trt_export --net_id --filepath --ckpt_file --input_shape --dynamic_batchsize ... Args: net_id: ID name of the network component in the config, it must be `torch.nn.Module`. filepath: filepath to export, if filename has no extension, it becomes `.ts`. ckpt_file: filepath of the model checkpoint to load. meta_file: filepath of the metadata file, if it is a list of file paths, the content of them will be merged. config_file: filepath of the config file to save in the TensorRT based TorchScript model and extract network information, the saved key in the model is the config filename without extension, and the saved config value is always serialized in JSON format no matter the original file format is JSON or YAML. it can be a single file or a list of files. if `None`, must be provided in `args_file`. key_in_ckpt: for nested checkpoint like `{"model": XXX, "optimizer": XXX, ...}`, specify the key of model weights. if not nested checkpoint, no need to set. precision: the weight precision of the converted TensorRT engine based TorchScript models. Should be 'fp32' or 'fp16'. input_shape: the input shape that is used to convert the model. Should be a list like [N, C, H, W] or [N, C, H, W, D]. If not given, will try to parse from the `metadata` config. use_trace: whether using `torch.jit.trace` to convert the PyTorch model to a TorchScript model and then convert to a TensorRT engine based TorchScript model or an ONNX model (if `use_onnx` is True). dynamic_batchsize: a sequence with three elements to define the batch size range of the input for the model to be converted. Should be a sequence like [MIN_BATCH, OPT_BATCH, MAX_BATCH]. After converted, the batchsize of model input should between `MIN_BATCH` and `MAX_BATCH` and the `OPT_BATCH` is the best performance batchsize that the TensorRT tries to fit. The `OPT_BATCH` should be the most frequently used input batchsize in the application. device: the target GPU index to convert and verify the model. use_onnx: whether using the ONNX-TensorRT way to export the TensorRT engine-based TorchScript model. onnx_input_names: optional input names of the ONNX model. This arg is only useful when `use_onnx` is True. Should be a sequence like `['input_0', 'input_1', ..., 'input_N']` where N equals to the number of the model inputs. If not given, will use `['input_0']`, which supposes the model only has one input. onnx_output_names: optional output names of the ONNX model. This arg is only useful when `use_onnx` is True. Should be a sequence like `['output_0', 'output_1', ..., 'output_N']` where N equals to the number of the model outputs. If not given, will use `['output_0']`, which supposes the model only has one output. args_file: a JSON or YAML file to provide default values for all the parameters of this function, so that the command line inputs can be simplified. converter_kwargs: extra arguments that are needed by `convert_to_trt`, except ones that already exist in the input parameters. override: id-value pairs to override or add the corresponding config content. e.g. ``--_meta#network_data_format#inputs#image#num_channels 3``. r3rrrYr:rr'rrrrr&rrrr trt_exportrrNfp32Finput_0output_0) rrYr'rrrrr&rrrrrr})rrrrr&rrrrrr?) rFr]rVrrrrGrrrrrr)&rrrrYr:r'rrrrr&rrrrrr]rrorrrrprZ precision_rrZdynamic_batchsize_rZ use_onnx_Zonnx_input_names_Zonnx_output_names_rrsrLrMZtrt_api_parametersrr?r?r@r%sO            rnetworkdataset_license metadata_strdict | str | None inference_strc CsL|durt}|dur t}t|}|r tdt|d|js/tdt|d|d}|d}|d}| | | | t |t rWt j |d d }t |t rct j |d d }tt|d d  } | |Wdn1s|wYtt|d d  } | |Wdn1swYtt|dd } d} | t| Wdn1swYtt|dd  } | dWdn1swY|durtt|dd  } | dWdn1swY|durtt|t|ddS|dur$t|t|ddSdS)a Initialise a new bundle directory with some default configuration files and optionally network weights. Typical usage example: .. code-block:: bash python -m monai.bundle init_bundle /path/to/bundle_dir network_ckpt.pt Args: bundle_dir: directory name to create, must not exist but parent direct must exist ckpt_file: optional checkpoint file to copy into bundle network: if given instead of ckpt_file this network's weights will be stored in bundle dataset_license: if `True`, a default license file called "data_license.txt" will be produced. This file is required if there are any license conditions stated for data your bundle uses. metadata_str: optional metadata string to write to bundle, if not given a default will be used. inference_str: optional inference string to write to bundle, if not given a default will be used. NzSpecified bundle directory 'z' already existsz0Parent directory of specified bundle directory 'z' does not existrr1docsr)indentrwzinference.json README.mda # Your Model Name Describe your model here and how to run it, for example using `inference.json`: ``` python -m monai.bundle run --meta_file /path/to/bundle/configs/metadata.json --config_file /path/to/bundle/configs/inference.json --dataset_dir ./input --bundle_root /path/to/bundle ``` LICENSEz*Select a license and place its terms here Tzdata_license.txtz6Select a license for dataset and place its terms here r3)rrrabsoluterrsr<parentis_dirrr;r9rrrrr rr ) rrrrrrZ configs_dirZ models_dirZdocs_diroreadmer?r?r@ init_bundlesT           rcCsd}tjtj|d}tj|r --name --bundle_dir --version ... Args: repo: namespace (user or organization) and a repo name separated by a /, e.g. `hf_username/bundle_name` bundle_name: name of the bundle directory to push. bundle_dir: path to the bundle directory. token: Hugging Face authentication token. Default is `None` (will default to the stored token). private: Private visibility of the repository on Hugging Face. Default is `True`. version_name: Name of the version tag to create. Default is `None` (no version tag is created). tag_as_latest_version: Whether to tag the commit as `latest_version`. This version will downloaded by default when using `bundle.download()`. Default is `False`. upload_folder_kwargs: Keyword arguments to pass to `HfApi.upload_folder`. Returns: repo_url: URL of the Hugging Face repo )rT)rrrrr)r folder_pathN)rrWrrr?) r/ZHfApiZ create_reporrrrrrZ upload_folderZ create_tag) rr*rrrrrrZhf_apirZmodelcard_pathZrepo_urlr?r?r@push_to_hf_hubGs #   rcKstd |||d|}t|tdd\}}t|tr8tdt|d\}}|s+tt|}|dur7td|dnt|t r@|}ntd|d|durV|d d |i|}n|d i|}| t d |d |S) a2 Specify `bundle workflow` to create monai bundle workflows. The workflow should be subclass of `BundleWorkflow` and be available to import. It can be MONAI existing bundle workflows or user customized workflows. Typical usage examples: .. code-block:: python # Specify config_file path to create workflow: workflow = create_workflow(config_file="/workspace/spleen_ct_segmentation/configs/train.json", workflow_type="train") # Set the workflow to other customized BundleWorkflow subclass to create workflow: workflow = create_workflow(workflow_name=CustomizedWorkflow) Args: workflow_name: specified bundle workflow name, should be a string or class, default to "ConfigWorkflow". config_file: filepath of the config file, if it is a list of file paths, the content of them will be merged. args_file: a JSON or YAML file to provide default values for this API. so that the command line inputs can be simplified. kwargs: arguments to instantiate the workflow class. )r3r*r:N)r*r:z monai.bundler)z(cannot locate specified workflow class: rpzaArgument `workflow_name` must be a bundle workflow class nameor subclass of BundleWorkflow, got: r:r_rr?) rFrVrr;r<r&rrs issubclassr initializer])r*r:rr7rZworkflow_class has_built_inrar?r?r@rBs0    rB bundle_pathlarge_file_namecCs|durtn|}|dur.tt|d}ttdd|}t|dkr.td|dt}| || d}|D]?}d |d <d |vrU| d d d krU| d d |vrf| d d d krf| d tj ||d|d<| dtdi|q>dS)a This utility allows you to download large files from a bundle. It supports file suffixes like ".yml", ".yaml", and ".json". If you don't specify a `large_file_name`, it will automatically search for large files among the supported suffixes. Typical usage examples: .. code-block:: bash # Execute this module as a CLI entry to download large files from a bundle path: python -m monai.bundle download_large_files --bundle_path # Execute this module as a CLI entry to download large files from the bundle path with a specified `large_file_name`: python -m monai.bundle download_large_files --bundle_path --large_file_name large_files.yaml Args: bundle_path: (Optional) The path to the bundle where the files are located. Default is `os.getcwd()`. large_file_name: (Optional) The name of the large file to be downloaded. Nz large_files*cSs |jdvS)N)z.ymlz.yamlr7)suffixrr?r?r@rs z&download_large_files..rz0Cannot find the large_files.yml/yaml/json under rpZ large_filesTfuzzyrrrerrr?)rrrDrglobfilterrrrrrHrPrrr)rrZlarge_file_pathrsZlarge_files_listZlf_datar?r?r@download_large_filess&      r)NT)r3r4r5r6r7r r8r9)rNr9r3r r7r r8rC)rWr<r3r9r8rX)r^r<r8r_)rhrhrh) rirjrkrlrmrlrnrlr8rC) ryr<rzr<r{r<r|r<r8r<)rr<rr<r8r<)rr<r8r<)rr<rr<rr<r8r<)T) rr<rrr|r<rr6r8rX) rrr|r<rr<rr6r8rX)r)r*r<rr<r8r<r:)rr<rrr8r_)rrT)rrr|r<rr<rr<rrrr6r8rX)rrN)rrr|r<rr<rr<rr<rrrrr8rX)r)rr<r8r)rrr*r<r8rX)r)rr9rrlr8r_)NN)r*r<rrrrr8r<) rr<r*r<rr<r7r r8r)rr r8r)r*rrrrr rr<rrrrrrrr6rrr8rX)&r*r<r!r"rrr#r<r$rr%r6rr rr<rrrrrr6r&rr'rr(r)r*r+rrr,rr-rr8r.)rrN)rr<rWr<rGrr8rH)rr<rWr<rGrr8rO) rr<rr<rWr<rGrr8rR)NrrN) rr<rrrr<rWr<rGrr8rU)NNNNNNNN)rVrrWrrXrrYrZr:rZr[rr\r4rrr]r r8rX)r*r+rrr7r r8rX)NNNNNN)rYrZrr rcrdrrrerrrr7r r8rX)Nrr)rsrtrr<r8rC)rsrr8rC) NNNNNNNNN)rrrYrZr:rZr&rrkrrmrrnrrrrrr]r r8rX)rr rr rsrrr<rr<rr<r:r<r'r<r7r r8rX) NNNNNNNNNN)rrrr rrrYrZr:rZr'rrrdrrrrrrr]r r8rX)NNNNNNNNNNNNNNNN)$rrrr rrrYrZr:rZr'rrrrrrrdrrr&rrrdrrrrrrrrr]r r8rX)NNFNN)rrrr rr"rr6rrrrr8rX)NTNF)rr<r*r<rr<rrrrdrrrrdrr r8r )NNN) r*r+r:rZrrr7r r8r )rrrrr8rX) __future__rr`rrrrr?rcollections.abcrr functoolsrpathlibrpydocrshutilrtextwrapr typingr r r> torch.cudar Zmonai._versionr monai.apps.utilsrrrrmonai.bundle.config_parserrmonai.bundle.utilsrrrZmonai.bundle.workflowsrr monai.configr monai.datarrmonai.networksrrrrrr monai.utilsr!r"r#r$r%r&r'r(rr+OPT_IMPORT_VERSIONr,rr-rr.r/__name__rYenvironrHZDEFAULT_DOWNLOAD_SOURCEr[rrrF _update_argsrVr]rgrxr~rrrrrrrrrrrrrrrrrrr rrrNrQrrr_rbrfr|rrrrrrrrrrBrr?r?r?r@s           $      %             !  9-#$*] = % eAs3Z=9