Book Image

AI Crash Course

By : Hadelin de Ponteves
5 (2)
Book Image

AI Crash Course

5 (2)
By: Hadelin de Ponteves

Overview of this book

Welcome to the Robot World … and start building intelligent software now! Through his best-selling video courses, Hadelin de Ponteves has taught hundreds of thousands of people to write AI software. Now, for the first time, his hands-on, energetic approach is available as a book. Starting with the basics before easing you into more complicated formulas and notation, AI Crash Course gives you everything you need to build AI systems with reinforcement learning and deep learning. Five full working projects put the ideas into action, showing step-by-step how to build intelligent software using the best and easiest tools for AI programming, including Python, TensorFlow, Keras, and PyTorch. AI Crash Course teaches everyone to build an AI to work in their applications. Once you've read this book, you're only limited by your imagination.
Table of Contents (17 chapters)
16
Index

Implementation

You'll implement the entire AI code and the Snake game in five files:

  1. environment.py file – The file containing the environment (Snake game)
  2. brain.py file – The file in which we build our CNN
  3. DQN.py – The file that builds the Experience Replay Memory
  4. train.py – The file where we will train our AI to play Snake
  5. test.py – The file where we will test our AI to see how well it performs

You can find all of them on the GitHub page along with a pre-trained model. To get there, select Chapter 13 folder on the main page.

We'll go through each file in the same order. Let's start building the environment!

Step 1 – Building the environment

Start this first, important step by importing the libraries you'll need. Like this:

# Importing the libraries   #4
import numpy as np   #5
import pygame as pg   #6

You'll only use two libraries: NumPy and PyGame. The former...