Skip to content

高鐵訂票驗證碼,使用Python、Keras (Tensorflow)、CNN

Notifications You must be signed in to change notification settings

vi000246/thsrc_captcha

 
 

Repository files navigation

HTSRC 高鐵訂票驗證碼

免責條款

此專案是個人學習如何使用 Deep Learning 中的 CNN,使用 Python 的 Keras、Tensorflow 進行實作,請勿使用於不法用途。若因使用該專案而大量訂票,相關的刑事、民事相關責任,請自行負責。

參考資料

其實基本上都是依照下面三個參考資料在實作,所以有疑問請在參考一下這些資料。

gary9987/-Keras-Python3.6-captcha

[爬蟲實戰] 如何破解高鐵驗證碼 (1) - 去除圖片噪音點?

[爬蟲實戰] 如何破解高鐵驗證碼 (2) - 使用迴歸方法去除多餘弧線?

Dependencies

2020-10-31 更新,使用 python 3.7 更新部分套件 請先安裝相關的 python 套件

pip3 install -r requirements.txt

步驟

大致上分為四個步驟,以下會分步驟說明

  • 爬蟲
  • 預處理
  • 標記圖片
  • CNN深度學習

爬蟲

爬蟲請參考 crawler.ipynb 和編譯出來的 crawler.py。此程式使用 Selenium Chrome driver 去抓取高鐵螢幕截圖,再切割出驗證碼圖片存入至 captcha 目錄下。

需要注意的是,因為我使用 Macbook Pro 的 Retina 螢幕,使用螢幕截圖時,解析度會自動變為2倍,所以中間有一段程式在處理這個 ratio,不過最後都存成 140 x 48 的圖片。

檔案列表:

# ipython notebook 檔 python檔
1 crawler.ipynb crawler.py

預處理

圖片預處理就參考參考資料的 youtube 教學影片,比較麻煩的是處理上方一條線。這部分我認為預處理沒有作的比參考資料1弄的漂亮,主要是因為其實高鐵的驗證碼圖片大小不是固定的,若是刪除此弧線若是可以根據圖片的高度,這樣效果會更好,但是我基本上分為三個步驟處理圖片,沒有把步驟1和步驟2合起來處理。

2020-10-31 更新,目前加了上下的 padding,使圖片變成一個 140 x 140 矩形,以方便直接套用模型使用

檔案列表:

# ipython notebook 檔 python檔
1 preprocess.ipynb
2 preprocess-batch.ipynb preprocess-batch.py

標記圖片

標記圖片花了很多時間,所以中間衍生我弄了另外一個專案 label_captcha_tool。主要是因為找了一些標記工具,發現有些是 windows 的,而或者是安裝有點麻煩,不如我就自己寫了一套網頁的版本,當然好處就是可以跨平台,也就是一個 html 而已,也不用安裝,算是大大節省我的時間。

這邊就標記檔,存成為 csv (label.csv),每一個圖片一行,之後要丟入 CNN 當作 label 的訓練資料。

CNN深度學習

CNN部分就直接使用參考資料1,這部分優化比較少

# ipython notebook 檔 python檔
1 cnn.ipynb

這邊就標記檔,存成為 csv,每一個圖片一行,之後要丟入 CNN 當作 label 的訓練資料。

model.summary()

