10. Playing an Atari Game with Deep Recurrent Q-Networks
Activity 10.01: Training a DQN with CNNs to Play Breakout
Solution
- Open a new Jupyter Notebook and import the relevant packages:
gym
,random
,tensorflow
,numpy
, andcollections
:import gym import random import numpy as np from collections import deque import tensorflow as tf from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Dense, Conv2D, \ MaxPooling2D, Flatten from tensorflow.keras.optimizers import RMSprop import datetime
- Set the seed for NumPy and TensorFlow to
168
:np.random.seed(168) tf.random.set_seed(168)
- Create the
DQN
class with the following methods: thebuild_model()
method to instantiate a CNN, theget_action()
method to apply the epsilon-greedy algorithm to choose the action to be played, theadd_experience()
method to store in memory the experience acquired by playing the game, thereplay()
method, which will perform experience replay by sampling experiences from...