How to do it...

  1. First, we import the necessary libraries, as follows:
import numpy as npimport gymimport tensorflow as tfimport matplotlib.pyplot as plt
  1. Let's set up the Pong environment and plot a frame:
Figures 5.1: Frame of the Pong game by OpenAI
env = gym.make("Pong-v0") # environment infoobservation = env.reset()for i in range(22):    # The ball is released after 20 frames    if i > 20:        plt.imshow(observation)        plt.show()        # Get the next observation    observation, _, _, _ = env.step(1)
  1. Before we implement the algorithm, we need a function that preprocesses the input data:
def preprocess_frame(frame): # remove top part of frame and some ...

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.