From bd7afde1a89259f6982a2ab07d42a3fcc7a6693f Mon Sep 17 00:00:00 2001 From: camillebrianceau Date: Tue, 19 Mar 2024 14:10:03 +0100 Subject: [PATCH] update & rebase --- clinicadl/hugging_face/hugging_face.py | 4 +- clinicadl/utils/maps_manager/maps_manager.py | 3 +- .../utils/maps_manager/maps_manager_utils.py | 184 +++++++++--------- 3 files changed, 95 insertions(+), 96 deletions(-) diff --git a/clinicadl/hugging_face/hugging_face.py b/clinicadl/hugging_face/hugging_face.py index 9d2910af7..e64b7ffcd 100644 --- a/clinicadl/hugging_face/hugging_face.py +++ b/clinicadl/hugging_face/hugging_face.py @@ -137,12 +137,12 @@ def create_readme( config_dict = toml.load(config_path) train_dict = read_json(config_file) - train_dict = change_str_to_path(train_dict) + # train_dict = change_str_to_path(train_dict) task = train_dict["network_task"] config_dict = remove_unused_tasks(config_dict, task) - config_dict = change_str_to_path(config_dict) + # config_dict = change_str_to_path(config_dict) file = open("tmp_README.md", "w") list_lines = [] diff --git a/clinicadl/utils/maps_manager/maps_manager.py b/clinicadl/utils/maps_manager/maps_manager.py index 179990986..e5439eb6a 100644 --- a/clinicadl/utils/maps_manager/maps_manager.py +++ b/clinicadl/utils/maps_manager/maps_manager.py @@ -30,9 +30,8 @@ ) from clinicadl.utils.maps_manager.ddp import DDP, cluster, init_ddp from clinicadl.utils.maps_manager.logwriter import LogWriter -from clinicadl.utils.maps_manager.maps_manager_utils import ( +from clinicadl.utils.maps_manager.maps_manager_utils import ( # change_str_to_path, add_default_values, - change_str_to_path, read_json, ) from clinicadl.utils.metric_module import RetainBest diff --git a/clinicadl/utils/maps_manager/maps_manager_utils.py b/clinicadl/utils/maps_manager/maps_manager_utils.py index c90b85c85..aa53cd316 100644 --- a/clinicadl/utils/maps_manager/maps_manager_utils.py +++ b/clinicadl/utils/maps_manager/maps_manager_utils.py @@ -175,95 +175,95 @@ def remove_unused_tasks( return toml_dict -def change_str_to_path( - toml_dict: Dict[str, Dict[str, Any]] -) -> Dict[str, Dict[str, Any]]: - """ - For all paths in the dictionnary, it changes the type from str to pathlib.Path. - - Paramaters - ---------- - toml_dict: Dict[str, Dict[str, Any]] - Dictionary of options as written in a TOML file, with type(path)=str - - Returns - ------- - Updated TOML dictionary with type(path)=pathlib.Path - """ - for key, value in toml_dict.items(): - if type(value) == Dict: - for key2, value2 in value.items(): - if ( - key2.endswith("tsv") - or key2.endswith("dir") - or key2.endswith("directory") - or key2.endswith("path") - or key2.endswith("json") - or key2.endswith("location") - ): - if value2 == "": - toml_dict[value][key2] = False - else: - toml_dict[value][key2] = Path(value2) - else: - if ( - key.endswith("tsv") - or key.endswith("dir") - or key.endswith("directory") - or key.endswith("path") - or key.endswith("json") - or key.endswith("location") - ): - if value == "" or value is False: - toml_dict[key] = False - else: - toml_dict[key] = Path(value) - return toml_dict - - -def change_path_to_str( - toml_dict: Dict[str, Dict[str, Any]] -) -> Dict[str, Dict[str, Any]]: - """ - For all paths in the dictionnary, it changes the type from pathlib.Path to str. - - Paramaters - ---------- - toml_dict: Dict[str, Dict[str, Any]] - Dictionary of options as written in a TOML file, with type(path)=pathlib.Path - - Returns - ------- - Updated TOML dictionary with type(path)=str - """ - for key, value in toml_dict.items(): - if type(value) == Dict: - for key2, value2 in value.items(): - if ( - key2.endswith("tsv") - or key2.endswith("dir") - or key2.endswith("directory") - or key2.endswith("path") - or key2.endswith("json") - or key2.endswith("location") - ): - if value2 == False: - toml_dict[value][key2] = "" - elif isinstance(value2, Path): - toml_dict[value][key2] = value2.as_posix() - else: - if ( - key.endswith("tsv") - or key.endswith("dir") - or key.endswith("directory") - or key.endswith("path") - or key.endswith("json") - or key.endswith("location") - ): - if value == False: - toml_dict[key] = "" - elif isinstance(value, Path): - toml_dict[key] = value.as_posix() - if isinstance(value, Path): - toml_dict[key] = value.as_posix() - return toml_dict +# def change_str_to_path( +# toml_dict: Dict[str, Dict[str, Any]] +# ) -> Dict[str, Dict[str, Any]]: +# """ +# For all paths in the dictionnary, it changes the type from str to pathlib.Path. + +# Paramaters +# ---------- +# toml_dict: Dict[str, Dict[str, Any]] +# Dictionary of options as written in a TOML file, with type(path)=str + +# Returns +# ------- +# Updated TOML dictionary with type(path)=pathlib.Path +# """ +# for key, value in toml_dict.items(): +# if type(value) == Dict: +# for key2, value2 in value.items(): +# if ( +# key2.endswith("tsv") +# or key2.endswith("dir") +# or key2.endswith("directory") +# or key2.endswith("path") +# or key2.endswith("json") +# or key2.endswith("location") +# ): +# if value2 == "": +# toml_dict[value][key2] = False +# else: +# toml_dict[value][key2] = Path(value2) +# else: +# if ( +# key.endswith("tsv") +# or key.endswith("dir") +# or key.endswith("directory") +# or key.endswith("path") +# or key.endswith("json") +# or key.endswith("location") +# ): +# if value == "" or value is False: +# toml_dict[key] = False +# else: +# toml_dict[key] = Path(value) +# return toml_dict + + +# def change_path_to_str( +# toml_dict: Dict[str, Dict[str, Any]] +# ) -> Dict[str, Dict[str, Any]]: +# """ +# For all paths in the dictionnary, it changes the type from pathlib.Path to str. + +# Paramaters +# ---------- +# toml_dict: Dict[str, Dict[str, Any]] +# Dictionary of options as written in a TOML file, with type(path)=pathlib.Path + +# Returns +# ------- +# Updated TOML dictionary with type(path)=str +# """ +# for key, value in toml_dict.items(): +# if type(value) == Dict: +# for key2, value2 in value.items(): +# if ( +# key2.endswith("tsv") +# or key2.endswith("dir") +# or key2.endswith("directory") +# or key2.endswith("path") +# or key2.endswith("json") +# or key2.endswith("location") +# ): +# if value2 == False: +# toml_dict[value][key2] = "" +# elif isinstance(value2, Path): +# toml_dict[value][key2] = value2.as_posix() +# else: +# if ( +# key.endswith("tsv") +# or key.endswith("dir") +# or key.endswith("directory") +# or key.endswith("path") +# or key.endswith("json") +# or key.endswith("location") +# ): +# if value == False: +# toml_dict[key] = "" +# elif isinstance(value, Path): +# toml_dict[key] = value.as_posix() +# if isinstance(value, Path): +# toml_dict[key] = value.as_posix() +# return toml_dict