美文网首页
Train mnist using your own image

Train mnist using your own image

作者: Linsw | 来源:发表于2016-12-01 16:46 被阅读106次

Table of Contents

<a id="1"></a>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.

<a id="2"></a>Method

<a id="21"></a>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.

imageimage

<a id="22"></a>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.

imageimage

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)

<a id="23"></a>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.

<a id="3"></a>Example results

Result of lswBeginnerMnist.py training , 29 images.

imageimage

Result of lswDeepMnist.py training , 36 images.

imageimage

My Github:LinShiwei (Lin Shiwei) · GitHub

相关文章

网友评论

      本文标题:Train mnist using your own image

      本文链接:https://www.haomeiwen.com/subject/sroxmttx.html