-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
53 lines (37 loc) · 1.28 KB
/
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import os
import yaml
import argparse
import torch
import pandas as pd
from dqn_agent import DQNAgent
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('-pc', '--path_config', required=True, type=str,
help='path to the experiment config file')
args = parser.parse_args()
return args
def read_yaml(path_file: str) -> dict:
"""Reads the experiment's config file.
:param path_file: Location of the yaml config file
:return: Experiment config in a dictionary
"""
path_dir = os.path.dirname(__file__)
with open(os.path.join(path_dir, 'experiments', path_file)) as stream:
config = yaml.load(stream, Loader=yaml.Loader)
return config
def save_scores(conf: dict, stats: dict) -> None:
df_stats = pd.DataFrame(stats)
path_save = os.path.join(
os.path.dirname(__file__),
'artifacts',
'_'.join(conf['tags']) + '.csv'
)
df_stats.to_csv(path_save, index=False)
def save_model(conf: dict, agent: DQNAgent) -> None:
path_save_model = os.path.join(
os.path.dirname(__file__),
'artifacts',
'saved_models',
'_'.join(conf['tags'] + [conf['model_to_use'][1]]) + '.pth'
)
torch.save(agent.policy_net.state_dict(), path_save_model)