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 single layer neural network


Let's see how to create a single layer neural network using TensorFlow and use it to build an image classifier. We will be using MNIST image dataset to build our system. It is dataset containing handwritten images of digits. Our goal is to build a classifier that can correctly identify the digit in each image.

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 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 the main function and parse the input arguments:

if __name__ == '__main__': 
...