Model: "functional_1"
__________________________________________________________________________________________________
Layer (type)                    Output Shape         Param #     Connected to                     
==================================================================================================
input_1 (InputLayer)            [(None, 140, 140, 3) 0                                            
__________________________________________________________________________________________________
conv1_pad (ZeroPadding2D)       (None, 146, 146, 3)  0           input_1[0][0]                    
__________________________________________________________________________________________________
conv1_conv (Conv2D)             (None, 70, 70, 64)   9472        conv1_pad[0][0]                  
__________________________________________________________________________________________________
conv1_bn (BatchNormalization)   (None, 70, 70, 64)   256         conv1_conv[0][0]                 
__________________________________________________________________________________________________
conv1_relu (Activation)         (None, 70, 70, 64)   0           conv1_bn[0][0]                   
__________________________________________________________________________________________________
pool1_pad (ZeroPadding2D)       (None, 72, 72, 64)   0           conv1_relu[0][0]                 
__________________________________________________________________________________________________
pool1_pool (MaxPooling2D)       (None, 35, 35, 64)   0           pool1_pad[0][0]                  
__________________________________________________________________________________________________
conv2_block1_1_conv (Conv2D)    (None, 35, 35, 64)   4160        pool1_pool[0][0]                 
__________________________________________________________________________________________________
conv2_block1_1_bn (BatchNormali (None, 35, 35, 64)   256         conv2_block1_1_conv[0][0]        
__________________________________________________________________________________________________
conv2_block1_1_relu (Activation (None, 35, 35, 64)   0           conv2_block1_1_bn[0][0]          
__________________________________________________________________________________________________
conv2_block1_2_conv (Conv2D)    (None, 35, 35, 64)   36928       conv2_block1_1_relu[0][0]        
__________________________________________________________________________________________________
conv2_block1_2_bn (BatchNormali (None, 35, 35, 64)   256         conv2_block1_2_conv[0][0]        
__________________________________________________________________________________________________
conv2_block1_2_relu (Activation (None, 35, 35, 64)   0           conv2_block1_2_bn[0][0]          
__________________________________________________________________________________________________
conv2_block1_0_conv (Conv2D)    (None, 35, 35, 256)  16640       pool1_pool[0][0]                 
__________________________________________________________________________________________________
conv2_block1_3_conv (Conv2D)    (None, 35, 35, 256)  16640       conv2_block1_2_relu[0][0]        
__________________________________________________________________________________________________
conv2_block1_0_bn (BatchNormali (None, 35, 35, 256)  1024        conv2_block1_0_conv[0][0]        
__________________________________________________________________________________________________
conv2_block1_3_bn (BatchNormali (None, 35, 35, 256)  1024        conv2_block1_3_conv[0][0]        
__________________________________________________________________________________________________
conv2_block1_add (Add)          (None, 35, 35, 256)  0           conv2_block1_0_bn[0][0]          
                                                                 conv2_block1_3_bn[0][0]          
__________________________________________________________________________________________________
conv2_block1_out (Activation)   (None, 35, 35, 256)  0           conv2_block1_add[0][0]           
__________________________________________________________________________________________________
conv2_block2_1_conv (Conv2D)    (None, 35, 35, 64)   16448       conv2_block1_out[0][0]           
__________________________________________________________________________________________________
conv2_block2_1_bn (BatchNormali (None, 35, 35, 64)   256         conv2_block2_1_conv[0][0]        
__________________________________________________________________________________________________
conv2_block2_1_relu (Activation (None, 35, 35, 64)   0           conv2_block2_1_bn[0][0]          
__________________________________________________________________________________________________
conv2_block2_2_conv (Conv2D)    (None, 35, 35, 64)   36928       conv2_block2_1_relu[0][0]        
__________________________________________________________________________________________________
conv2_block2_2_bn (BatchNormali (None, 35, 35, 64)   256         conv2_block2_2_conv[0][0]        
__________________________________________________________________________________________________
conv2_block2_2_relu (Activation (None, 35, 35, 64)   0           conv2_block2_2_bn[0][0]          
__________________________________________________________________________________________________
conv2_block2_3_conv (Conv2D)    (None, 35, 35, 256)  16640       conv2_block2_2_relu[0][0]        
__________________________________________________________________________________________________
conv2_block2_3_bn (BatchNormali (None, 35, 35, 256)  1024        conv2_block2_3_conv[0][0]        
__________________________________________________________________________________________________
conv2_block2_add (Add)          (None, 35, 35, 256)  0           conv2_block1_out[0][0]           
                                                                 conv2_block2_3_bn[0][0]          
__________________________________________________________________________________________________
conv2_block2_out (Activation)   (None, 35, 35, 256)  0           conv2_block2_add[0][0]           
__________________________________________________________________________________________________
conv2_block3_1_conv (Conv2D)    (None, 35, 35, 64)   16448       conv2_block2_out[0][0]           
__________________________________________________________________________________________________
conv2_block3_1_bn (BatchNormali (None, 35, 35, 64)   256         conv2_block3_1_conv[0][0]        
__________________________________________________________________________________________________
conv2_block3_1_relu (Activation (None, 35, 35, 64)   0           conv2_block3_1_bn[0][0]          
__________________________________________________________________________________________________
conv2_block3_2_conv (Conv2D)    (None, 35, 35, 64)   36928       conv2_block3_1_relu[0][0]        
__________________________________________________________________________________________________
conv2_block3_2_bn (BatchNormali (None, 35, 35, 64)   256         conv2_block3_2_conv[0][0]        
__________________________________________________________________________________________________
conv2_block3_2_relu (Activation (None, 35, 35, 64)   0           conv2_block3_2_bn[0][0]          
__________________________________________________________________________________________________
conv2_block3_3_conv (Conv2D)    (None, 35, 35, 256)  16640       conv2_block3_2_relu[0][0]        
__________________________________________________________________________________________________
conv2_block3_3_bn (BatchNormali (None, 35, 35, 256)  1024        conv2_block3_3_conv[0][0]        
__________________________________________________________________________________________________
conv2_block3_add (Add)          (None, 35, 35, 256)  0           conv2_block2_out[0][0]           
                                                                 conv2_block3_3_bn[0][0]          
__________________________________________________________________________________________________
conv2_block3_out (Activation)   (None, 35, 35, 256)  0           conv2_block3_add[0][0]           
__________________________________________________________________________________________________
conv3_block1_1_conv (Conv2D)    (None, 18, 18, 128)  32896       conv2_block3_out[0][0]           
__________________________________________________________________________________________________
conv3_block1_1_bn (BatchNormali (None, 18, 18, 128)  512         conv3_block1_1_conv[0][0]        
__________________________________________________________________________________________________
conv3_block1_1_relu (Activation (None, 18, 18, 128)  0           conv3_block1_1_bn[0][0]          
__________________________________________________________________________________________________
conv3_block1_2_conv (Conv2D)    (None, 18, 18, 128)  147584      conv3_block1_1_relu[0][0]        
__________________________________________________________________________________________________
conv3_block1_2_bn (BatchNormali (None, 18, 18, 128)  512         conv3_block1_2_conv[0][0]        
__________________________________________________________________________________________________
conv3_block1_2_relu (Activation (None, 18, 18, 128)  0           conv3_block1_2_bn[0][0]          
__________________________________________________________________________________________________
conv3_block1_0_conv (Conv2D)    (None, 18, 18, 512)  131584      conv2_block3_out[0][0]           
__________________________________________________________________________________________________
conv3_block1_3_conv (Conv2D)    (None, 18, 18, 512)  66048       conv3_block1_2_relu[0][0]        
__________________________________________________________________________________________________
conv3_block1_0_bn (BatchNormali (None, 18, 18, 512)  2048        conv3_block1_0_conv[0][0]        
__________________________________________________________________________________________________
conv3_block1_3_bn (BatchNormali (None, 18, 18, 512)  2048        conv3_block1_3_conv[0][0]        
__________________________________________________________________________________________________
conv3_block1_add (Add)          (None, 18, 18, 512)  0           conv3_block1_0_bn[0][0]          
                                                                 conv3_block1_3_bn[0][0]          
__________________________________________________________________________________________________
conv3_block1_out (Activation)   (None, 18, 18, 512)  0           conv3_block1_add[0][0]           
__________________________________________________________________________________________________
conv3_block2_1_conv (Conv2D)    (None, 18, 18, 128)  65664       conv3_block1_out[0][0]           
__________________________________________________________________________________________________
conv3_block2_1_bn (BatchNormali (None, 18, 18, 128)  512         conv3_block2_1_conv[0][0]        
__________________________________________________________________________________________________
conv3_block2_1_relu (Activation (None, 18, 18, 128)  0           conv3_block2_1_bn[0][0]          
__________________________________________________________________________________________________
conv3_block2_2_conv (Conv2D)    (None, 18, 18, 128)  147584      conv3_block2_1_relu[0][0]        
__________________________________________________________________________________________________
conv3_block2_2_bn (BatchNormali (None, 18, 18, 128)  512         conv3_block2_2_conv[0][0]        
__________________________________________________________________________________________________
conv3_block2_2_relu (Activation (None, 18, 18, 128)  0           conv3_block2_2_bn[0][0]          
__________________________________________________________________________________________________
conv3_block2_3_conv (Conv2D)    (None, 18, 18, 512)  66048       conv3_block2_2_relu[0][0]        
__________________________________________________________________________________________________
conv3_block2_3_bn (BatchNormali (None, 18, 18, 512)  2048        conv3_block2_3_conv[0][0]        
__________________________________________________________________________________________________
conv3_block2_add (Add)          (None, 18, 18, 512)  0           conv3_block1_out[0][0]           
                                                                 conv3_block2_3_bn[0][0]          
__________________________________________________________________________________________________
conv3_block2_out (Activation)   (None, 18, 18, 512)  0           conv3_block2_add[0][0]           
__________________________________________________________________________________________________
conv3_block3_1_conv (Conv2D)    (None, 18, 18, 128)  65664       conv3_block2_out[0][0]           
__________________________________________________________________________________________________
conv3_block3_1_bn (BatchNormali (None, 18, 18, 128)  512         conv3_block3_1_conv[0][0]        
__________________________________________________________________________________________________
conv3_block3_1_relu (Activation (None, 18, 18, 128)  0           conv3_block3_1_bn[0][0]          
__________________________________________________________________________________________________
conv3_block3_2_conv (Conv2D)    (None, 18, 18, 128)  147584      conv3_block3_1_relu[0][0]        
__________________________________________________________________________________________________
conv3_block3_2_bn (BatchNormali (None, 18, 18, 128)  512         conv3_block3_2_conv[0][0]        
__________________________________________________________________________________________________
conv3_block3_2_relu (Activation (None, 18, 18, 128)  0           conv3_block3_2_bn[0][0]          
__________________________________________________________________________________________________
conv3_block3_3_conv (Conv2D)    (None, 18, 18, 512)  66048       conv3_block3_2_relu[0][0]        
__________________________________________________________________________________________________
conv3_block3_3_bn (BatchNormali (None, 18, 18, 512)  2048        conv3_block3_3_conv[0][0]        
__________________________________________________________________________________________________
conv3_block3_add (Add)          (None, 18, 18, 512)  0           conv3_block2_out[0][0]           
                                                                 conv3_block3_3_bn[0][0]          
__________________________________________________________________________________________________
conv3_block3_out (Activation)   (None, 18, 18, 512)  0           conv3_block3_add[0][0]           
__________________________________________________________________________________________________
conv3_block4_1_conv (Conv2D)    (None, 18, 18, 128)  65664       conv3_block3_out[0][0]           
__________________________________________________________________________________________________
conv3_block4_1_bn (BatchNormali (None, 18, 18, 128)  512         conv3_block4_1_conv[0][0]        
__________________________________________________________________________________________________
conv3_block4_1_relu (Activation (None, 18, 18, 128)  0           conv3_block4_1_bn[0][0]          
__________________________________________________________________________________________________
conv3_block4_2_conv (Conv2D)    (None, 18, 18, 128)  147584      conv3_block4_1_relu[0][0]        
__________________________________________________________________________________________________
conv3_block4_2_bn (BatchNormali (None, 18, 18, 128)  512         conv3_block4_2_conv[0][0]        
__________________________________________________________________________________________________
conv3_block4_2_relu (Activation (None, 18, 18, 128)  0           conv3_block4_2_bn[0][0]          
__________________________________________________________________________________________________
conv3_block4_3_conv (Conv2D)    (None, 18, 18, 512)  66048       conv3_block4_2_relu[0][0]        
__________________________________________________________________________________________________
conv3_block4_3_bn (BatchNormali (None, 18, 18, 512)  2048        conv3_block4_3_conv[0][0]        
__________________________________________________________________________________________________
conv3_block4_add (Add)          (None, 18, 18, 512)  0           conv3_block3_out[0][0]           
                                                                 conv3_block4_3_bn[0][0]          
__________________________________________________________________________________________________
conv3_block4_out (Activation)   (None, 18, 18, 512)  0           conv3_block4_add[0][0]           
__________________________________________________________________________________________________
conv4_block1_1_conv (Conv2D)    (None, 9, 9, 256)    131328      conv3_block4_out[0][0]           
__________________________________________________________________________________________________
conv4_block1_1_bn (BatchNormali (None, 9, 9, 256)    1024        conv4_block1_1_conv[0][0]        
__________________________________________________________________________________________________
conv4_block1_1_relu (Activation (None, 9, 9, 256)    0           conv4_block1_1_bn[0][0]          
__________________________________________________________________________________________________
conv4_block1_2_conv (Conv2D)    (None, 9, 9, 256)    590080      conv4_block1_1_relu[0][0]        
__________________________________________________________________________________________________
conv4_block1_2_bn (BatchNormali (None, 9, 9, 256)    1024        conv4_block1_2_conv[0][0]        
__________________________________________________________________________________________________
conv4_block1_2_relu (Activation (None, 9, 9, 256)    0           conv4_block1_2_bn[0][0]          
__________________________________________________________________________________________________
conv4_block1_0_conv (Conv2D)    (None, 9, 9, 1024)   525312      conv3_block4_out[0][0]           
__________________________________________________________________________________________________
conv4_block1_3_conv (Conv2D)    (None, 9, 9, 1024)   263168      conv4_block1_2_relu[0][0]        
__________________________________________________________________________________________________
conv4_block1_0_bn (BatchNormali (None, 9, 9, 1024)   4096        conv4_block1_0_conv[0][0]        
__________________________________________________________________________________________________
conv4_block1_3_bn (BatchNormali (None, 9, 9, 1024)   4096        conv4_block1_3_conv[0][0]        
__________________________________________________________________________________________________
conv4_block1_add (Add)          (None, 9, 9, 1024)   0           conv4_block1_0_bn[0][0]          
                                                                 conv4_block1_3_bn[0][0]          
__________________________________________________________________________________________________
conv4_block1_out (Activation)   (None, 9, 9, 1024)   0           conv4_block1_add[0][0]           
__________________________________________________________________________________________________
conv4_block2_1_conv (Conv2D)    (None, 9, 9, 256)    262400      conv4_block1_out[0][0]           
__________________________________________________________________________________________________
conv4_block2_1_bn (BatchNormali (None, 9, 9, 256)    1024        conv4_block2_1_conv[0][0]        
__________________________________________________________________________________________________
conv4_block2_1_relu (Activation (None, 9, 9, 256)    0           conv4_block2_1_bn[0][0]          
__________________________________________________________________________________________________
conv4_block2_2_conv (Conv2D)    (None, 9, 9, 256)    590080      conv4_block2_1_relu[0][0]        
__________________________________________________________________________________________________
conv4_block2_2_bn (BatchNormali (None, 9, 9, 256)    1024        conv4_block2_2_conv[0][0]        
__________________________________________________________________________________________________
conv4_block2_2_relu (Activation (None, 9, 9, 256)    0           conv4_block2_2_bn[0][0]          
__________________________________________________________________________________________________
conv4_block2_3_conv (Conv2D)    (None, 9, 9, 1024)   263168      conv4_block2_2_relu[0][0]        
__________________________________________________________________________________________________
conv4_block2_3_bn (BatchNormali (None, 9, 9, 1024)   4096        conv4_block2_3_conv[0][0]        
__________________________________________________________________________________________________
conv4_block2_add (Add)          (None, 9, 9, 1024)   0           conv4_block1_out[0][0]           
                                                                 conv4_block2_3_bn[0][0]          
__________________________________________________________________________________________________
conv4_block2_out (Activation)   (None, 9, 9, 1024)   0           conv4_block2_add[0][0]           
__________________________________________________________________________________________________
conv4_block3_1_conv (Conv2D)    (None, 9, 9, 256)    262400      conv4_block2_out[0][0]           
__________________________________________________________________________________________________
conv4_block3_1_bn (BatchNormali (None, 9, 9, 256)    1024        conv4_block3_1_conv[0][0]        
__________________________________________________________________________________________________
conv4_block3_1_relu (Activation (None, 9, 9, 256)    0           conv4_block3_1_bn[0][0]          
__________________________________________________________________________________________________
conv4_block3_2_conv (Conv2D)    (None, 9, 9, 256)    590080      conv4_block3_1_relu[0][0]        
__________________________________________________________________________________________________
conv4_block3_2_bn (BatchNormali (None, 9, 9, 256)    1024        conv4_block3_2_conv[0][0]        
__________________________________________________________________________________________________
conv4_block3_2_relu (Activation (None, 9, 9, 256)    0           conv4_block3_2_bn[0][0]          
__________________________________________________________________________________________________
conv4_block3_3_conv (Conv2D)    (None, 9, 9, 1024)   263168      conv4_block3_2_relu[0][0]        
__________________________________________________________________________________________________
conv4_block3_3_bn (BatchNormali (None, 9, 9, 1024)   4096        conv4_block3_3_conv[0][0]        
__________________________________________________________________________________________________
conv4_block3_add (Add)          (None, 9, 9, 1024)   0           conv4_block2_out[0][0]           
                                                                 conv4_block3_3_bn[0][0]          
__________________________________________________________________________________________________
conv4_block3_out (Activation)   (None, 9, 9, 1024)   0           conv4_block3_add[0][0]           
__________________________________________________________________________________________________
conv4_block4_1_conv (Conv2D)    (None, 9, 9, 256)    262400      conv4_block3_out[0][0]           
__________________________________________________________________________________________________
conv4_block4_1_bn (BatchNormali (None, 9, 9, 256)    1024        conv4_block4_1_conv[0][0]        
__________________________________________________________________________________________________
conv4_block4_1_relu (Activation (None, 9, 9, 256)    0           conv4_block4_1_bn[0][0]          
__________________________________________________________________________________________________
conv4_block4_2_conv (Conv2D)    (None, 9, 9, 256)    590080      conv4_block4_1_relu[0][0]        
__________________________________________________________________________________________________
conv4_block4_2_bn (BatchNormali (None, 9, 9, 256)    1024        conv4_block4_2_conv[0][0]        
__________________________________________________________________________________________________
conv4_block4_2_relu (Activation (None, 9, 9, 256)    0           conv4_block4_2_bn[0][0]          
__________________________________________________________________________________________________
conv4_block4_3_conv (Conv2D)    (None, 9, 9, 1024)   263168      conv4_block4_2_relu[0][0]        
__________________________________________________________________________________________________
conv4_block4_3_bn (BatchNormali (None, 9, 9, 1024)   4096        conv4_block4_3_conv[0][0]        
__________________________________________________________________________________________________
conv4_block4_add (Add)          (None, 9, 9, 1024)   0           conv4_block3_out[0][0]           
                                                                 conv4_block4_3_bn[0][0]          
__________________________________________________________________________________________________
conv4_block4_out (Activation)   (None, 9, 9, 1024)   0           conv4_block4_add[0][0]           
__________________________________________________________________________________________________
conv4_block5_1_conv (Conv2D)    (None, 9, 9, 256)    262400      conv4_block4_out[0][0]           
__________________________________________________________________________________________________
conv4_block5_1_bn (BatchNormali (None, 9, 9, 256)    1024        conv4_block5_1_conv[0][0]        
__________________________________________________________________________________________________
conv4_block5_1_relu (Activation (None, 9, 9, 256)    0           conv4_block5_1_bn[0][0]          
__________________________________________________________________________________________________
conv4_block5_2_conv (Conv2D)    (None, 9, 9, 256)    590080      conv4_block5_1_relu[0][0]        
__________________________________________________________________________________________________
conv4_block5_2_bn (BatchNormali (None, 9, 9, 256)    1024        conv4_block5_2_conv[0][0]        
__________________________________________________________________________________________________
conv4_block5_2_relu (Activation (None, 9, 9, 256)    0           conv4_block5_2_bn[0][0]          
__________________________________________________________________________________________________
conv4_block5_3_conv (Conv2D)    (None, 9, 9, 1024)   263168      conv4_block5_2_relu[0][0]        
__________________________________________________________________________________________________
conv4_block5_3_bn (BatchNormali (None, 9, 9, 1024)   4096        conv4_block5_3_conv[0][0]        
__________________________________________________________________________________________________
conv4_block5_add (Add)          (None, 9, 9, 1024)   0           conv4_block4_out[0][0]           
                                                                 conv4_block5_3_bn[0][0]          
__________________________________________________________________________________________________
conv4_block5_out (Activation)   (None, 9, 9, 1024)   0           conv4_block5_add[0][0]           
__________________________________________________________________________________________________
conv4_block6_1_conv (Conv2D)    (None, 9, 9, 256)    262400      conv4_block5_out[0][0]           
__________________________________________________________________________________________________
conv4_block6_1_bn (BatchNormali (None, 9, 9, 256)    1024        conv4_block6_1_conv[0][0]        
__________________________________________________________________________________________________
conv4_block6_1_relu (Activation (None, 9, 9, 256)    0           conv4_block6_1_bn[0][0]          
__________________________________________________________________________________________________
conv4_block6_2_conv (Conv2D)    (None, 9, 9, 256)    590080      conv4_block6_1_relu[0][0]        
__________________________________________________________________________________________________
conv4_block6_2_bn (BatchNormali (None, 9, 9, 256)    1024        conv4_block6_2_conv[0][0]        
__________________________________________________________________________________________________
conv4_block6_2_relu (Activation (None, 9, 9, 256)    0           conv4_block6_2_bn[0][0]          
__________________________________________________________________________________________________
conv4_block6_3_conv (Conv2D)    (None, 9, 9, 1024)   263168      conv4_block6_2_relu[0][0]        
__________________________________________________________________________________________________
conv4_block6_3_bn (BatchNormali (None, 9, 9, 1024)   4096        conv4_block6_3_conv[0][0]        
__________________________________________________________________________________________________
conv4_block6_add (Add)          (None, 9, 9, 1024)   0           conv4_block5_out[0][0]           
                                                                 conv4_block6_3_bn[0][0]          
__________________________________________________________________________________________________
conv4_block6_out (Activation)   (None, 9, 9, 1024)   0           conv4_block6_add[0][0]           
__________________________________________________________________________________________________
conv5_block1_1_conv (Conv2D)    (None, 5, 5, 512)    524800      conv4_block6_out[0][0]           
__________________________________________________________________________________________________
conv5_block1_1_bn (BatchNormali (None, 5, 5, 512)    2048        conv5_block1_1_conv[0][0]        
__________________________________________________________________________________________________
conv5_block1_1_relu (Activation (None, 5, 5, 512)    0           conv5_block1_1_bn[0][0]          
__________________________________________________________________________________________________
conv5_block1_2_conv (Conv2D)    (None, 5, 5, 512)    2359808     conv5_block1_1_relu[0][0]        
__________________________________________________________________________________________________
conv5_block1_2_bn (BatchNormali (None, 5, 5, 512)    2048        conv5_block1_2_conv[0][0]        
__________________________________________________________________________________________________
conv5_block1_2_relu (Activation (None, 5, 5, 512)    0           conv5_block1_2_bn[0][0]          
__________________________________________________________________________________________________
conv5_block1_0_conv (Conv2D)    (None, 5, 5, 2048)   2099200     conv4_block6_out[0][0]           
__________________________________________________________________________________________________
conv5_block1_3_conv (Conv2D)    (None, 5, 5, 2048)   1050624     conv5_block1_2_relu[0][0]        
__________________________________________________________________________________________________
conv5_block1_0_bn (BatchNormali (None, 5, 5, 2048)   8192        conv5_block1_0_conv[0][0]        
__________________________________________________________________________________________________
conv5_block1_3_bn (BatchNormali (None, 5, 5, 2048)   8192        conv5_block1_3_conv[0][0]        
__________________________________________________________________________________________________
conv5_block1_add (Add)          (None, 5, 5, 2048)   0           conv5_block1_0_bn[0][0]          
                                                                 conv5_block1_3_bn[0][0]          
__________________________________________________________________________________________________
conv5_block1_out (Activation)   (None, 5, 5, 2048)   0           conv5_block1_add[0][0]           
__________________________________________________________________________________________________
conv5_block2_1_conv (Conv2D)    (None, 5, 5, 512)    1049088     conv5_block1_out[0][0]           
__________________________________________________________________________________________________
conv5_block2_1_bn (BatchNormali (None, 5, 5, 512)    2048        conv5_block2_1_conv[0][0]        
__________________________________________________________________________________________________
conv5_block2_1_relu (Activation (None, 5, 5, 512)    0           conv5_block2_1_bn[0][0]          
__________________________________________________________________________________________________
conv5_block2_2_conv (Conv2D)    (None, 5, 5, 512)    2359808     conv5_block2_1_relu[0][0]        
__________________________________________________________________________________________________
conv5_block2_2_bn (BatchNormali (None, 5, 5, 512)    2048        conv5_block2_2_conv[0][0]        
__________________________________________________________________________________________________
conv5_block2_2_relu (Activation (None, 5, 5, 512)    0           conv5_block2_2_bn[0][0]          
__________________________________________________________________________________________________
conv5_block2_3_conv (Conv2D)    (None, 5, 5, 2048)   1050624     conv5_block2_2_relu[0][0]        
__________________________________________________________________________________________________
conv5_block2_3_bn (BatchNormali (None, 5, 5, 2048)   8192        conv5_block2_3_conv[0][0]        
__________________________________________________________________________________________________
conv5_block2_add (Add)          (None, 5, 5, 2048)   0           conv5_block1_out[0][0]           
                                                                 conv5_block2_3_bn[0][0]          
__________________________________________________________________________________________________
conv5_block2_out (Activation)   (None, 5, 5, 2048)   0           conv5_block2_add[0][0]           
__________________________________________________________________________________________________
conv5_block3_1_conv (Conv2D)    (None, 5, 5, 512)    1049088     conv5_block2_out[0][0]           
__________________________________________________________________________________________________
conv5_block3_1_bn (BatchNormali (None, 5, 5, 512)    2048        conv5_block3_1_conv[0][0]        
__________________________________________________________________________________________________
conv5_block3_1_relu (Activation (None, 5, 5, 512)    0           conv5_block3_1_bn[0][0]          
__________________________________________________________________________________________________
conv5_block3_2_conv (Conv2D)    (None, 5, 5, 512)    2359808     conv5_block3_1_relu[0][0]        
__________________________________________________________________________________________________
conv5_block3_2_bn (BatchNormali (None, 5, 5, 512)    2048        conv5_block3_2_conv[0][0]        
__________________________________________________________________________________________________
conv5_block3_2_relu (Activation (None, 5, 5, 512)    0           conv5_block3_2_bn[0][0]          
__________________________________________________________________________________________________
conv5_block3_3_conv (Conv2D)    (None, 5, 5, 2048)   1050624     conv5_block3_2_relu[0][0]        
__________________________________________________________________________________________________
conv5_block3_3_bn (BatchNormali (None, 5, 5, 2048)   8192        conv5_block3_3_conv[0][0]        
__________________________________________________________________________________________________
conv5_block3_add (Add)          (None, 5, 5, 2048)   0           conv5_block2_out[0][0]           
                                                                 conv5_block3_3_bn[0][0]          
__________________________________________________________________________________________________
conv5_block3_out (Activation)   (None, 5, 5, 2048)   0           conv5_block3_add[0][0]           
__________________________________________________________________________________________________
flatten (Flatten)               (None, 51200)        0           conv5_block3_out[0][0]           
__________________________________________________________________________________________________
dropout (Dropout)               (None, 51200)        0           flatten[0][0]                    
__________________________________________________________________________________________________
digit1 (Dense)                  (None, 19)           972819      dropout[0][0]                    
__________________________________________________________________________________________________
digit2 (Dense)                  (None, 19)           972819      dropout[0][0]                    
__________________________________________________________________________________________________
digit3 (Dense)                  (None, 19)           972819      dropout[0][0]                    
__________________________________________________________________________________________________
digit4 (Dense)                  (None, 19)           972819      dropout[0][0]                    
==================================================================================================
Total params: 27,478,988
Trainable params: 27,425,868
Non-trainable params: 53,120
_______________________________

model.fit log

Epoch 1/10
  1/160 [..............................] - ETA: 0s - loss: 22.5601 - digit1_loss: 6.3056 - digit2_loss: 5.1959 - digit3_loss: 5.2820 - digit4_loss: 5.7765 - digit1_accuracy: 0.0400 - digit2_accuracy: 0.0600 - digit3_accuracy: 0.0200 - digit4_accuracy: 0.0400WARNING:tensorflow:From /home/asrock/miniconda3/envs/py37/lib/python3.7/site-packages/tensorflow/python/ops/summary_ops_v2.py:1277: stop (from tensorflow.python.eager.profiler) is deprecated and will be removed after 2020-07-01.
Instructions for updating:
use `tf.profiler.experimental.stop` instead.
160/160 [==============================] - ETA: 0s - loss: 5.1009 - digit1_loss: 1.2506 - digit2_loss: 1.4666 - digit3_loss: 1.3645 - digit4_loss: 1.0192 - digit1_accuracy: 0.6875 - digit2_accuracy: 0.6325 - digit3_accuracy: 0.6516 - digit4_accuracy: 0.7579WARNING:tensorflow:Can save best model only with val_digit4_acc available, skipping.
160/160 [==============================] - 467s 3s/step - loss: 5.1009 - digit1_loss: 1.2506 - digit2_loss: 1.4666 - digit3_loss: 1.3645 - digit4_loss: 1.0192 - digit1_accuracy: 0.6875 - digit2_accuracy: 0.6325 - digit3_accuracy: 0.6516 - digit4_accuracy: 0.7579 - val_loss: 12.3649 - val_digit1_loss: 3.1157 - val_digit2_loss: 3.0148 - val_digit3_loss: 3.0902 - val_digit4_loss: 3.1442 - val_digit1_accuracy: 0.0520 - val_digit2_accuracy: 0.0565 - val_digit3_accuracy: 0.0510 - val_digit4_accuracy: 0.0485
Epoch 2/10
160/160 [==============================] - ETA: 0s - loss: 0.4223 - digit1_loss: 0.1329 - digit2_loss: 0.1250 - digit3_loss: 0.1050 - digit4_loss: 0.0594 - digit1_accuracy: 0.9666 - digit2_accuracy: 0.9688 - digit3_accuracy: 0.9735 - digit4_accuracy: 0.9891WARNING:tensorflow:Can save best model only with val_digit4_acc available, skipping.
160/160 [==============================] - 360s 2s/step - loss: 0.4223 - digit1_loss: 0.1329 - digit2_loss: 0.1250 - digit3_loss: 0.1050 - digit4_loss: 0.0594 - digit1_accuracy: 0.9666 - digit2_accuracy: 0.9688 - digit3_accuracy: 0.9735 - digit4_accuracy: 0.9891 - val_loss: 12.1964 - val_digit1_loss: 3.0770 - val_digit2_loss: 3.0028 - val_digit3_loss: 3.0334 - val_digit4_loss: 3.0832 - val_digit1_accuracy: 0.0420 - val_digit2_accuracy: 0.0660 - val_digit3_accuracy: 0.0565 - val_digit4_accuracy: 0.0475
Epoch 3/10
160/160 [==============================] - ETA: 0s - loss: 0.1893 - digit1_loss: 0.0640 - digit2_loss: 0.0561 - digit3_loss: 0.0422 - digit4_loss: 0.0270 - digit1_accuracy: 0.9837 - digit2_accuracy: 0.9852 - digit3_accuracy: 0.9899 - digit4_accuracy: 0.9951WARNING:tensorflow:Can save best model only with val_digit4_acc available, skipping.
160/160 [==============================] - 294s 2s/step - loss: 0.1893 - digit1_loss: 0.0640 - digit2_loss: 0.0561 - digit3_loss: 0.0422 - digit4_loss: 0.0270 - digit1_accuracy: 0.9837 - digit2_accuracy: 0.9852 - digit3_accuracy: 0.9899 - digit4_accuracy: 0.9951 - val_loss: 11.9718 - val_digit1_loss: 3.0124 - val_digit2_loss: 2.9721 - val_digit3_loss: 2.9535 - val_digit4_loss: 3.0337 - val_digit1_accuracy: 0.0540 - val_digit2_accuracy: 0.0745 - val_digit3_accuracy: 0.0830 - val_digit4_accuracy: 0.0490
Epoch 4/10
160/160 [==============================] - ETA: 0s - loss: 0.0826 - digit1_loss: 0.0266 - digit2_loss: 0.0244 - digit3_loss: 0.0183 - digit4_loss: 0.0134 - digit1_accuracy: 0.9926 - digit2_accuracy: 0.9927 - digit3_accuracy: 0.9954 - digit4_accuracy: 0.9971WARNING:tensorflow:Can save best model only with val_digit4_acc available, skipping.
160/160 [==============================] - 307s 2s/step - loss: 0.0826 - digit1_loss: 0.0266 - digit2_loss: 0.0244 - digit3_loss: 0.0183 - digit4_loss: 0.0134 - digit1_accuracy: 0.9926 - digit2_accuracy: 0.9927 - digit3_accuracy: 0.9954 - digit4_accuracy: 0.9971 - val_loss: 9.6025 - val_digit1_loss: 2.5325 - val_digit2_loss: 2.3726 - val_digit3_loss: 2.5017 - val_digit4_loss: 2.1956 - val_digit1_accuracy: 0.2305 - val_digit2_accuracy: 0.2565 - val_digit3_accuracy: 0.1965 - val_digit4_accuracy: 0.2775
Epoch 5/10
160/160 [==============================] - ETA: 0s - loss: 0.0502 - digit1_loss: 0.0147 - digit2_loss: 0.0178 - digit3_loss: 0.0106 - digit4_loss: 0.0070 - digit1_accuracy: 0.9950 - digit2_accuracy: 0.9955 - digit3_accuracy: 0.9965 - digit4_accuracy: 0.9985WARNING:tensorflow:Can save best model only with val_digit4_acc available, skipping.
160/160 [==============================] - 330s 2s/step - loss: 0.0502 - digit1_loss: 0.0147 - digit2_loss: 0.0178 - digit3_loss: 0.0106 - digit4_loss: 0.0070 - digit1_accuracy: 0.9950 - digit2_accuracy: 0.9955 - digit3_accuracy: 0.9965 - digit4_accuracy: 0.9985 - val_loss: 3.1617 - val_digit1_loss: 0.9068 - val_digit2_loss: 0.8327 - val_digit3_loss: 0.9125 - val_digit4_loss: 0.5096 - val_digit1_accuracy: 0.7155 - val_digit2_accuracy: 0.7395 - val_digit3_accuracy: 0.7145 - val_digit4_accuracy: 0.8590
Epoch 6/10
160/160 [==============================] - ETA: 0s - loss: 0.0485 - digit1_loss: 0.0158 - digit2_loss: 0.0164 - digit3_loss: 0.0099 - digit4_loss: 0.0064 - digit1_accuracy: 0.9955 - digit2_accuracy: 0.9956 - digit3_accuracy: 0.9965 - digit4_accuracy: 0.9987WARNING:tensorflow:Can save best model only with val_digit4_acc available, skipping.
160/160 [==============================] - 277s 2s/step - loss: 0.0485 - digit1_loss: 0.0158 - digit2_loss: 0.0164 - digit3_loss: 0.0099 - digit4_loss: 0.0064 - digit1_accuracy: 0.9955 - digit2_accuracy: 0.9956 - digit3_accuracy: 0.9965 - digit4_accuracy: 0.9987 - val_loss: 0.6361 - val_digit1_loss: 0.2090 - val_digit2_loss: 0.1884 - val_digit3_loss: 0.1894 - val_digit4_loss: 0.0492 - val_digit1_accuracy: 0.9340 - val_digit2_accuracy: 0.9400 - val_digit3_accuracy: 0.9445 - val_digit4_accuracy: 0.9880
Epoch 7/10
160/160 [==============================] - ETA: 0s - loss: 0.0841 - digit1_loss: 0.0375 - digit2_loss: 0.0262 - digit3_loss: 0.0122 - digit4_loss: 0.0081 - digit1_accuracy: 0.9899 - digit2_accuracy: 0.9921 - digit3_accuracy: 0.9970 - digit4_accuracy: 0.9981WARNING:tensorflow:Can save best model only with val_digit4_acc available, skipping.
160/160 [==============================] - 256s 2s/step - loss: 0.0841 - digit1_loss: 0.0375 - digit2_loss: 0.0262 - digit3_loss: 0.0122 - digit4_loss: 0.0081 - digit1_accuracy: 0.9899 - digit2_accuracy: 0.9921 - digit3_accuracy: 0.9970 - digit4_accuracy: 0.9981 - val_loss: 0.3697 - val_digit1_loss: 0.1242 - val_digit2_loss: 0.1084 - val_digit3_loss: 0.1025 - val_digit4_loss: 0.0346 - val_digit1_accuracy: 0.9625 - val_digit2_accuracy: 0.9685 - val_digit3_accuracy: 0.9675 - val_digit4_accuracy: 0.9870
Epoch 8/10
160/160 [==============================] - ETA: 0s - loss: 0.1055 - digit1_loss: 0.0345 - digit2_loss: 0.0317 - digit3_loss: 0.0273 - digit4_loss: 0.0120 - digit1_accuracy: 0.9914 - digit2_accuracy: 0.9905 - digit3_accuracy: 0.9924 - digit4_accuracy: 0.9969WARNING:tensorflow:Can save best model only with val_digit4_acc available, skipping.
160/160 [==============================] - 269s 2s/step - loss: 0.1055 - digit1_loss: 0.0345 - digit2_loss: 0.0317 - digit3_loss: 0.0273 - digit4_loss: 0.0120 - digit1_accuracy: 0.9914 - digit2_accuracy: 0.9905 - digit3_accuracy: 0.9924 - digit4_accuracy: 0.9969 - val_loss: 0.1400 - val_digit1_loss: 0.0425 - val_digit2_loss: 0.0450 - val_digit3_loss: 0.0401 - val_digit4_loss: 0.0123 - val_digit1_accuracy: 0.9870 - val_digit2_accuracy: 0.9880 - val_digit3_accuracy: 0.9920 - val_digit4_accuracy: 0.9970
Epoch 9/10
160/160 [==============================] - ETA: 0s - loss: 0.0787 - digit1_loss: 0.0254 - digit2_loss: 0.0273 - digit3_loss: 0.0175 - digit4_loss: 0.0085 - digit1_accuracy: 0.9936 - digit2_accuracy: 0.9911 - digit3_accuracy: 0.9955 - digit4_accuracy: 0.9977WARNING:tensorflow:Can save best model only with val_digit4_acc available, skipping.
160/160 [==============================] - 284s 2s/step - loss: 0.0787 - digit1_loss: 0.0254 - digit2_loss: 0.0273 - digit3_loss: 0.0175 - digit4_loss: 0.0085 - digit1_accuracy: 0.9936 - digit2_accuracy: 0.9911 - digit3_accuracy: 0.9955 - digit4_accuracy: 0.9977 - val_loss: 0.1617 - val_digit1_loss: 0.0449 - val_digit2_loss: 0.0610 - val_digit3_loss: 0.0433 - val_digit4_loss: 0.0124 - val_digit1_accuracy: 0.9895 - val_digit2_accuracy: 0.9835 - val_digit3_accuracy: 0.9870 - val_digit4_accuracy: 0.9970
Epoch 10/10
160/160 [==============================] - ETA: 0s - loss: 0.0760 - digit1_loss: 0.0291 - digit2_loss: 0.0187 - digit3_loss: 0.0164 - digit4_loss: 0.0119 - digit1_accuracy: 0.9920 - digit2_accuracy: 0.9941 - digit3_accuracy: 0.9944 - digit4_accuracy: 0.9962WARNING:tensorflow:Can save best model only with val_digit4_acc available, skipping.
160/160 [==============================] - 276s 2s/step - loss: 0.0760 - digit1_loss: 0.0291 - digit2_loss: 0.0187 - digit3_loss: 0.0164 - digit4_loss: 0.0119 - digit1_accuracy: 0.9920 - digit2_accuracy: 0.9941 - digit3_accuracy: 0.9944 - digit4_accuracy: 0.9962 - val_loss: 0.2139 - val_digit1_loss: 0.0275 - val_digit2_loss: 0.1140 - val_digit3_loss: 0.0613 - val_digit4_loss: 0.0110 - val_digit1_accuracy: 0.9900 - val_digit2_accuracy: 0.9700 - val_digit3_accuracy: 0.9825 - val_digit4_accuracy: 0.9960

訓練 log

Train History

其他

把 Jupyter Notebook 轉為 python script

# 爬蟲
jupyter nbconvert --to script crawler.ipynb

# 影像預處理
jupyter nbconvert --to script preprocessBatch.ipynb

# Model
jupyter nbconvert --to script utilities.ipynb

About

高鐵訂票驗證碼,使用Python、Keras (Tensorflow)、CNN

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Jupyter Notebook 91.1%
  • Python 8.9%