Skip to content

Commit

Permalink
update README for CNN model
Browse files Browse the repository at this point in the history
  • Loading branch information
JackonYang committed Jan 7, 2018
1 parent e29bd77 commit d0f4285
Showing 1 changed file with 127 additions and 19 deletions.
146 changes: 127 additions & 19 deletions README.md
Expand Up @@ -10,6 +10,9 @@ Follow the steps,
run the code,
and it works!

the easiest model requires only 2 convolutional layers.
accuracy is 90%+

There are several more steps to put this prototype on production.

**Ping me for paid technical supports**.
Expand Down Expand Up @@ -102,36 +105,117 @@ Navigate your web browser to `http://127.0.0.1:6006/` to view the TensorBoard.

## Solve Captcha Using CNN Model

#### 1-char captcha -- also covered in MNIST tutorial.
#### 1-char Captcha

the same 2-layer CNN model as talked in MNIST tutorial

1. 2 Convolutional layer.
2. Accuracy: 99%
1. 2 Convolutional layers.
2. Accuracy: 97%
3. Training data: 20000 images.
4. Time cost: <5min. using GTX-1080.
4. Time cost: <4min. using GTX-1080.

```bash
# generating test data
$ python datasets/gen_captcha.py -d --npi 1 -n 2000
# run the model
$ python cnn_1_char.py --data_dir images/char-1-epoch-2000/
```

Output While Training:

```bash
$ time python conv_captcha.py
$ $ time python cnn_1_char.py --data_dir images/char-1-epoch-2000/
data loaded
train images: 10000. test images: 2000
train images: 20000. test images: 4000
label_size: 10, image_size: 6000
...
step 9100, training accuracy = 100.00%, testing accuracy = 98.90%
step 9200, training accuracy = 100.00%, testing accuracy = 98.80%
step 9300, training accuracy = 100.00%, testing accuracy = 98.90%
step 9400, training accuracy = 100.00%, testing accuracy = 98.80%
step 9500, training accuracy = 100.00%, testing accuracy = 98.90%
step 9600, training accuracy = 100.00%, testing accuracy = 98.60%
step 9700, training accuracy = 100.00%, testing accuracy = 98.65%
step 9800, training accuracy = 100.00%, testing accuracy = 98.95%
step 9900, training accuracy = 100.00%, testing accuracy = 98.95%
testing accuracy = 99.15%
step 9100, training accuracy = 100.00%, testing accuracy = 96.60%
step 9200, training accuracy = 100.00%, testing accuracy = 97.80%
step 9300, training accuracy = 100.00%, testing accuracy = 97.65%
step 9400, training accuracy = 100.00%, testing accuracy = 97.95%
step 9500, training accuracy = 100.00%, testing accuracy = 97.25%
step 9600, training accuracy = 98.00%, testing accuracy = 96.80%
step 9700, training accuracy = 100.00%, testing accuracy = 97.70%
step 9800, training accuracy = 100.00%, testing accuracy = 97.25%
step 9900, training accuracy = 100.00%, testing accuracy = 95.40%
testing accuracy = 97.85%

real 3m35.217s
user 3m4.168s
sys 0m31.036s
```

#### 2-char Captcha

Add 1 more layer, reshape the output before calculating Loss.

1. Accuracy: 97%
3. Training data: 45000 images.
4. Time cost: <5min. using GTX-1080.

```bash
# generating test data
$ python datasets/gen_captcha.py -d --npi=2 -n 500
# run the model
$ python cnn_n_char.py --data_dir=images/char-2-epoch-500/
```

Output While Training:

```bash
$ time python cnn_n_char.py --data_dir=images/char-2-epoch-500/
data loaded
train images: 45000. test images: 9000
label_size: 10, image_size: 8000
...
step 9100, training accuracy = 99.00%, testing accuracy = 96.45%
step 9200, training accuracy = 100.00%, testing accuracy = 97.28%
step 9300, training accuracy = 100.00%, testing accuracy = 96.75%
step 9400, training accuracy = 100.00%, testing accuracy = 96.68%
step 9500, training accuracy = 100.00%, testing accuracy = 96.55%
step 9600, training accuracy = 100.00%, testing accuracy = 96.40%
step 9700, training accuracy = 100.00%, testing accuracy = 95.58%
step 9800, training accuracy = 99.00%, testing accuracy = 96.70%
step 9900, training accuracy = 99.00%, testing accuracy = 96.68%
testing accuracy = 97.33%

real 4m49.509s
user 4m10.980s
sys 0m34.164s
```

#### 4-char Captcha

the same model as 2-char captcha.

only change the training dataset to 4-char ones.

real 4m44.143s
user 3m40.896s
sys 0m33.492s
```bash
# generating test data
$ python datasets/gen_captcha.py -d --npi=4 -n 6
# run the model
$ python cnn_n_char.py --data_dir images/char-4-epoch-6/
```

Output While Training:

```bash
$ python cnn_n_char.py --data_dir images/char-4-epoch-6/
data loaded
train images: 30240. test images: 5040
label_size: 10, image_size: 12000
...
step 9100, training accuracy = 100.00%, testing accuracy = 92.73%
step 9200, training accuracy = 98.00%, testing accuracy = 92.86%
step 9300, training accuracy = 97.50%, testing accuracy = 91.74%
step 9400, training accuracy = 99.00%, testing accuracy = 92.84%
step 9500, training accuracy = 99.00%, testing accuracy = 92.99%
step 9600, training accuracy = 99.00%, testing accuracy = 93.78%
step 9700, training accuracy = 100.00%, testing accuracy = 92.56%
step 9800, training accuracy = 99.50%, testing accuracy = 93.01%
step 9900, training accuracy = 99.00%, testing accuracy = 92.84%
testing accuracy = 93.24%
```

## Generate DataSet for Training

Expand Down Expand Up @@ -222,3 +306,27 @@ test images: (7564, 100, 80), labels: (7564, 124)
1 epoch has `10*9*8*7=5040` images, generate 10 epoches for training.

generating the dataset:

```bash
$ python datasets/gen_captcha.py -d --npi=4 -n 6
10 choices: 0123456789
generating 6 epoches of captchas in ./images/char-4-epoch-6/train
generating 1 epoches of captchas in ./images/char-4-epoch-6/test
write meta info in ./images/char-4-epoch-6/meta.json
```

preview the dataset:

```bash
$ python datasets/base.py images/char-4-epoch-6/
========== Meta Info ==========
num_per_image: 4
label_choices: 0123456789
height: 100
width: 120
n_epoch: 6
label_size: 10
==============================
train images: (30240, 100, 120), labels: (30240, 40)
test images: (5040, 100, 120), labels: (5040, 40)
```

0 comments on commit d0f4285

Please sign in to comment.