forked from htcr/sam_road
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
30 lines (24 loc) · 923 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import yaml
from addict import Dict
from datetime import datetime
import os
def load_config(path):
with open(path) as file:
config_dict = yaml.safe_load(file)
return Dict(config_dict)
def create_output_dir_and_save_config(output_dir_prefix, config, specified_dir=None):
if specified_dir:
output_dir = specified_dir
else:
# Generate the output directory name with the current timestamp
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
output_dir = f"{output_dir_prefix}_{timestamp}"
# Create the directory if it doesn't exist
if not os.path.exists(output_dir):
os.makedirs(output_dir)
# Define the path for the config file
config_path = os.path.join(output_dir, "config.yaml")
# Save the config as a YAML file
with open(config_path, 'w') as file:
yaml.dump(config.to_dict(), file)
return output_dir