Train mnist using your own images

Table of Contents

  • [Introduction]
  • [Method]
    • [Step One]
    • Step Two
    • Step Three
  • Example results

Introduction

In tensorflow.org there are MNIST For ML Beginners and Deep MNIST for Experts for learning.

In these tutorials, the training source is from MNIST. It is awesome, containing thousands of images.

But there are some situations that we want to use our own images for training. I have searched on the Internet and could hardly find the direct way to convert images into MNIST Database format. So I just do it myself and have found another way to create my data files and train it in the tensorflow.

Method

Step One

You should first have some images for training. You can use your own images or use my images for a try.

The images like the following, should have a black background and a white number.

Train mnist using your own images_第1张图片
image

Step Two

I have writed some Matlab code to convert your images into image data and create label data. These data are in binary format and have .txt suffix. Here shows the data format in these data file.

Train mnist using your own images_第2张图片
image

After generating, these four files should like the following:

trainImage.txt
trainImageLabel.txt
testImage.txt
testImageLabel.txt

And then you should use gzipCreate.py to convert these files into '.gz' files.

trainImage.txt.gz
trainImageLabel.txt.gz
testImage.txt.gz
testImageLabel.txt.gz

Until now, the training files are ready.(training files can be find in this repository)

Step Three

I have done some changes to tensorflow's mnist example code. You can use lswBeginnerMnist.py for simple mnist training or use lswDeepMnist.py for deep mnist training.

Example results

Result of lswBeginnerMnist.py training , 29 images.

Train mnist using your own images_第3张图片
image

Result of lswDeepMnist.py training , 36 images.

Train mnist using your own images_第4张图片
image

My Github:LinShiwei (Lin Shiwei) · GitHub

你可能感兴趣的:(Train mnist using your own images)