From 3742ab493dbf4573c930a46aefc537b9127b4370 Mon Sep 17 00:00:00 2001 From: Paula Derrenger <107626595+pderrenger@users.noreply.github.com> Date: Sun, 9 Jun 2024 04:21:38 +0200 Subject: [PATCH] Code Refactor for Speed and Readability (#13074) Refactor code for speed and clarity Co-authored-by: Glenn Jocher --- utils/general.py | 4 +++- utils/loggers/clearml/clearml_utils.py | 9 +++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/utils/general.py b/utils/general.py index bce9d6d..ed38cc0 100644 --- a/utils/general.py +++ b/utils/general.py @@ -616,10 +616,12 @@ def yaml_load(file="data.yaml"): return yaml.safe_load(f) -def yaml_save(file="data.yaml", data={}): +def yaml_save(file="data.yaml", data=None): """Safely saves `data` to a YAML file specified by `file`, converting `Path` objects to strings; `data` is a dictionary. """ + if data is None: + data = {} with open(file, "w") as f: yaml.safe_dump({k: str(v) if isinstance(v, Path) else v for k, v in data.items()}, f, sort_keys=False) diff --git a/utils/loggers/clearml/clearml_utils.py b/utils/loggers/clearml/clearml_utils.py index f1b5665..2b5351e 100644 --- a/utils/loggers/clearml/clearml_utils.py +++ b/utils/loggers/clearml/clearml_utils.py @@ -47,10 +47,11 @@ def construct_dataset(clearml_info_string): {"train", "test", "val", "nc", "names"} ), "The right keys were not found in the yaml file, make sure it at least has the following keys: ('train', 'test', 'val', 'nc', 'names')" - data_dict = {} - data_dict["train"] = ( - str((dataset_root_path / dataset_definition["train"]).resolve()) if dataset_definition["train"] else None - ) + data_dict = { + "train": ( + str((dataset_root_path / dataset_definition["train"]).resolve()) if dataset_definition["train"] else None + ) + } data_dict["test"] = ( str((dataset_root_path / dataset_definition["test"]).resolve()) if dataset_definition["test"] else None )