Book Image

Artificial Intelligence with Python

Book Image

Artificial Intelligence with Python

Overview of this book

Artificial Intelligence is becoming increasingly relevant in the modern world. By harnessing the power of algorithms, you can create apps which intelligently interact with the world around you, building intelligent recommender systems, automatic speech recognition systems and more. Starting with AI basics you'll move on to learn how to develop building blocks using data mining techniques. Discover how to make informed decisions about which algorithms to use, and how to apply them to real-world scenarios. This practical book covers a range of topics including predictive analytics and deep learning.
Table of Contents (23 chapters)
Artificial Intelligence with Python
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Building an image classifier using a Convolutional Neural Network


The image classifier in the previous section didn't perform well. Getting 92.1% on MNIST dataset is relatively easy. Let's see how we can use Convolutional Neural Networks (CNNs) to achieve a much higher accuracy. We will build an image classifier using the same dataset, but with a CNN instead of a single layer neural network.

Create a new python and import the following packages:

import argparse 
 
import tensorflow as tf 
from tensorflow.examples.tutorials.mnist import input_data 

Define a function to parse the input arguments:

def build_arg_parser(): 
    parser = argparse.ArgumentParser(description='Build a CNN classifier \ 
            using MNIST data') 
    parser.add_argument('--input-dir', dest='input_dir', type=str,  
            default='./mnist_data', help='Directory for storing data') 
    return parser 

Define a function to create values for weights in each layer...