forked from praveenVnktsh/CarRacingv0-PPO-pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
65 lines (43 loc) · 1.53 KB
/
config.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
import torch
import os
import numpy as np
class Args():
def __init__(self):
self.checkpoint = 622
trial = 5
self.test = False
self.gamma = 0.99
self.action_repeat = 4
self.valueStackSize = 8
self.actionStack = 0
self.seed = 0
self.numberOfLasers = 5
self.deathThreshold = 2000
self.clip_param = 0.4
self.ppo_epoch = 10
self.buffer_capacity = 500
self.batch_size = 128
self.deathByGreeneryThreshold = 35
self.maxDistance = 100
self.actionMultiplier = np.array([2., 1.0, 1.0])
self.actionBias = np.array([-1.0, 0.0, 0.0])
saveloc = 'model/distances/train_' + str(trial) + '/'
self.saveLocation = saveloc
os.makedirs(self.saveLocation, exist_ok = True)
f = open(saveloc + 'params.json','w')
f.write(str(self.getParamsDict()))
f.close()
def getParamsDict(self):
ret = {key:value for key, value in self.__dict__.items() if not key.startswith('__') and not callable(key)}
print('\nHYPERPARAMETERS = ', ret)
return ret
def actionTransformation(self, action):
return action*self.actionMultiplier + self.actionBias
def configure():
args = Args()
use_cuda = torch.cuda.is_available()
device = torch.device("cuda" if use_cuda else "cpu")
torch.manual_seed(args.seed)
if use_cuda:
torch.cuda.manual_seed(args.seed)
return args, use_cuda, device