Table of Contents
- [Introduction]
- [Method]
- [Step One]
- Step Two
- Step Three
- Example results
<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.
<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.
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.
Result of lswDeepMnist.py training , 36 images.
My Github:LinShiwei (Lin Shiwei) · GitHub