MCPcopy Create free account
hub / github.com/Farama-Foundation/ViZDoom / run

Function run

examples/python/learning_tensorflow.py:178–222  ·  view source on GitHub ↗
(agent, game, replay_memory)

Source from the content-addressed store, hash-verified

176
177
178def run(agent, game, replay_memory):
179 time_start = time()
180
181 for episode in range(num_train_epochs):
182 train_scores = []
183 print("\nEpoch %d\n-------" % (episode + 1))
184
185 game.new_episode()
186
187 for i in trange(learning_steps_per_epoch, leave=False):
188 state = game.get_state()
189 screen_buf = preprocess(state.screen_buffer)
190 action = agent.choose_action(screen_buf)
191 reward = game.make_action(actions[action], frames_per_action)
192 done = game.is_episode_finished()
193
194 if not done:
195 next_screen_buf = preprocess(game.get_state().screen_buffer)
196 else:
197 next_screen_buf = tf.zeros(shape=screen_buf.shape)
198
199 if done:
200 train_scores.append(game.get_total_reward())
201
202 game.new_episode()
203
204 replay_memory.append((screen_buf, action, reward, next_screen_buf, done))
205
206 if i >= batch_size:
207 agent.train_dqn(get_samples(replay_memory))
208
209 if (i % target_net_update_steps) == 0:
210 agent.update_target_net()
211
212 train_scores = np.array(train_scores)
213 print(
214 "Results: mean: {:.1f}±{:.1f},".format(
215 train_scores.mean(), train_scores.std()
216 ),
217 "min: %.1f," % train_scores.min(),
218 "max: %.1f," % train_scores.max(),
219 )
220
221 test(test_episodes_per_epoch, game, agent)
222 print("Total elapsed time: %.2f minutes" % ((time() - time_start) / 60.0))
223
224
225def test(test_episodes_per_epoch, game, agent):

Callers 1

Calls 6

get_samplesFunction · 0.85
choose_actionMethod · 0.80
train_dqnMethod · 0.80
preprocessFunction · 0.70
testFunction · 0.70
update_target_netMethod · 0.45

Tested by

no test coverage detected