Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions turtlebot3_dqn/turtlebot3_dqn/dqn_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def process(self):
while True:
local_step += 1

q_values = self.model.predict(state)
q_values = self.model.predict(state, verbose=0)
sum_max_q += float(numpy.max(q_values))

action = int(self.get_action(state))
Expand Down Expand Up @@ -246,9 +246,9 @@ def get_action(self, state):
if lucky > (1 - self.epsilon):
result = random.randint(0, self.action_size - 1)
else:
result = numpy.argmax(self.model.predict(state))
result = numpy.argmax(self.model.predict(state, verbose=0))
else:
result = numpy.argmax(self.model.predict(state))
result = numpy.argmax(self.model.predict(state, verbose=0))

return result

Expand Down Expand Up @@ -300,11 +300,11 @@ def train_model(self, terminal):

current_states = numpy.array([transition[0] for transition in data_in_mini_batch])
current_states = current_states.squeeze()
current_qvalues_list = self.model.predict(current_states)
current_qvalues_list = self.model.predict(current_states, verbose=0)

next_states = numpy.array([transition[3] for transition in data_in_mini_batch])
next_states = next_states.squeeze()
next_qvalues_list = self.target_model.predict(next_states)
next_qvalues_list = self.target_model.predict(next_states, verbose=0)

x_train = []
y_train = []
Expand Down
18 changes: 11 additions & 7 deletions turtlebot3_dqn/turtlebot3_dqn/dqn_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ def process(self):
action = int(self.get_action(state))

req = Dqn.Request()
print(int(action))
req.action = action
req.init = init

Expand Down Expand Up @@ -136,7 +135,13 @@ def process(self):
'Exception while calling service: {0}'.format(future.exception()))

break

if done:
print(
'Episode:', episode,
'score:', score,
'memory length:', len(self.memory),
'epsilon:', self.epsilon)

time.sleep(0.01)

def build_model(self):
Expand All @@ -161,8 +166,7 @@ def get_action(self, state):
return random.randrange(self.action_size)
else:
state = numpy.asarray(state)
q_value = self.model.predict(state.reshape(1, len(state)))
print(numpy.argmax(q_value[0]))
q_value = self.model.predict(state.reshape(1, len(state)), verbose=0)
return numpy.argmax(q_value[0])

def train_model(self, target_train_start=False):
Expand All @@ -177,13 +181,13 @@ def train_model(self, target_train_start=False):
next_state = numpy.asarray(mini_batch[i][3])
done = numpy.asarray(mini_batch[i][4])

q_value = self.model.predict(state.reshape(1, len(state)))
q_value = self.model.predict(state.reshape(1, len(state)), verbose=0)
self.max_q_value = numpy.max(q_value)

if not target_train_start:
target_value = self.model.predict(next_state.reshape(1, len(next_state)))
target_value = self.model.predict(next_state.reshape(1, len(next_state)), verbose=0)
else:
target_value = self.target_model.predict(next_state.reshape(1, len(next_state)))
target_value = self.target_model.predict(next_state.reshape(1, len(next_state)), verbose=0)

if done:
next_q_value = reward
Expand Down