Newbie about Deep Learning and TensorFlow?
Boring with MNIST?
Want a more interesting and complicated application?
This is for you. This repo contains a cnn model for recognizing numbers of captcha
CAPTCHA is kind of images that contains chars and digits for people to recognize, it is used in website log in to test you whether you are a robot or a person. In this repo we will develop a small convolutional neural network with TensorFlow to recognize it.
For simplicity, images will only contain four digits with noise
we say a image is classified correctly if and only if four digits inside this image are all classified correctly
Two sample images are listed below
python 2.7 with following packages installed should work fine
- numpy
- TensorFlow(verison >= 1.4) (because we will use
tf.data
) - captcha(you can install it with
pip install captcha
)
(anaconda environment is strongly recommended for managing these packages)
windows and python 3.X are not tested but should be OK.
GPU is not a must, but without it, training might be very slow.
-
Train and validation images are generated on the fly, doesn't need to download any big datasets.
-
Inputs of model is built on top of
tf.data
instead of old queue-based api, so reading the code combined with the official document abouttf.data
will help you understand how to write it yourself. -
Very short code, easy to read.
First clone this repo
git clone https://github.com/zakizhou/CAPTCHA
Before run training, training and validation images should be generated, change to the root dir of this repo and run
cd CAPTCHA
mkdir -p images/train
mkdir -p images/validation
mkdir -p tfrecords
mkdir -p save
python captcha_producer.py -n 30000 -p images/train
This will generate 30000 training images in the images/train/ and also convert infomation about
these images into tfrecords/train.tfrecords
file.
for validation set:
python captcha_producer.py -n 3000 -p "images/validation"
Now you can run this model with
python captcha_train.py
After 10000 steps (you can manually change num of steps in captcha_train.py
file) training on single GTX1060, this model achieved
around 70% accuracy, adjusting the scale of parameters or adding dropout
should still improve this performance
images/train
andimages/validation
will contains generated train and validation imagestfrecords
will contains about generated tfrecords(train.tfrecords
,validation.tfrecords
)save
will contains saved model after trainingcaptcha_producer.py
is used to generate images and tfrecordscaptcha_model.py
contains utils functions for defining the modelcaptcha_data.py
is used for build input for modelcaptcha_config.py
contains configs for modelcaptcha_train.py
is used for training model
- add multi gpu training code
- add tensorboard code
- add functions for keep on training after shutdown