-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparams.py
80 lines (64 loc) · 2.57 KB
/
params.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import time
import os
import random
import datetime
class Params:
def __init__(self):
self.map = 'exp1' # one of 'exp1' 'exp2' 'exp3' 'exp4'
# Configs for running trains/test
self.num_train_processes = 20
if self.map in ['exp1', 'exp3']:
self.train_maps = [f'multitarget-visnav-{self.map}-v1'] * self.num_train_processes
elif self.map in ['exp2', 'exp4']:
self.train_maps = [f'multitarget-visnav-{self.map}-seen-v1'] * self.num_train_processes
else:
raise ValueError('self.map must be provided as exp{1,2,3,4}.')
if self.map in ['exp1', 'exp3']:
self.eval_maps = [f'multitarget-visnav-{self.map}-v1']
else:
self.eval_maps = [f'multitarget-visnav-{self.map}-seen-v1',
f'multitarget-visnav-{self.map}-unseen-v1']
self.num_test_processes = len(self.eval_maps)
self.n_eval = 500
self.gpu_ids_train = [0, 1]
self.gpu_ids_test = [0, 1]
self.seed = random.randint(0, 10000)
# Model/optimizer hyperparameters
self.gamma = 0.99
self.entropy_coef = 0.01
self.lr = 7e-5
self.tau = 1.0
self.clip_grad_norm = 10.0
self.value_loss_coef = 0.5
self.amsgrad = True
self.goal_coef = 0.5
self.goal_batch_size = 50
self.minimum_warmup = self.num_train_processes * 100
self.weight_decay = 0
# Gym environment settings
self.scaled_resolution = (42, 42)
self.living_reward = -0.0025 # 4-frame stack, so living reward is quadrupled
self.goal_reward = 10.0
self.non_goal_penalty = 1.0
self.non_goal_break = True
self.timeout_penalty = 0.1
# Logging-related
now = datetime.datetime.now()
nowDate = now.strftime('%Y-%m-%d-%H:%M:%S')
self.log_file = nowDate
if not os.path.exists('./wgt'):
os.mkdir('./wgt')
self.weight_dir = './wgt/{}_wgt/'.format(nowDate)
params = Params()
def log_params():
path = './log/{}'.format(params.log_file)
msg = str('start time\t{}\n'.format(time.strftime('%X %x %Z')))
params_dict = params.__dict__
for key in params_dict.keys():
msg += '{}\t{}\n'.format(key, str(params_dict[key]))
msg += '\n' + '\t'.join(['time', 'numUpdates', 'mapId', 'saveModelIdx', 'avgReward', 'avgLength', 'successRate', 'bestRate']) + '\n'
csv_path = path + '.csv'
if not os.path.isdir('./log'):
os.mkdir('./log')
with open(csv_path, 'w') as file:
file.write(msg)