How to do it...

  1. Let's start with importing the necessary libraries, as follows:
import gymimport randomimport numpy as npimport matplotlib.pyplot as pltfrom collections import dequefrom keras.models import Sequentialfrom keras.optimizers import Adamfrom keras.layers import Dense, Flattenfrom keras.layers.convolutional import Conv2Dfrom keras import backend as K
  1. First, we will plot an example input image of the game:
Figure 11.1: Example input image of Breakout by OpenAI
env = gym.make('BreakoutDeterministic-v4')observation = env.reset()for i in range(3):    # The ball is released after 2 frames    if i > 1:        print(observation.shape) plt.imshow(observation) ...

Get Python Deep Learning Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.