Code Monkey home page Code Monkey logo

tensorflow-mnist-predict's Introduction

TensorFlowTM MNIST predict (recognise handwriting)

This repository accompanies the blog post Using TensorFlowTM to create your own handwriting recognition engine.

Installation & Setup

Overview

This project uses the MNIST tutorials from the TensorFlow website. The two tutorials, the beginner tutorial and the expert tutorial, use different deep learning models. The python scripts ending with _1 use the model from the beginner tutorial. The scripts ending with _2 use the model from the advanced tutorial. As expected scripts using the model from the expert tutorial give better results.

This projects consists of four scripts:

  1. create_model_1.py – creates a model model.ckpt file based on the beginners tutorial.
  2. create_model_1.py – creates a model model2.ckpt file based on the expert tutorial.
  3. predict_1.py – uses the model.ckpt (beginners tutorial) file to predict the correct integer form a handwritten number in a .png file.
  4. predict_2.py – uses the model2.ckpt (expert tutorial) file to predict the correct integer form a handwritten number in a .png file.

Dependencies

The following Python libraries are required.

Installing TensorFlow

Of course TensorFlow needs to be installed. The TensorFlow website has a good manual .

Installing Python Image Library (PIL)

The Python Image Library (PIL) is no longer available. Luckily there is a good fork called Pillow. Installing is as easy as:

sudo pip install Pillow

Or look at the Pillow documentation for other installation options.

The python scripts

The easiest way the use the scripts is to put all four scripts in the same folder. If TensorFlow is installed correctly the images to train the model are downloaded automatically.

Running

Running is based on the steps:

  1. create the model file
  2. create an image file containing a handwritten number
  3. predict the integer

1. create the model file

The easiest way is to cd to the directory where the python files are located. Then run:

python create_model_1.py

or

python create_model_2.py

to create the model based on the MNIST beginners tutorial (model_1) or the model based on the expert tutorial (model_2).

2. create an image file

You have to create a PNG file that contains a handwritten number. The background has to be white and the number has to be black. Any paint program should be able to do this. Also the image has to be auto cropped so that there is no border around the number.

3. predict the integer

The easiest way again is to put the image file from the previous step (step 2) in the same directory as the python scripts and cd to the directory where the python files are located.

The predict scripts require one argument: the file location of the image file containing the handwritten number. For example when the image file is ‘number1.png’ and is in the same location as the script, run:

python predict_1.py ‘number1.png’

or

python predict_2.py ‘number1.png’

The first script, predict_1.py, uses the model.ckpt file created by the create_model_1.py script. The second script, predict_2.py, uses the model2.ckpt file created by the create_model_2.py script.

tensorflow-mnist-predict's People

Contributors

niektemme avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.