看了《深度學習世界深度學習世界深度學習世界深度學習世界》2017-12-21 的文章「驗證碼,再見!利用機器學習在15分鐘內破解驗證碼」,以爲簡單易行,對於深度學習新手來講動手實踐的可行性很強。遂決定親手實踐一下,體驗深度學習在解決實際問題方面的威力。python
安裝OpenCV3. 具體過程略。算法
https://s3-us-west-2.amazonaws.com/mlif-example-code/solving_captchas_code_examples.zipshell
源代碼目錄solving_captchas_code_examples下的子目錄generated_captcha_images下原有9955個圖片windows
子目錄extracted_letter_images中是空的。網絡
運行命令:機器學習
python extract_single_letters_from_captchas.py學習
運行完成後,\extracted_letter_images下產生32個目錄。存放切割出來的單字母圖片。如:測試
python train_model.py操作系統
PS F:\test\solving_captchas_code_examples> python train_model.py3d
Using TensorFlow backend.
Train on 29058 samples, validate on 9686 samples
Epoch 1/10
29058/29058 [==============================] - 97s - loss: 0.2419 - acc: 0.9395 - val_loss: 0.0233 - val_acc: 0.9937
Epoch 2/10
29058/29058 [==============================] - 96s - loss: 0.0150 - acc: 0.9966 - val_loss: 0.0109 - val_acc: 0.9966
Epoch 3/10
29058/29058 [==============================] - 98s - loss: 0.0102 - acc: 0.9970 - val_loss: 0.0132 - val_acc: 0.9962
Epoch 4/10
29058/29058 [==============================] - 97s - loss: 0.0057 - acc: 0.9986 - val_loss: 0.0140 - val_acc: 0.9968
Epoch 5/10
29058/29058 [==============================] - 100s - loss: 0.0042 - acc: 0.9987 - val_loss: 0.0099 - val_acc: 0.9971
Epoch 6/10
29058/29058 [==============================] - 96s - loss: 0.0080 - acc: 0.9980 - val_loss: 0.0120 - val_acc: 0.9975
Epoch 7/10
29058/29058 [==============================] - 96s - loss: 0.0028 - acc: 0.9991 - val_loss: 0.0086 - val_acc: 0.9976
Epoch 8/10
29058/29058 [==============================] - 95s - loss: 0.0028 - acc: 0.9992 - val_loss: 0.0073 - val_acc: 0.9981
Epoch 9/10
29058/29058 [==============================] - 96s - loss: 0.0050 - acc: 0.9987 - val_loss: 0.0100 - val_acc: 0.9974
Epoch 10/10
29058/29058 [==============================] - 97s - loss: 0.0052 - acc: 0.9990 - val_loss: 0.0084 - val_acc: 0.9980
python3 solve_captchas_with_model.py
CAPTCHA text is: PQDR
CAPTCHA text is: T324
CAPTCHA text is: FPV3
CAPTCHA text is: H72Z
CAPTCHA text is: FCBP
CAPTCHA text is: 29LY
CAPTCHA text is: 36YG
CAPTCHA text is: M3C5
CAPTCHA text is: 32Y7
CAPTCHA text is: 6GQ6
能夠看到,因爲是從訓練數據中隨機抽取驗證碼圖片進行識別,識別率所有正確。
從下圖看出,即便字符粘連,也能正確識別。說明字符切割和單字符的訓練算法是有效的。