Skip to content
Snippets Groups Projects
Commit 8e575e06 authored by Armin Co's avatar Armin Co
Browse files

Added offline batchsize option

Load both networks for double q agent
parent 4a0dc96d
Branches
No related tags found
No related merge requests found
...@@ -3,6 +3,7 @@ __pycache__ ...@@ -3,6 +3,7 @@ __pycache__
saved_agents saved_agents
benchmarks benchmarks
baselines baselines
simple
workspace.code-workspace workspace.code-workspace
test test
tech_demo.py tech_demo.py
......
...@@ -20,6 +20,7 @@ class QAgent: ...@@ -20,6 +20,7 @@ class QAgent:
self.action_space = conf.env.action_space.n self.action_space = conf.env.action_space.n
self.name = conf.name self.name = conf.name
self.epsilon_decay = conf.eps_decay self.epsilon_decay = conf.eps_decay
self.OFFLINE_BATCHSIZE = conf.offline_batchsize
def get_action(self, state): def get_action(self, state):
if np.random.rand() <= self.epsilon: if np.random.rand() <= self.epsilon:
...@@ -80,7 +81,7 @@ class DQAgent(QAgent): ...@@ -80,7 +81,7 @@ class DQAgent(QAgent):
def get_action(self, state): def get_action(self, state):
if np.random.rand() <= self.epsilon: if np.random.rand() <= self.epsilon:
return random.randrange(self.action_space) return random.randrange(self.action_space)
action_values = (self.q.predict(state) + self.q2.predict(state)) / 2 action_values = self.q.predict(state)
return np.argmax(action_values[0]) return np.argmax(action_values[0])
def learn(self, offline=False, epochs=1): def learn(self, offline=False, epochs=1):
...@@ -110,6 +111,15 @@ class DQAgent(QAgent): ...@@ -110,6 +111,15 @@ class DQAgent(QAgent):
self.epsilon *= self.epsilon_decay self.epsilon *= self.epsilon_decay
return loss return loss
def load(self, path, net=True, memory=True):
print('Load: ' + path)
if net:
print('Network')
self.q.load(path+'.net')
self.q2.load(path+'.net')
if memory:
self.memory.load(path+'.mem')
class CarlaManual(QAgent): class CarlaManual(QAgent):
control = None control = None
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment