@@ -10,6 +10,9 @@ Follow the steps,
10
10
run the code,
11
11
and it works!
12
12
13
+ the easiest model requires only 2 convolutional layers.
14
+ accuracy is 90%+
15
+
13
16
There are several more steps to put this prototype on production.
14
17
15
18
** Ping me for paid technical supports** .
@@ -102,36 +105,117 @@ Navigate your web browser to `http://127.0.0.1:6006/` to view the TensorBoard.
102
105
103
106
## Solve Captcha Using CNN Model
104
107
105
- #### 1-char captcha -- also covered in MNIST tutorial.
108
+ #### 1-char Captcha
109
+
110
+ the same 2-layer CNN model as talked in MNIST tutorial
106
111
107
- 1 . 2 Convolutional layer .
108
- 2 . Accuracy: 99 %
112
+ 1 . 2 Convolutional layers .
113
+ 2 . Accuracy: 97 %
109
114
3 . Training data: 20000 images.
110
- 4 . Time cost: <5min. using GTX-1080.
115
+ 4 . Time cost: <4min. using GTX-1080.
116
+
117
+ ``` bash
118
+ # generating test data
119
+ $ python datasets/gen_captcha.py -d --npi 1 -n 2000
120
+ # run the model
121
+ $ python cnn_1_char.py --data_dir images/char-1-epoch-2000/
122
+ ```
111
123
124
+ Output While Training:
112
125
113
126
``` bash
114
- $ time python conv_captcha .py
127
+ $ $ time python cnn_1_char .py --data_dir images/char-1-epoch-2000/
115
128
data loaded
116
- train images: 10000 . test images: 2000
129
+ train images: 20000 . test images: 4000
117
130
label_size: 10, image_size: 6000
118
131
...
119
- step 9100, training accuracy = 100.00%, testing accuracy = 98.90%
120
- step 9200, training accuracy = 100.00%, testing accuracy = 98.80%
121
- step 9300, training accuracy = 100.00%, testing accuracy = 98.90%
122
- step 9400, training accuracy = 100.00%, testing accuracy = 98.80%
123
- step 9500, training accuracy = 100.00%, testing accuracy = 98.90%
124
- step 9600, training accuracy = 100.00%, testing accuracy = 98.60%
125
- step 9700, training accuracy = 100.00%, testing accuracy = 98.65%
126
- step 9800, training accuracy = 100.00%, testing accuracy = 98.95%
127
- step 9900, training accuracy = 100.00%, testing accuracy = 98.95%
128
- testing accuracy = 99.15%
132
+ step 9100, training accuracy = 100.00%, testing accuracy = 96.60%
133
+ step 9200, training accuracy = 100.00%, testing accuracy = 97.80%
134
+ step 9300, training accuracy = 100.00%, testing accuracy = 97.65%
135
+ step 9400, training accuracy = 100.00%, testing accuracy = 97.95%
136
+ step 9500, training accuracy = 100.00%, testing accuracy = 97.25%
137
+ step 9600, training accuracy = 98.00%, testing accuracy = 96.80%
138
+ step 9700, training accuracy = 100.00%, testing accuracy = 97.70%
139
+ step 9800, training accuracy = 100.00%, testing accuracy = 97.25%
140
+ step 9900, training accuracy = 100.00%, testing accuracy = 95.40%
141
+ testing accuracy = 97.85%
142
+
143
+ real 3m35.217s
144
+ user 3m4.168s
145
+ sys 0m31.036s
146
+ ```
147
+
148
+ #### 2-char Captcha
149
+
150
+ Add 1 more layer, reshape the output before calculating Loss.
151
+
152
+ 1 . Accuracy: 97%
153
+ 3 . Training data: 45000 images.
154
+ 4 . Time cost: <5min. using GTX-1080.
155
+
156
+ ``` bash
157
+ # generating test data
158
+ $ python datasets/gen_captcha.py -d --npi=2 -n 500
159
+ # run the model
160
+ $ python cnn_n_char.py --data_dir=images/char-2-epoch-500/
161
+ ```
162
+
163
+ Output While Training:
164
+
165
+ ``` bash
166
+ $ time python cnn_n_char.py --data_dir=images/char-2-epoch-500/
167
+ data loaded
168
+ train images: 45000. test images: 9000
169
+ label_size: 10, image_size: 8000
170
+ ...
171
+ step 9100, training accuracy = 99.00%, testing accuracy = 96.45%
172
+ step 9200, training accuracy = 100.00%, testing accuracy = 97.28%
173
+ step 9300, training accuracy = 100.00%, testing accuracy = 96.75%
174
+ step 9400, training accuracy = 100.00%, testing accuracy = 96.68%
175
+ step 9500, training accuracy = 100.00%, testing accuracy = 96.55%
176
+ step 9600, training accuracy = 100.00%, testing accuracy = 96.40%
177
+ step 9700, training accuracy = 100.00%, testing accuracy = 95.58%
178
+ step 9800, training accuracy = 99.00%, testing accuracy = 96.70%
179
+ step 9900, training accuracy = 99.00%, testing accuracy = 96.68%
180
+ testing accuracy = 97.33%
181
+
182
+ real 4m49.509s
183
+ user 4m10.980s
184
+ sys 0m34.164s
185
+ ```
186
+
187
+ #### 4-char Captcha
188
+
189
+ the same model as 2-char captcha.
190
+
191
+ only change the training dataset to 4-char ones.
129
192
130
- real 4m44.143s
131
- user 3m40.896s
132
- sys 0m33.492s
193
+ ``` bash
194
+ # generating test data
195
+ $ python datasets/gen_captcha.py -d --npi=4 -n 6
196
+ # run the model
197
+ $ python cnn_n_char.py --data_dir images/char-4-epoch-6/
133
198
```
134
199
200
+ Output While Training:
201
+
202
+ ``` bash
203
+ $ python cnn_n_char.py --data_dir images/char-4-epoch-6/
204
+ data loaded
205
+ train images: 30240. test images: 5040
206
+ label_size: 10, image_size: 12000
207
+ ...
208
+ step 9100, training accuracy = 100.00%, testing accuracy = 92.73%
209
+ step 9200, training accuracy = 98.00%, testing accuracy = 92.86%
210
+ step 9300, training accuracy = 97.50%, testing accuracy = 91.74%
211
+ step 9400, training accuracy = 99.00%, testing accuracy = 92.84%
212
+ step 9500, training accuracy = 99.00%, testing accuracy = 92.99%
213
+ step 9600, training accuracy = 99.00%, testing accuracy = 93.78%
214
+ step 9700, training accuracy = 100.00%, testing accuracy = 92.56%
215
+ step 9800, training accuracy = 99.50%, testing accuracy = 93.01%
216
+ step 9900, training accuracy = 99.00%, testing accuracy = 92.84%
217
+ testing accuracy = 93.24%
218
+ ```
135
219
136
220
## Generate DataSet for Training
137
221
@@ -222,3 +306,27 @@ test images: (7564, 100, 80), labels: (7564, 124)
222
306
1 epoch has ` 10*9*8*7=5040 ` images, generate 10 epoches for training.
223
307
224
308
generating the dataset:
309
+
310
+ ``` bash
311
+ $ python datasets/gen_captcha.py -d --npi=4 -n 6
312
+ 10 choices: 0123456789
313
+ generating 6 epoches of captchas in ./images/char-4-epoch-6/train
314
+ generating 1 epoches of captchas in ./images/char-4-epoch-6/test
315
+ write meta info in ./images/char-4-epoch-6/meta.json
316
+ ```
317
+
318
+ preview the dataset:
319
+
320
+ ``` bash
321
+ $ python datasets/base.py images/char-4-epoch-6/
322
+ ========== Meta Info ==========
323
+ num_per_image: 4
324
+ label_choices: 0123456789
325
+ height: 100
326
+ width: 120
327
+ n_epoch: 6
328
+ label_size: 10
329
+ ==============================
330
+ train images: (30240, 100, 120), labels: (30240, 40)
331
+ test images: (5040, 100, 120), labels: (5040, 40)
332
+ ```
0 commit comments