O'Reilly logo

Python Deep Learning Cookbook by Indra den Bakker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required