Code Refactor for Speed and Readability (#13074)
Refactor code for speed and clarity Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
1 parent
3ec95f9e3d
commit
3742ab493d
2 files changed
+8
-5
No files matched your search
+3
-1
@@ -616,10 +616,12 @@ def yaml_load(file="data.yaml"):
|
|||||||
return yaml.safe_load(f)
|
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
|
"""Safely saves `data` to a YAML file specified by `file`, converting `Path` objects to strings; `data` is a
|
||||||
dictionary.
|
dictionary.
|
||||||
"""
|
"""
|
||||||
|
if data is None:
|
||||||
|
data = {}
|
||||||
with open(file, "w") as f:
|
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)
|
yaml.safe_dump({k: str(v) if isinstance(v, Path) else v for k, v in data.items()}, f, sort_keys=False)
|
||||||
|
|
||||||
|
|||||||
@@ -47,10 +47,11 @@ def construct_dataset(clearml_info_string):
|
|||||||
{"train", "test", "val", "nc", "names"}
|
{"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')"
|
), "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 = {
|
||||||
data_dict["train"] = (
|
"train": (
|
||||||
str((dataset_root_path / dataset_definition["train"]).resolve()) if dataset_definition["train"] else None
|
str((dataset_root_path / dataset_definition["train"]).resolve()) if dataset_definition["train"] else None
|
||||||
)
|
)
|
||||||
|
}
|
||||||
data_dict["test"] = (
|
data_dict["test"] = (
|
||||||
str((dataset_root_path / dataset_definition["test"]).resolve()) if dataset_definition["test"] else None
|
str((dataset_root_path / dataset_definition["test"]).resolve()) if dataset_definition["test"] else None
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in new issue
Block a user