---
# System prepended metadata

title: TRDG for CRNN chinese zh and cn training data notes
tags: [TRDG, OCR, CRNN]

---

# TRDG for CRNN chinese zh and cn training data notes

# 主要流程
1.用command_run.bat批次產生資料
2.將output裡面的資料夾都搬去C:\develop\CRNN_Chinese_Characters_Rec_data\datasets
(先直式在其他，分兩批做就不用每張圖都做(檢查)padding問題，please check item 3 below)
3.從CRNN_Chinese_Characters_Rec\lib\utils\prepare_training_data.ipynb處理資料
4.訓練CRNN model , CRNN_Chinese_Characters_Rec, python train.py


# 英數字
2024-06-03
使用peter挑的英數字型檔替換原本的
![image](https://hackmd.io/_uploads/HJImcuq4C.png)

# bat批次產生2024-06-03參數設計在這
```
@echo off
@REM filename command_run.bat

@REM\||(
remark
)

@REM -num and -let must combind with -rs and -sw 1
@REM gen number and latin smaples , target 100k
python run.py -t 32 --output_dir output\num_c1w_w6_cs1_sw1_na2_wd1153_b1_al1_rbl_fi        -c 10000 -rs -num -w 6 -cs 1 -sw 1 -na 2 -wd 1153 -b 1 -al 1 -bl 1 -rbl -fi
python run.py -t 32 --output_dir output\num_c5k_w7_cs1_sw1_na2_wd1153_b0_al1_rbl_m1_rk     -c 5000 -rs -num -w 7 -cs 1 -sw 1 -na 2 -wd 1153 -b 0 -al 1 -bl 1 -rbl -m 1 -k 1 -rk
python run.py -t 32 --output_dir output\num_c5k_w7_cs1_sw1_na2_wd1153_b0_al2_rbl_m1_do     -c 5000 -rs -num -w 7 -cs 1 -sw 1 -na 2 -wd 1153 -b 0 -al 2 -bl 1 -rbl -m 1 -d 3 -do 2
python run.py -t 32 --output_dir output\num_c5k_w6_cs1_sw1_na2_wd1153_b1_al1_rbl_fi_tc     -c 5000 -rs -num -w 6 -cs 1 -sw 1 -na 2 -wd 1153 -b 1 -al 1 -bl 1 -rbl -fi -tc "#000000,#888888"

python run.py -t 32 --output_dir output\let_c1w_w7_cs1_sw1_na2_wd1153_b1_al2_rbl_fi        -c 1000 -rs -let -w 7 -cs 1 -sw 1 -na 2 -wd 1153 -b 1 -al 2 -bl 1 -rbl -fi 
python run.py -t 32 --output_dir output\let_c5k_w7_cs1_sw1_na2_wd1153_b0_al1_rbl_m1_rk     -c 5000 -rs -let -w 7 -cs 1 -sw 1 -na 2 -wd 1153 -b 0 -al 1 -bl 1 -rbl -m 1 -k 1 -rk
python run.py -t 32 --output_dir output\let_c5k_w7_cs1_sw1_na2_wd1153_b0_al0_rbl_m1_do     -c 5000 -rs -let -w 7 -cs 1 -sw 1 -na 2 -wd 1153 -b 0 -al 0 -bl 1 -rbl -m 1 -d 3 -do 2
python run.py -t 32 --output_dir output\let_c5k_w7_cs1_sw1_na2_wd1153_b1_al0_rbl_fi_tc     -c 5000 -rs -let -w 7 -cs 1 -sw 1 -na 2 -wd 1153 -b 1 -al 0 -bl 1 -rbl -fi -tc "#000000,#888888"

python run.py -t 32 --output_dir output\let_num_c2w_w7_cs1_sw1_na2_wd1153_b1_al0_rbl_fi    -c 20000 -rs -let -num -w 7 -cs 1 -sw 1 -na 2 -wd 1153 -b 1 -al 0 -bl 1 -rbl -fi
python run.py -t 32 --output_dir output\let_num_c5k_w9_cs1_sw1_na2_wd1153_b1_al1_rbl_fi_ft -c 5000 -rs -let -num -w 9 -cs 1 -sw 1 -na 2 -wd 1153 -b 1 -al 1 -bl 1 -rbl -fi -ft fonts\zh\mingliu.ttc
python run.py -t 32 --output_dir output\let_num_c5k_w7_cs1_sw1_na2_wd1153_b1_al2_rbl_m0_ft -c 5000 -rs -let -num -w 7 -cs 1 -sw 1 -na 2 -wd 1153 -b 1 -al 2 -bl 1 -rbl -m 0 -ft fonts\zh\mingliu.ttc
python run.py -t 32 --output_dir output\let_num_c5k_w6_cs1_sw1_na2_wd1153_b1_al2_rbl_m0_tc -c 5000 -rs -let -num -w 6 -cs 1 -sw 1 -na 2 -wd 1153 -b 1 -al 2 -bl 1 -rbl -m 0 -tc "#000000,#888888"
python run.py -t 32 --output_dir output\let_num_c1w_w6_cs1_sw1_na2_wd1153_b3_al2_rbl_m0_tc -c 10000 -rs -let -num -w 6 -cs 1 -sw 1 -na 2 -wd 1153 -b 3 -al 2 -bl 1 -rbl -m 0 -tc "#000000,#888888"
python run.py -t 32 --output_dir output\let_num_c1w_w7_cs1_sw1_na2_wd1153_b3_al1_rbl_fi_tc -c 10000 -rs -let -num -w 7 -cs 1 -sw 1 -na 2 -wd 1153 -b 3 -al 1 -bl 1 -rbl -fi -tc "#000000,#888888"

@REM use -ft for specify one font mingliu.ttc                                                           
python run.py -t 32 --output_dir output\lzh_c5w_w30_cs1_sw1_na2_wd1153_b1_al2_rbl_fi_ft    -c 50000 -l zh -w 30 -cs 1 -sw 1 -na 2 -wd 1153 -b 1 -al 2 -bl 1 -rbl -fi -ft fonts\zh\mingliu.ttc
python run.py -t 32 --output_dir output\lzh_c5w_w40_cs1_sw0_na2_wd1153_b1_al1_rbl_fi_ft    -c 50000 -l zh -w 40 -cs 1 -sw 0 -na 2 -wd 1153 -b 1 -al 1 -bl 1 -rbl -fi -ft fonts\zh\mingliu.ttc
																						
@REM use -l zh                                                                             
python run.py -t 32 --output_dir output\lzh_c3w_w30_cs1_sw1_na2_wd1153_b0_al0_rbl_fi       -c 30000 -l zh -w 30 -cs 1 -sw 1 -na 2 -wd 1153 -b 0 -al 0 -bl 1 -rbl -fi
python run.py -t 32 --output_dir output\lzh_c3w_w30_cs1_sw0_na2_wd1153_b0_al1_rbl_m1       -c 30000 -l zh -w 30 -cs 1 -sw 0 -na 2 -wd 1153 -b 0 -al 1 -bl 1 -rbl -m 1
python run.py -t 32 --output_dir output\lzh_c2w_w20_cs0_sw1_na2_wd1153_b1_al2_rbl_m0_rk    -c 20000 -l zh -w 20 -cs 0 -sw 1 -na 2 -wd 1153 -b 1 -al 2 -bl 1 -rbl -m 0 -k 1 -rk
python run.py -t 32 --output_dir output\lzh_c2w_w30_cs1_sw0_na2_wd1153_b1_al1_rbl_m0_rk    -c 20000 -l zh -w 30 -cs 1 -sw 0 -na 2 -wd 1153 -b 0 -al 1 -bl 1 -rbl -m 0 -k 1 -rk
python run.py -t 32 --output_dir output\lzh_c2w_w40_cs0_sw0_na2_wd1153_b1_al2_rbl_m0_do    -c 20000 -l zh -w 40 -cs 0 -sw 0 -na 2 -wd 1153 -b 1 -al 2 -bl 1 -rbl -m 0 -d 1 -do 0
																						
@REM use -l cn                                                                             
python run.py -t 32 --output_dir output\lcn_c3w_w30_cs1_sw1_na2_wd1153_b0_al0_rbl_fi       -c 30000 -l cn -w 30 -cs 1 -sw 1 -na 2 -wd 1153 -b 0 -al 0 -bl 1 -rbl -fi
python run.py -t 32 --output_dir output\lcn_c3w_w30_cs1_sw0_na2_wd1153_b0_al1_rbl_m1       -c 30000 -l cn -w 30 -cs 1 -sw 0 -na 2 -wd 1153 -b 0 -al 1 -bl 1 -rbl -m 1
python run.py -t 32 --output_dir output\lcn_c2w_w20_cs0_sw1_na2_wd1153_b1_al2_rbl_m0_rk    -c 20000 -l cn -w 20 -cs 0 -sw 1 -na 2 -wd 1153 -b 1 -al 2 -bl 1 -rbl -m 0 -k 1 -rk
python run.py -t 32 --output_dir output\lcn_c2w_w30_cs1_sw0_na2_wd1153_b1_al1_rbl_m0_rk    -c 20000 -l cn -w 30 -cs 1 -sw 0 -na 2 -wd 1153 -b 0 -al 1 -bl 1 -rbl -m 0 -k 1 -rk
python run.py -t 32 --output_dir output\lcn_c2w_w40_cs0_sw0_na2_wd1153_b1_al2_rbl_m0_do    -c 20000 -l cn -w 40 -cs 0 -sw 0 -na 2 -wd 1153 -b 1 -al 2 -bl 1 -rbl -m 0 -d 1 -do 0
																						
@REM -i input dict file                                                                    
python run.py -t 32 --output_dir output\ibodict_c2w_cs1_na2_wd1153_b0_al0_rbl_m0           -i texts\bo_dict.txt -c 20000 -l bo -cs 1 -na 2 -wd 1153 -b 0 -al 0 -bl 1 -rbl -m 0
python run.py -t 32 --output_dir output\ibodict_c2w_cs2_na2_wd1153_b1_al2_rbl_m1           -i texts\bo_dict.txt -c 20000 -l bo -cs 2 -na 2 -wd 1153 -b 1 -al 2 -bl 1 -rbl -m 1
python run.py -t 32 --output_dir output\ibodict_c2w_cs0_na2_wd1153_b0_al1_rbl_m2_tc_ft     -i texts\bo_dict.txt -c 20000 -l bo -cs 0 -na 2 -wd 1153 -b 0 -al 1 -bl 1 -rbl -m 2 -tc "#000000,#888888" -ft fonts\zh\mingliu.ttc
python run.py -t 32 --output_dir output\ibodict_c2w_cs1_na2_wd1153_b0_al0_rbl_m0_rk        -i texts\bo_dict.txt -c 20000 -l bo -cs 1 -na 2 -wd 1153 -b 0 -al 0 -bl 1 -rbl -m 0 -k 1 -rk
																						
																						
@REM vertical chinese sample                                                               
python run.py -t 32 --output_dir output\or_lzh_c2w_w26_cs0_sw0_na2_b0_al0_rbl_m1           -c 20000 -l zh -w 26 -cs 0 -sw 0 -na 2 -b 0 -al 0 -bl 1 -rbl -m 1 -or 1
python run.py -t 32 --output_dir output\or_lzh_c2w_w26_cs1_sw0_na2_b1_al1_rbl_m2           -c 20000 -l zh -w 26 -cs 1 -sw 0 -na 2 -b 1 -al 1 -bl 1 -rbl -m 2 -or 1
python run.py -t 32 --output_dir output\or_lzh_c2w_w16_cs0_sw1_na2_b0_al0_rbl_m2           -c 20000 -l zh -w 16 -cs 0 -sw 1 -na 2 -b 0 -al 0 -bl 1 -rbl -m 2 -or 1
python run.py -t 32 --output_dir output\or_lzh_c2w_w26_cs0_sw0_na2_b1_al2_rbl_fi           -c 20000 -l zh -w 26 -cs 0 -sw 0 -na 2 -b 1 -al 2 -bl 1 -rbl -fi -or 1 -tc "#000000,#888888"
python run.py -t 32 --output_dir output\or_lzh_c2w_w26_cs0_sw0_na2_b1_al2_rbl_fi_tc        -c 20000 -l zh -w 26 -cs 0 -sw 0 -na 2 -b 1 -al 2 -bl 1 -rbl -fi -or 1 
python run.py -t 32 --output_dir output\or_lzh_c2w_w26_cs0_sw0_na2_b1_al2_rbl_fi_ft        -c 20000 -l zh -w 26 -cs 0 -sw 0 -na 2 -b 1 -al 2 -bl 1 -rbl -fi -or 1 -ft fonts\zh\mingliu.ttc
python run.py -t 32 --output_dir output\or_lzh_c2w_w26_cs0_sw0_na2_b0_al0_rbl_m0_do        -c 20000 -l zh -w 26 -cs 0 -sw 0 -na 2 -b 0 -al 0 -bl 1 -rbl -m 0 -or 1 -d 1 -do 0
python run.py -t 32 --output_dir output\or_lzh_c2w_w26_cs0_sw0_na2_b0_al1_rbl_m1_do        -c 20000 -l zh -w 26 -cs 0 -sw 0 -na 2 -b 0 -al 1 -bl 1 -rbl -m 1 -or 1 -d 2 -do 0
																						   
python run.py -t 32 --output_dir output\or_lcn_c2w_w26_cs0_sw0_na2_b0_al1_rbl_m1           -c 20000 -l cn -w 26 -cs 0 -sw 0 -na 2 -b 0 -al 1 -bl 1 -rbl -m 1 -or 1
python run.py -t 32 --output_dir output\or_lcn_c2w_w26_cs1_sw0_na2_b1_al0_rbl_m2           -c 20000 -l cn -w 26 -cs 1 -sw 0 -na 2 -b 1 -al 0 -bl 1 -rbl -m 2 -or 1
python run.py -t 32 --output_dir output\or_lcn_c2w_w16_cs0_sw1_na2_b0_al2_rbl_m2           -c 20000 -l cn -w 16 -cs 0 -sw 1 -na 2 -b 0 -al 2 -bl 1 -rbl -m 2 -or 1
python run.py -t 32 --output_dir output\or_lcn_c2w_w26_cs0_sw0_na2_b1_al2_rbl_fi           -c 20000 -l cn -w 26 -cs 0 -sw 0 -na 2 -b 1 -al 2 -bl 1 -rbl -fi -or 1 -tc "#000000,#888888"
python run.py -t 32 --output_dir output\or_lcn_c2w_w26_cs0_sw0_na2_b1_al0_rbl_fi           -c 20000 -l cn -w 26 -cs 0 -sw 0 -na 2 -b 1 -al 0 -bl 1 -rbl -fi -or 1
python run.py -t 32 --output_dir output\or_lcn_c2w_w26_cs0_sw0_na2_b0_al1_rbl_m0_do        -c 20000 -l cn -w 26 -cs 0 -sw 0 -na 2 -b 0 -al 1 -bl 1 -rbl -m 0 -or 1 -d 1 -do 0
python run.py -t 32 --output_dir output\or_lcn_c2w_w26_cs0_sw0_na2_b0_al0_rbl_m1_do        -c 20000 -l cn -w 26 -cs 0 -sw 0 -na 2 -b 0 -al 0 -bl 1 -rbl -m 1 -or 1 -d 2 -do 0



```


# 用TRDG產生資料
因為產生文字圖是用"字型檔"產生的，所以繁中、簡中字型不能混用
dicts分別放 cn & zh 字典檔，fonts也分開放
![](https://i.imgur.com/yMkZcLd.png)
而且每一種字型ttf都要單獨測試是否正確輸出，如 simsunb.ttf 字型就有問題如下
![](https://i.imgur.com/4SQpSnE.png)

# 簡中字型
Deng.ttf 正常
![](https://i.imgur.com/iVGGhM9.jpg)
Dengb.ttf 正常
![](https://i.imgur.com/Rgt4co5.jpg)
Dengl.ttf 正常
![](https://i.imgur.com/cPymOqd.jpg)
msyhl.ttc 正常
![](https://i.imgur.com/DUrAt8v.jpg)
msyh.ttc 正常
![](https://i.imgur.com/CLxEoA9.jpg)
msyhbd.ttc 正常
![](https://i.imgur.com/Ii29kOo.jpg)
simsun.ttc 正常
![](https://i.imgur.com/pLfzTWB.jpg)
simkai.ttf 正常
![](https://i.imgur.com/0K8AoNO.jpg)
SourceHanSans-Normal.ttf 正常
![](https://i.imgur.com/iDrTM0O.jpg)
simfang.ttf 正常
![](https://i.imgur.com/iKPpuoV.jpg)
simhei.ttf 正常
![](https://i.imgur.com/V2JjvzR.jpg)
simsunb.ttf 異常

# 繁中字型
mingliu.ttc 正常
![](https://i.imgur.com/tWiKpsz.jpg)
![199](https://hackmd.io/_uploads/B1kjccaVC.jpg)
mingliub.ttc 異常(HK、ExtB)
![199](https://hackmd.io/_uploads/H1Gva9p4A.jpg)
kaiu.ttf 正常
![](https://i.imgur.com/5Zsk3YQ.jpg)
![199](https://hackmd.io/_uploads/SJzvqqp4R.jpg)
msjhl.ttc 正常
![](https://i.imgur.com/i5kF2ym.jpg)
![199](https://hackmd.io/_uploads/S1yl2qp4A.jpg)
msjh.ttc 正常
![](https://i.imgur.com/XJdmOMo.jpg)
![199](https://hackmd.io/_uploads/Bk4CiqaVC.jpg)
msjhbd.ttc 正常
![](https://i.imgur.com/Meeq5ig.jpg)
![199](https://hackmd.io/_uploads/B1GZnqa4R.jpg)
mingliun.ttc (mingliu.ttc 新細明體) 
![199](https://hackmd.io/_uploads/r1PcEjpV0.jpg)
mingliunb.ttc (mingliub.ttc 新細明體 EXT) 異常
![199](https://hackmd.io/_uploads/rkXfHja4A.jpg)


# 使用方式
產生樣本的時候就是用 cn zh 參數分別產生樣本，才不會有些字出不來 but
!!!剛剛測試把簡中、繁中合併排除重複字成為一個 bo.txt 字型裡面放簡中、繁中字型都放一起(fonts\bo)，結果也都是正確的!!?
那就是兩種方式都可以用:分開產出、合併產出。
![image](https://hackmd.io/_uploads/HkaVJFqEA.png)

![image](https://hackmd.io/_uploads/Sk48ytqNA.png)

![image](https://hackmd.io/_uploads/HJwdyYq4R.png)



# 產生樣本參數
python run.py -c 100 -l bo -w 30 -cs 0 -sw 0 -na 2
-cs [CHARACTER_SPACING], Define the width of the spaces between characters. 2 means two pixels 這是指字元間的空間(像素)
-sw 0 標籤檔中每個字之間沒有空白字元，如下圖
![](https://i.imgur.com/So70WxH.png)
![](https://i.imgur.com/k2vp0WO.jpg)
![](https://i.imgur.com/ryyq6rv.jpg)
![](https://i.imgur.com/OEvzoUc.jpg)

python run.py -c 100 -l bo -w 30 -cs 5 -sw 0 -na 2
-cs 5 # 每個字之間有5像素空間
![](https://i.imgur.com/IIcEYGS.png)
![](https://i.imgur.com/1vwhtCu.jpg)
![](https://i.imgur.com/Bcqlnoa.jpg)

python run.py -c 100 -l bo -w 30 -cs 0 -sw 1 -na 2
-sw [SPACE_WIDTH], Define the width of the spaces between words. 2.0 means twice the normal space width
-sw 1 (以上) 標籤檔中每個字之間有空白字元
![](https://i.imgur.com/bUFxQdo.png)
![](https://i.imgur.com/Y3DQG3x.jpg)
![](https://i.imgur.com/XwhpBBT.jpg)
![](https://i.imgur.com/hKZPxpW.jpg)

python run.py -c 100 -l bo -w 30 -cs 0 -sw 2 -na 2
-sw 2
![](https://i.imgur.com/h1gKQ6E.png)
![](https://i.imgur.com/uC6AtCo.jpg)
![](https://i.imgur.com/CRaDXJ1.jpg)
![](https://i.imgur.com/ZXMUUWE.jpg)

python run.py -c 100 -l bo -w 30 -cs 0 -sw 3 -na 2
-sw 3
![](https://i.imgur.com/i7EMx1h.jpg)
![](https://i.imgur.com/BkSBQZY.jpg)
![](https://i.imgur.com/Bn8ircB.jpg)
實際上是影像尺寸長很多(在這裡他會縮放圖形大小所以看不出來)
![](https://i.imgur.com/ckF94zJ.png)

python run.py -c 100 -l bo -w 30 -cs 0 -sw 0 -na 2 -fi
-fi, Apply a tight crop around the rendered text
-fi 字擠滿(變大) 
![](https://i.imgur.com/lpLgsSS.jpg)
![](https://i.imgur.com/9MtfnIt.jpg)
![](https://i.imgur.com/ZMIWGD0.jpg)
![](https://i.imgur.com/wjNJqhR.png)
比較 python run.py -c 100 -l bo -w 30 -cs 0 -sw 0 -na 2
![](https://i.imgur.com/7ILHQtM.jpg)
![](https://i.imgur.com/U3YbDy4.jpg)
![](https://i.imgur.com/SpkwJYQ.jpg)

python run.py -c 100 -l bo -w 30 -cs 0 -sw 0 -na 2 -fi -m 6
-m [MARGINS], Define the margins around the text when rendered. In pixels
實際上 上下左都有留出6像素空間
![](https://i.imgur.com/B8hQ24L.jpg)
![](https://i.imgur.com/8QRhrh9.jpg)
![](https://i.imgur.com/l5HFN3I.jpg)
![](https://i.imgur.com/v0ODcEp.png)
比較 python run.py -c 100 -l bo -w 30 -cs 0 -sw 0 -na 2 -fi
只有 - fi 就預設留5像素空間
![](https://i.imgur.com/l9dSw1d.png)
比較 python run.py -c 100 -l bo -w 30 -cs 0 -sw 0 -na 2 -fi -m 2
-m 2 效果更明確 (勝過 -fi ) 都留2像素空間
![](https://i.imgur.com/1blZkMF.png)
比較 python run.py -c 100 -l bo -w 30 -cs 0 -sw 0 -na 2 -m 10
![](https://i.imgur.com/Czgndbr.png)

python run.py -c 100 -l bo -w 3 -cs 0 -sw 0 -na 2 -or 1
-or [ORIENTATION], Define the orientation of the text. 0: Horizontal, 1:Vertical
這裡要注意的是 -wd 是無法固定長度(高度)的 -f 也不行(直式時會變控制寬度)
代表產生直式的圖形時長度是無法固定所以產生較適中的字數最後再做padding補足
會產生直的圖 所以需要左轉90度訓練
![](https://i.imgur.com/s9opp5a.jpg)

python run.py -c 100 -l bo -w 30 -cs 0 -sw 0 -na 2 -hw
-hw 結果有產生 label檔案 但沒產生圖片檔案 試試 en
python run.py -c 100 -l en -w 30 -cs 0 -sw 0 -na 2 -hw
-hw 一樣 結果有產生label檔案 但沒產生圖片檔案
可能是因為沒有GPU關係(晚點測)

python run.py -t 8 -c 10 -l bo -w 30 -cs 0 -sw 0 -na 2 -k 5 
-t [THREAD_COUNT], Define the number of thread to use for image
generation
-k [SKEW_ANGLE], Define skewing angle of the generated text. In
positive degrees
![](https://i.imgur.com/PkirP9t.jpg)
![](https://i.imgur.com/qzJAiBL.jpg)
![](https://i.imgur.com/ZatlkIe.jpg)

python run.py -t 8 -c 10 -l bo -w 30 -cs 0 -sw 0 -na 2 -k 5 -rk
這裡就要注意不可以輸出太長的文字(寬度)因為字會變很小，如果寬度短字就會較適中
![](https://i.imgur.com/TkiMd4B.jpg)
![](https://i.imgur.com/chT6Fw1.jpg)
![](https://i.imgur.com/6zOwaXA.jpg)
![](https://i.imgur.com/N8azNH8.jpg)
![](https://i.imgur.com/Nrysyg9.jpg)

python run.py -t 8 -c 10 -l bo -w 30 -cs 0 -sw 0 -na 2 -bl 2
![](https://i.imgur.com/00sNCNs.jpg)
![](https://i.imgur.com/HueYg4o.jpg)
![](https://i.imgur.com/3wtrdmH.jpg)

python run.py -t 8 -c 10 -l bo -w 30 -cs 0 -sw 0 -na 2 -bl 1
![](https://i.imgur.com/DQzuFYP.jpg)
![](https://i.imgur.com/Tcqlypm.jpg)
![](https://i.imgur.com/EOBxpn8.jpg)

python run.py -t 8 -c 10 -l bo -w 30 -cs 0 -sw 0 -na 2 -bl 3 -rbl
-rbl 隨機變 bl
-bl 3 看樣子還是不行用 
![](https://i.imgur.com/0bMpN5L.jpg)
![](https://i.imgur.com/fuzkWkr.jpg)
![](https://i.imgur.com/wCwo28N.jpg)
![](https://i.imgur.com/UNvlKVZ.jpg)
![](https://i.imgur.com/BA2VTCd.jpg)
![](https://i.imgur.com/f2uuR5a.jpg)

python run.py -t 8 -c 10 -l bo -w 30 -cs 0 -sw 0 -na 2 -bl 1 -b
![](https://i.imgur.com/GmbyEaL.jpg)
![](https://i.imgur.com/UtU5fS2.jpg)
![](https://i.imgur.com/88n5bV7.jpg)


python run.py -t 8 -c 10 -l bo -w 30 -cs 0 -sw 0 -na 2 -d 3 -do 2
  -d [DISTORSION], Define a distorsion applied to the resulting image. 0:None (Default), 1: Sine wave, 2: Cosine wave, 3:Random
  -do [DISTORSION_ORIENTATION], Define the distorsion's orientation. Only used if -d is specified. 0: Vertical (Up and down), 1: Horizontal (Left and Right), 2: Both
![](https://i.imgur.com/hWNyl3G.jpg)
![](https://i.imgur.com/sJiAimi.jpg)
![](https://i.imgur.com/ye0ekQ3.jpg)
![](https://i.imgur.com/USvqGZO.jpg)
![](https://i.imgur.com/ut7QMct.jpg)
![](https://i.imgur.com/dW9N350.jpg)
![](https://i.imgur.com/MlZojbe.jpg)
![](https://i.imgur.com/oi9qOxf.jpg)
![](https://i.imgur.com/jPNWqzi.jpg)
![](https://i.imgur.com/EPE2tCa.jpg)

python run.py -t 8 -c 10 -l bo -w 30 -cs 0 -sw 0 -na 2 -d 3 -do 2 -k 3 -rk
![](https://i.imgur.com/O1dJtwN.jpg)
![](https://i.imgur.com/8c4k0MF.jpg)
![](https://i.imgur.com/csYOmx9.jpg)
![](https://i.imgur.com/Xz1rSbC.jpg)
![](https://i.imgur.com/VDP01au.jpg)
![](https://i.imgur.com/OyvAHS7.jpg)
![](https://i.imgur.com/4f7IMGA.jpg)
![](https://i.imgur.com/54HKWOC.jpg)
![](https://i.imgur.com/qicyDTX.jpg)
![](https://i.imgur.com/oitQ54s.jpg)

python run.py -t 8 -c 10 -l bo -w 30 -cs 0 -sw 0 -na 2 -d 1 -do 0 -k 2 -rk
![](https://i.imgur.com/Be9tHnC.jpg)
![](https://i.imgur.com/Vqj7sUc.jpg)
![](https://i.imgur.com/zSeKiNe.jpg)
![](https://i.imgur.com/4AmRW8r.jpg)
![](https://i.imgur.com/d6B3KRq.jpg)
![](https://i.imgur.com/QnzBcF0.jpg)
![](https://i.imgur.com/LabNvxp.jpg)
![](https://i.imgur.com/oaZQ7r7.jpg)
![](https://i.imgur.com/gIo1VEW.jpg)
![](https://i.imgur.com/ynSbf2Z.jpg)

python run.py -t 8 -c 10 -l bo -w 30 -cs 0 -sw 0 -na 2 -b 3 -tc #FDFEFE
-b [BACKGROUND], Define what kind of background to use. 0: Gaussian Noise, 1: Plain white, 2: Quasicrystal, 3: Pictures

![](https://i.imgur.com/uDuQLQA.jpg)
![](https://i.imgur.com/Q78gKOo.jpg)
![](https://i.imgur.com/jSH5ApD.jpg)
![](https://i.imgur.com/FHOXRYi.jpg)
![](https://i.imgur.com/QVViVLS.jpg)

python run.py -t 8 -c 10 -l bo -w 30 -cs 0 -sw 0 -na 2 -b 3 -tc #FDFEFE -wd 800 -al 0
-wd [WIDTH], Define the width of the resulting image. If not set it will be the width of the text + 10. If the width of the generated text is bigger that number will be used
-al [ALIGNMENT], Define the alignment of the text in the image. Only used if the width parameter is set. 0: left, 1: center, 2: right
![](https://i.imgur.com/WBBBKeU.jpg)
![](https://i.imgur.com/k8Ig0o9.jpg)
![](https://i.imgur.com/jhgkAa7.jpg)
![](https://i.imgur.com/HZ1CDGr.jpg)
![](https://i.imgur.com/TPBtshC.jpg)

python run.py -t 8 -c 10 -l bo -w 30 -cs 0 -sw 0 -na 2 -b 3 -tc #FDFEFE -wd 960 -al 0
![](https://i.imgur.com/QjlzN1Y.jpg)
![](https://i.imgur.com/2M5LEWH.jpg)
![](https://i.imgur.com/0UlYp9Z.jpg)
![](https://i.imgur.com/psiOEA5.jpg)
![](https://i.imgur.com/5seD0gX.jpg)
![](https://i.imgur.com/jsY0n3M.jpg)
![](https://i.imgur.com/g55zq7K.jpg)
![](https://i.imgur.com/DqjsAJY.jpg)
![](https://i.imgur.com/mj4amA8.jpg)

顏色範圍 python run.py -t 20 -c 10000 -w 2 -rs -num -cs 0 -sw 1 -na 2 -al 1 -fi -bl 1 -rbl -tc "#000000,#888888"

```
如果遇到下面問題就是 背景圖尺寸太小 造成的
    background_img = background_generator.image(
  File "c:\application\Develop\TextRecognitionDataGenerator\trdg\background_generator.py", line 72, in image
    Image.Resampling.LANCZOS,
  File "C:\Users\richard\AppData\Roaming\Python\Python39\site-packages\PIL\Image.py", line 65, in __getattr__
    raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
AttributeError: module 'PIL.Image' has no attribute 'Resampling'
```

# 文字標籤與數值標籤(訓練時的key,index)之轉換
```
# char_std_zhcn_8000.txt
# python dictionary 只能從key對應出value，不能從value對應出key，所以用下面的方法較為方便

# 這可以直接從key(index)取出value(字碼)，可以做為還原預測後的結果輸出
# {0: 'blank', 1: ' ', 2: '!', 3: '"', 4: '#', 5: '$', 6: '%',
with open('lib\dataset\\txt\char_std_zhcn_8000.txt', 'r', encoding='utf-8') as file:
	char_dict = {num : char.replace('\n','') for num, char in enumerate(file.readlines())}

# 這可以直接從字碼(value)取出key(index)，可以作為產生訓練的label
# {'blank': 0, ' ': 1, '!': 2, '"': 3, '#': 4, '$': 5, '%': 6,
with open('lib\dataset\\txt\char_std_zhcn_8000.txt', 'r', encoding='utf-8') as file:
	char_dict = {char.replace('\n','') : num for num, char in enumerate(file.readlines())}
```

# 產生樣本指令
```
python run.py -t 20 -c 10000 -l bo -w 30 -cs 1 -sw 0 -na 2 -b 3 -tc #ECF0F1 -wd 800 -al 1    
python run.py -t 20 -c 10000 -l bo -w 15 -cs 1 -sw 0 -na 2 -b 3 -tc #FDFEFE -wd 400 -al 0 -k 1 -rk -fi
python run.py -t 20 -c 10000 -l bo -w 30 -cs 0 -sw 1 -na 2 -d 1 -do 0 -wd 800 -al 2
python run.py -t 20 -c 10000 -l bo -w 30 -cs 0 -sw 0 -na 2 -wd 800 -al 1 -fi
python run.py -t 20 -c 10000 -l bo -w 15 -cs 0 -sw 2 -na 2 -wd 800 -al 1 -fi
python run.py -t 20 -c 10000 -l bo -w 25 -cs 0 -sw 0 -na 2 -or 1 -wd 800 -al 1 -fi    # 直的用 -wd 參數似乎無效
python run.py -t 20 -c 10000 -l bo -w 15 -cs 0 -sw 1 -na 2 -or 1 -wd 800 -al 1 -fi 
```
# 訓練不起來無法收斂
一開始做了6萬個樣本各式各樣大約15~35字一個樣本長度大約830x32(H)
結果怎麼訓練都預測blank都沒預測 loss 也不下降大約停在7.x
後來做比較標準10萬個每個5~10字 大小固定 280x32 情況也依樣
最後做50萬標準樣本每個10字 大小 280x32 開始好轉 應該是樣本數不足造成的問題
經過了五六日三天訓練，loss一直在3.x左右不降 lr 改小也沒明顯效果
星期日下午改成100萬樣本接著訓練如下lr改大epoch從164開始接著
```
get_last_lr : [0.0001]
誰昏---------------------------------暸折----------------------------敔篆劣苞懊髭 => 誰昏暸折敔篆劣苞懊髭, gt: 誰昏暸稽驸篆同涅懊髭 60208
洪胄---------------------------------畦台----------------------------穿砌邈维捎蜊 => 洪胄畦台穿砌邈维捎蜊, gt: 洪胄畦镖俋砌閻瓠昝蜊 60208
熬簑--------------------------------凉*-----------------------------砰麾衡蠕纸湃 => 熬簑凉*砰麾衡蠕纸湃, gt: 莼箠桓*抨貴褽贊钥陷 60208
穋喳---------------------------------糙泛----------------------------幢効鋕覲绣魔 => 穋喳糙泛幢効鋕覲绣魔, gt: 穋痠發証董妣鉀餿绣賸 60208
唁澈---------------------------------沃合----------------------------淳橡蓊棵殿例 => 唁澈沃合淳橡蓊棵殿例, gt: 贪貍勾濩衰橡蓊愠報畋 60208
郑祚---------------------------------被乃----------------------------猖暾遶螂晁辨 => 郑祚被乃猖暾遶螂晁辨, gt: 郑攻被泥棻燉壞穀涯雊 60208
兗攀---------------------------------椭并----------------------------郾妾恵奋刨别 => 兗攀椭并郾妾恵奋刨别, gt: 屈矯慼沬熟妾恵哀刨别 60208
浚黴---------------------------------印台----------------------------物泮皢念施纱 => 浚黴印台物泮皢念施纱, gt: 浚黴阡鑩购泮襤念咸釭 60208
其叱---------------------------------魏杰----------------------------鎧策崔青嘻帷 => 其叱魏杰鎧策崔青嘻帷, gt: 其叱隸癲鯧策崔值湩帷 60208
鈜飢---------------------------------禇合----------------------------胎臃盒肌涉用 => 鈜飢禇合胎臃盒肌涉用, gt: 鈣觔鹵履昵臃盒肌侪床 60208
[#correct:0 / #total:50000]
Test loss: 2.6071, accuray: 0.0000
is best: False
best acc is: 0.5
Epoch: [201][1/928]     Time 70.413s (70.413s)  Speed 14.5 samples/s    Data 69.194s (69.194s)  Loss 2.36798 (2.36798)
Epoch: [201][101/928]   Time 0.875s (1.570s)    Speed 1170.7 samples/s  Data 0.000s (0.685s)    Loss 2.47772 (2.41443)
Epoch: [201][201/928]   Time 0.890s (1.230s)    Speed 1150.1 samples/s  Data 0.000s (0.345s)    Loss 2.37902 (2.41238)
Epoch: [201][301/928]   Time 0.906s (1.121s)    Speed 1130.3 samples/s  Data 0.000s (0.230s)    Loss 2.38764 (2.40693)
Epoch: [201][401/928]   Time 0.922s (1.069s)    Speed 1111.1 samples/s  Data 0.000s (0.173s)    Loss 2.39769 (2.42378)
Epoch: [201][501/928]   Time 0.922s (1.039s)    Speed 1111.1 samples/s  Data 0.000s (0.138s)    Loss 2.36000 (2.42060)
Epoch: [201][601/928]   Time 0.922s (1.019s)    Speed 1111.1 samples/s  Data 0.000s (0.116s)    Loss 2.50331 (2.41983)
Epoch: [201][701/928]   Time 0.906s (1.005s)    Speed 1130.3 samples/s  Data 0.000s (0.099s)    Loss 2.54265 (2.42062)
Epoch: [201][801/928]   Time 0.890s (0.994s)    Speed 1150.1 samples/s  Data 0.000s (0.087s)    Loss 2.41593 (2.41837)
Epoch: [201][901/928]   Time 0.923s (0.986s)    Speed 1110.0 samples/s  Data 0.000s (0.077s)    Loss 2.36441 (2.41718)
get_last_lr : [0.0001]
昂毁---------------------------------又燕----------------------------仉淦弓鈕瓤贍 => 昂毁又燕仉淦弓鈕瓤贍, gt: 昂煞又傍沁淦弓紘瓤饜 60208
泳苞---------------------------------辆台----------------------------光脰喝制蠡勘 => 泳苞辆台光脰喝制蠡勘, gt: 泳茶锠侑永碎璁劬蠡勘 60208
H媺-------------------------------杏絃------------------------------征鑩般俊籣呵 => H媺杏絃征鑩般俊籣呵, gt: H媺杏锐析繡蛻埂蠡呵 60208
整赦---------------------------------兵双----------------------------唁纔港轂翮崴 => 整赦兵双唁纔港轂翮崴, gt: 整赦兵僻悟纔惜頷翮崴 60208
逾捆---------------------------------代合----------------------------保灞惚梢尽珊 => 逾捆代合保灞惚梢尽珊, gt: 逾捆代富帟灞惚捻尽诹 60208
窕妮---------------------------------羯合----------------------------麋冕繙努鈷泀 => 窕妮羯合麋冕繙努鈷泀, gt: 窕妮赐跷櫺葉縛廸紉泀 60208
疙夜---------------------------------蜴干----------------------------驊瞠敕婪祚倫 => 疙夜蜴干驊瞠敕婪祚倫, gt: 疙夜蜴淆驊満敕晶祚舆 60208
顷卉------------------------------迂----合---------------------------互擰咸S句葫 => 顷卉迂合互擰咸S句葫, gt: 栊企护殼目褒馅S泞葫 60208
鋕寁---------------------------------台怜----------------------------票悴灌涂睦埔 => 鋕寁台怜票悴灌涂睦埔, gt: 鋕富台咐摆烊瓘涂焜埔 60208
一祝---------------------------------瓣墙----------------------------滋哦撙潼峰恪 => 一祝瓣墙滋哦撙潼峰恪, gt: 一祝酈苏熒哦澴潼媲莢 60208
[#correct:0 / #total:50000]
Test loss: 2.5707, accuray: 0.0000
is best: False
best acc is: 0.5
Epoch: [202][1/928]     Time 69.900s (69.900s)  Speed 14.6 samples/s    Data 68.650s (68.650s)  Loss 2.37830 (2.37830)
Epoch: [202][101/928]   Time 0.890s (1.562s)    Speed 1150.2 samples/s  Data 0.000s (0.681s)    Loss 2.37056 (2.39034)
Epoch: [202][201/928]   Time 0.890s (1.224s)    Speed 1150.1 samples/s  Data 0.000s (0.342s)    Loss 2.32948 (2.38704)
Epoch: [202][301/928]   Time 0.890s (1.116s)    Speed 1150.1 samples/s  Data 0.000s (0.229s)    Loss 2.52910 (2.39653)
Epoch: [202][401/928]   Time 0.922s (1.064s)    Speed 1111.1 samples/s  Data 0.000s (0.172s)    Loss 2.50734 (2.39553)
Epoch: [202][501/928]   Time 1.110s (1.035s)    Speed 922.4 samples/s   Data 0.000s (0.137s)    Loss 2.37314 (2.39704)
Epoch: [202][601/928]   Time 0.957s (1.024s)    Speed 1069.8 samples/s  Data 0.000s (0.115s)    Loss 2.42147 (2.39529)
```
星期一早上 加大 lr 看看
```
  RESUME: 
    IS_RESUME: True
    FILE: 'output/360CC/checkpoints/checkpoint_202_acc_0.0000.pth'
  OPTIMIZER: 'adam'
  LR: 0.001
  
(dbnet_wenmu) C:\Application\Develop\CRNN_Chinese_Characters_Rec>python train.py
=> creating output\360CC\checkpoints
=> creating output\360CC\log
torch.cuda.device_count() 2
load 950000 images!
load 50000 images!
C:\Application\Anaconda3\envs\dbnet_wenmu\lib\site-packages\torch\cuda\nccl.py:15: UserWarning: PyTorch is not compiled with NCCL support
  warnings.warn('PyTorch is not compiled with NCCL support')
Epoch: [203][1/928]     Time 82.937s (82.937s)  Speed 12.3 samples/s    Data 67.677s (67.677s)  Loss 2.33732 (2.33732)  
Epoch: [203][101/928]   Time 0.893s (1.711s)    Speed 1147.1 samples/s  Data 0.001s (0.671s)    Loss 8.96026 (9.50182)
Epoch: [203][201/928]   Time 0.938s (1.323s)    Speed 1091.6 samples/s  Data 0.000s (0.337s)    Loss 9.04953 (9.20968)
```
loss 馬上變大好像行不通，讓他跑一個早上觀察情勢吧!
```
get_last_lr : [0.001]
--------訷伽挽蓓藜所----------------------表刨曳晞------------------------------- => 訷伽挽蓓藜所表刨曳晞, gt: 瓠邺炼值閘秒育纷怠姢 60208
--------危匠滋抬疣甍----------------------帷豕棠彗------------------------------- => 危匠滋抬疣甍帷豕棠彗, gt: 录匠阔供迭壅睥困葇彗 60208
--------霰喝婢婷绣呅----------------------墀晒矞剽------------------------------- => 霰喝婢婷绣呅墀晒矞剽, gt: 霰煨娓硬鐙柑瑲畛孱鄯 60208
--------櫳寨耘巷瑚却----------------------宏卒庸艶------------------------------- => 櫳寨耘巷瑚却宏卒庸艶, gt: 欄裊耘差颂彤宏空蓬鰹 60208
--------釭湃Y鼯霉殯----------------------篇祥琁宜------------------------------- => 釭湃Y鼯霉殯篇祥琁宜, gt: 釘瑕v勰竁瀰雙泯难里 60208
--------霉瀗姓即尸叙----------------------晞銀蟠佶------------------------------- => 霉瀗姓即尸叙晞銀蟠佶, gt: 霉濃衿劫了剃碳錄躏芫 60208
--------濫窗雉徉碘妣----------------------喔郇佳撼------------------------------- => 濫窗雉徉碘妣喔郇佳撼, gt: 潔夢粮萡碉妍握钵芺糜 60208
--------楠珂慵铎堃粗----------------------焕孃箭豉------------------------------- => 楠珂慵铎堃粗焕孃箭豉, gt: 掳冊嚷锈鹵娇娸爛箭辟 60208
--------勖寯登印舖塔----------------------咏暾慌喇------------------------------- => 勖寯登印舖塔咏暾慌喇, gt: 勖慝盒牝鍵捶扼檄陰嘶 60208
--------狂溯溪晋跑张----------------------字虺錬蛭------------------------------- => 狂溯溪晋跑张字虺錬蛭, gt: 血阙連蚕賒矜宅嵇鎢珊 60208
[#correct:0 / #total:50000]
Test loss: 4.2269, accuray: 0.0000
is best: False
best acc is: 0.5
Epoch: [207][1/928]     Time 70.857s (70.857s)  Speed 14.5 samples/s    Data 69.544s (69.544s)  Loss 3.75811 (3.75811)
Epoch: [207][101/928]   Time 0.890s (1.587s)    Speed 1150.1 samples/s  Data 0.000s (0.689s)    Loss 3.50063 (3.62656)
Epoch: [207][201/928]   Time 0.906s (1.245s)    Speed 1130.3 samples/s  Data 0.000s (0.346s)    Loss 3.20806 (3.51401)
Epoch: [207][301/928]   Time 0.906s (1.131s)    Speed 1130.3 samples/s  Data 0.000s (0.231s)    Loss 2.97672 (3.38925)
Epoch: [207][401/928]   Time 0.906s (1.075s)    Speed 1130.3 samples/s  Data 0.000s (0.174s)    Loss 2.92123 (3.50896)
Epoch: [207][501/928]   Time 0.890s (1.043s)    Speed 1150.1 samples/s  Data 0.000s (0.139s)    Loss 2.79506 (3.36849)
Epoch: [207][601/928]   Time 0.922s (1.023s)    Speed 1111.1 samples/s  Data 0.000s (0.116s)    Loss 2.70623 (3.25136)
Epoch: [207][701/928]   Time 0.937s (1.010s)    Speed 1092.6 samples/s  Data 0.000s (0.100s)    Loss 2.30098 (3.19216)
Epoch: [207][801/928]   Time 0.937s (0.999s)    Speed 1092.6 samples/s  Data 0.000s (0.087s)    Loss 3.07901 (3.08758)
Epoch: [207][901/928]   Time 0.938s (0.990s)    Speed 1091.6 samples/s  Data 0.000s (0.078s)    Loss 1.99408 (2.98755)
get_last_lr : [0.001]
--------钟袍瑣B瀑聞----------------------妒添结泣------------------------------- => 钟袍瑣B瀑聞妒添结泣, gt: 钟袍橙B瀑閨妒涟结泣 60208
--------胞伺狸盒父虻----------------------榟悉胃份------------------------------- => 胞伺狸盒父虻榟悉胃份, gt: 胞伺狸盒父虻棹悉匿份 60208
--------鼷媜道聊旺罹----------------------浻员伯潋------------------------------- => 鼷媜道聊旺罹浻员伯潋, gt: 驍媛逢酗旺禧浻员伯谢 60208
--------窿憩斾虐\氖----------------------墘犯道磊------------------------------- => 窿憩斾虐\氖墘犯道磊, gt: 窿憩淤墐(風阄犯逢蜇 60208
--------涂梃瑧岳蜜羣----------------------笛个苔雇------------------------------- => 涂梃瑧岳蜜羣笛个苔雇, gt: 涂砲禕否奪膏笛个居庫 60208
--------稀丸欵边菟涮----------------------芒弁忽妲------------------------------- => 稀丸欵边菟涮芒弁忽妲, gt: 诱办麸还菟漱芒弁雨妲 60208
--------圯炳吮磴彬碖----------------------蜴吊站呃------------------------------- => 圯炳吮磴彬碖蜴吊站呃, gt: 圯炳吮健呵嗡蜴叵站呃 60208
--------逸枋研汍槻祁----------------------揍硎趒赪------------------------------- => 逸枋研汍槻祁揍硎趒赪, gt: 谌抚站沉搁扯摸硎翅赪 60208
--------晞賻壅轿彬檻----------------------桐棣差關------------------------------- => 晞賻壅轿彬檻桐棣差關, gt: 煆駕摹設坜撥椀棣荖關 60208
--------鲔里卫诰豢澗----------------------誥慝别髭------------------------------- => 鲔里卫诰豢澗誥慝别髭, gt: 缆里卫裆豢瓒詩庸別塾 60208
[#correct:6 / #total:50000]
Test loss: 2.3273, accuray: 0.0001
is best: False
best acc is: 0.5
Epoch: [208][1/928]     Time 69.512s (69.512s)  Speed 14.7 samples/s    Data 68.184s (68.184s)  Loss 2.14744 (2.14744)
Epoch: [208][101/928]   Time 0.860s (1.561s)    Speed 1191.3 samples/s  Data 0.000s (0.675s)    Loss 1.92325 (2.07647)
Epoch: [208][201/928]   Time 0.906s (1.233s)    Speed 1130.5 samples/s  Data 0.000s (0.339s)    Loss 1.69332 (1.96284)
Epoch: [208][301/928]   Time 0.922s (1.130s)    Speed 1111.1 samples/s  Data 0.000s (0.227s)    Loss 3.99288 (2.31386)
Epoch: [208][401/928]   Time 0.969s (1.085s)    Speed 1057.2 samples/s  Data 0.000s (0.170s)    Loss 1.61625 (2.26425)
Epoch: [208][501/928]   Time 1.000s (1.059s)    Speed 1024.3 samples/s  Data 0.000s (0.136s)    Loss 1.46375 (2.13594)
Epoch: [208][601/928]   Time 0.969s (1.044s)    Speed 1056.3 samples/s  Data 0.016s (0.114s)    Loss 1.32206 (2.02556)
Epoch: [208][701/928]   Time 0.969s (1.032s)    Speed 1056.3 samples/s  Data 0.000s (0.098s)    Loss 1.26725 (1.92496)
Epoch: [208][801/928]   Time 0.970s (1.023s)    Speed 1055.9 samples/s  Data 0.000s (0.085s)    Loss 1.10244 (1.83746)
Epoch: [208][901/928]   Time 0.969s (1.016s)    Speed 1057.0 samples/s  Data 0.000s (0.076s)    Loss 5.34617 (2.20898)
```
第一次看到一點機會 [#correct:6 / #total:50000]
```
Epoch: [212][901/928]   Time 0.953s (1.016s)    Speed 1074.7 samples/s
        Data 0.000s (0.078s)    Loss 0.13186 (0.65571)
get_last_lr : [0.001]
--------俐榕--矮------虻-摩-佳--------------醺-煬-室摔--------------------------- => 俐榕矮虻摩佳醺煬室摔, gt: 俐榕矮虻摩佳醺煬室摔 60208
--------丝鞍--物------辙-蜥-囤--------------铄-巽-跶熊--------------------------- => 丝鞍物辙蜥囤铄巽跶熊, gt: 丝鞍物辙蜥囤铄巽跶熊 60208
--------输迩--牙------竭-寁-旖-------------鎂-贾-鞿-霉--------------------------- => 输迩牙竭寁旖鎂贾鞿霉, gt: 输迩牙竭寁旖鍰贾鞿霉 60208
--------魑茜--取------汕-酴-更--------------增-摘-唐陳--------------------------- => 魑茜取汕酴更增摘唐陳, gt: 魑茜取汕酴更增摘唐陳 60208
--------漓倡--奇------嵋-菊-死--------------卸-帼-蜀竹--------------------------- => 漓倡奇嵋菊死卸帼蜀竹, gt: 漓倡奇嵋菊死卸帼蜀竹 60208
--------愁柳--傍------窘-修-彣--------------鋸-绣-炳伊--------------------------- => 愁柳傍窘修彣鋸绣炳伊, gt: 愁柳傍窘修彣鋸绣炳伊 60208
--------勋'--箐-----調調-鋕-惱-------------鲔-犀-无-琥--------------------------- => 勋'箐調鋕惱鲔犀无琥, gt: 勋'箐調鋕惱鲔窜无魂 60208
--------掀辮--胱------嵘-梂-捌--------------莆-如-是倌--------------------------- => 掀辮胱嵘梂捌莆如是倌, gt: 掀辮胱嵘梂捌莆如是倌 60208
--------锵嫖--粮------郇-暍-酽--------------蚕-宥-撩姥--------------------------- => 锵嫖粮郇暍酽蚕宥撩姥, gt: 詭嫖粮郇暍酽蚕宥撩姥 60208
--------搖澔--迹------俞-霪-佔--------------饵-庶-欉眬--------------------------- => 搖澔迹俞霪佔饵庶欉眬, gt: 搖澔迹俞霪佔饵庶欉眬 60208
[#correct:42314 / #total:50000]
Test loss: 0.1403, accuray: 0.8463
is best: True
best acc is: 0.84628
Epoch: [213][1/928]     Time 70.743s (70.743s)  Speed 14.5 samples/s    Data 69.508s (69.508s)       Loss 0.13029 (0.13029)
Epoch: [213][101/928]   Time 0.922s (1.591s)    Speed 1110.1 samples/s  Data 0.000s (0.688s) Loss 0.10438 (0.12138)
Epoch: [213][201/928]   Time 0.891s (1.249s)    Speed 1149.1 samples/s  Data 0.000s (0.346s) Loss 0.10930 (0.11821)
Epoch: [213][301/928]   Time 0.953s (1.135s)    Speed 1074.6 samples/s  Data 0.000s (0.231s) Loss 0.27143 (0.13268)
Epoch: [213][401/928]   Time 0.906s (1.079s)    Speed 1130.2 samples/s  Data 0.000s (0.174s) Loss 0.08384 (0.14955)
Epoch: [213][501/928]   Time 0.937s (1.047s)    Speed 1092.5 samples/s  Data 0.000s (0.139s) Loss 0.08428 (0.13696)
Epoch: [213][601/928]   Time 0.906s (1.027s)    Speed 1130.2 samples/s  Data 0.000s (0.116s) Loss 0.09254 (0.12755)
Epoch: [213][701/928]   Time 0.922s (1.013s)    Speed 1111.1 samples/s  Data 0.000s (0.099s) Loss 0.06434 (0.11988)
Epoch: [213][801/928]   Time 0.922s (1.002s)    Speed 1111.1 samples/s  Data 0.000s (0.087s) Loss 0.07092 (0.11331)
Epoch: [213][901/928]   Time 0.906s (0.993s)    Speed 1130.2 samples/s  Data 0.000s (0.078s) Loss 0.05870 (0.10804)
get_last_lr : [0.001]
--------哼賻--崔------生-鈐-鐛--------------劻-勉-兄-璇-------------------------- => 哼賻崔生鈐鐛劻勉兄璇, gt: 哼賻崔生鈐鐛劻勉兄璇 60208
--------蕩靛--枨------走-靈-快--------------他-烊-苓-速-------------------------- => 蕩靛枨走靈快他烊苓速, gt: 蕩靛枨走靈快他烊苓速 60208
--------锜煨--团------亘-酦-疏--------------俍-鳯-氯-芋-------------------------- => 锜煨团亘酦疏俍鳯氯芋, gt: 锜煨团亘酦疏俍鳯氯芋 60208
--------郢烹--托------捻-盗-弦--------------跷-蹤-紆-汰-------------------------- => 郢烹托捻盗弦跷蹤紆汰, gt: 郢烹托捻盗弦跷蹤紆汰 60208
--------戟熏--怪------蛻-魁-萡--------------罵-对-涸-沱-------------------------- => 戟熏怪蛻魁萡罵对涸沱, gt: 戟熏怪蛻魁萡罵对涸沱 60208
--------氟肚--搔------鍹-蛔-瞎--------------歐-澧-煇-猓-------------------------- => 氟肚搔鍹蛔瞎歐澧煇猓, gt: 氟肚搔鍹蛔瞎歐澧煇猓 60208
--------嗫卅--侦------醇-楚-苹--------------厢-美-眛-近-------------------------- => 嗫卅侦醇楚苹厢美眛近, gt: 嗫卅侦醇楚苹厢美眛还 60208
--------腳二--皖------醞-鳍-刷--------------邵-茜-秋-珠-------------------------- => 腳二皖醞鳍刷邵茜秋珠, gt: 腳二皖醞鳍刷邵茜秋珠 60208
--------矞澎--金------燕-n-迹--------------吠-杰-钠-酵-------------------------- => 矞澎金燕n迹吠杰钠酵, gt: 矞澎金燕n迹吠杰钠酵 60208
--------斂享--蝓------夸-瞰-园---------------薆-駭-裝-^------------------------- => 斂享蝓夸瞰园薆駭裝^, gt: 斂享蝓夸瞰园薆駭裝^ 60208
[#correct:45049 / #total:50000]
Test loss: 0.0800, accuray: 0.9010
is best: True
best acc is: 0.90098

get_last_lr : [0.001]
--------潘-賸賸-铠铠-------晢--枇------洱-------頊--佑-------项--尺---------------- => 潘賸铠晢枇洱頊佑项尺, gt: 潘賸铠晢枇洱頊佐项尺 60208
--------雅-戒--仆--------还--打------洹-------輯--哭-------躍--茹---------------- => 雅戒仆还打洹輯哭躍茹, gt: 雅戒仆还打洹輯哭躍茹 60208
--------眇--仲--暱-------布--八------童------燁--焊-------妨--丘----------------- => 眇仲暱布八童燁焊妨丘, gt: 眇仲暱布八童燁焊妨丘 60208
--------琺--蒨-餮--------籃--榟------菩-------哂--揉-------扣--然---------------- => 琺蒨餮籃榟菩哂揉扣然, gt: 琺蒨餮籃榟菩哂揉扣然 60208
--------硼-芊--诟--------傑--鈹------堰-------湄--砂-------茆--用---------------- => 硼芊诟傑鈹堰湄砂茆用, gt: 硼芊诟傑鈹堰湄砂茆用 60208
--------舲-對--幅--------凉--沒------泫-------蝦--數-------套--馴---------------- => 舲對幅凉沒泫蝦數套馴, gt: 舲對幅凉沒泫蝦數套馴 60208
--------奚-厄厄-脹--------碟--锜------轉-------辟--駟-------标--畜---------------- => 奚厄脹碟锜轉辟駟标畜, gt: 奚厄脹碟锜轉辟駟标畜 60208
--------晉-琛--晤--------眺--稞------扯-------髋--盟--------統--床--------------- => 晉琛晤眺稞扯髋盟統床, gt: 雷琛晤眺稞扯髋盟統床 60208
--------柩柩--泠-------銳-----j----閨----鏇--膏--------筛--捩------------------- => 柩泠銳-j閨鏇膏筛捩, gt: 柩泠銳~f墾鏇膏筛捩 60208
--------郢-溉--蛄-------妒妒--服------善-------褕--掣--------再--懺--------------- => 郢溉蛄妒服善褕掣再懺, gt: 郢溉蛄妒服善褕掣屈懺 60208
[#correct:28051 / #total:50000]
Test loss: 0.2197, accuray: 0.5610
is best: False
best acc is: 0.9863
```

```
Epoch: [222][1/928]     Time 70.174s (70.174s)  Speed 14.6 samples/s    Data 68.877s (68.877s)       Loss 0.14591 (0.14591)
Epoch: [222][101/928]   Time 0.890s (1.584s)    Speed 1150.0 samples/s  Data 0.000s (0.682s) Loss 0.02058 (0.04721)
Epoch: [222][201/928]   Time 0.906s (1.245s)    Speed 1130.2 samples/s  Data 0.000s (0.343s) Loss 0.01535 (0.03288)
Epoch: [222][301/928]   Time 0.922s (1.132s)    Speed 1111.0 samples/s  Data 0.000s (0.229s) Loss 0.01022 (0.02637)
Epoch: [222][401/928]   Time 0.907s (1.078s)    Speed 1129.4 samples/s  Data 0.000s (0.172s) Loss 0.01075 (0.02249)
Epoch: [222][501/928]   Time 0.922s (1.047s)    Speed 1110.3 samples/s  Data 0.000s (0.138s) Loss 0.00832 (0.01983)
Epoch: [222][601/928]   Time 0.907s (1.026s)    Speed 1129.4 samples/s  Data 0.000s (0.115s) Loss 0.00693 (0.01788)
Epoch: [222][701/928]   Time 0.906s (1.010s)    Speed 1130.2 samples/s  Data 0.000s (0.099s) Loss 0.00620 (0.01638)
Epoch: [222][801/928]   Time 0.906s (0.998s)    Speed 1130.2 samples/s  Data 0.000s (0.086s) Loss 0.00707 (0.01522)
Epoch: [222][901/928]   Time 0.922s (0.988s)    Speed 1111.1 samples/s  Data 0.000s (0.077s) Loss 0.00592 (0.01429)
get_last_lr : [0.001]
--------尧-郅--雩--------鎖--則------坏------党--旨旨-------雕--饑---------------- => 尧郅雩鎖則坏党旨雕饑, gt: 尧郅雩鎖則坏党旨雕饑 60208
--------牲---夜--洎-------疯--癖---------型---鲁--z-----划--咯------------------ => 牲夜洎疯癖型鲁z划咯, gt: 牲夜洎疯癖型鲁z划咯 60208
--------植-阁--惚--------麼--瞇------您-------任--瑢--------葇--袁--------------- => 植阁惚麼瞇您任瑢葇袁, gt: 植阁惚麼瞇您任瑢葇袁 60208
--------毚--眺--予-------砷--区------崎------岭--欠-------灿--照----------------- => 毚眺予砷区崎岭欠灿照, gt: 毚眺予砷区崎岭欠灿照 60208
--------秀-濾--梃--------云--蓁------杼-------佝-狸狸-------攣--茂---------------- => 秀濾梃云蓁杼佝狸攣茂, gt: 秀濾梃云蓁杼佝狸攣茂 60208
--------屎--状--稜-------膂--漁------倞------坝--逶--------源--困---------------- => 屎状稜膂漁倞坝逶源困, gt: 屎状稜膂漁倞坝逶源困 60208
--------趒--可--球-------撼--八------嫖------勝--懍-------仰--里----------------- => 趒可球撼八嫖勝懍仰里, gt: 趒可球撼八嫖勝懍仰里 60208
--------鉛-阪--濛--------匐--杏------煐-------涿--婵--------泛--僅--------------- => 鉛阪濛匐杏煐涿婵泛僅, gt: 鉛阪濛匐杏煐涿婵泛僅 60208
--------峭--島--红-------哩--羞------拚------瞞--闪-------强强-墓----------------- => 峭島红哩羞拚瞞闪强墓, gt: 峭島红哩羞拚瞞闪强墓 60208
--------祖---祝--焰-------豺--Z-----坍----頌--阻--------手--娼------------------ => 祖祝焰豺Z坍頌阻手娼, gt: 祖祝焰豺Z坍頌阻手娼 60208
[#correct:49330 / #total:50000]
Test loss: 0.0086, accuray: 0.9866
is best: True
best acc is: 0.9866
Epoch: [223][1/928]     Time 70.932s (70.932s)  Speed 14.4 samples/s    Data 69.697s (69.697s)       Loss 0.00505 (0.00505)

Epoch: [223][801/928]   Time 0.949s (1.003s)    Speed 1079.0 samples/s  Data 0.000s (0.087s)    Loss 0.00435 (0.00425)
Epoch: [223][901/928]   Time 0.953s (0.999s)    Speed 1074.9 samples/s  Data 0.000s (0.078s)    Loss 0.00394 (0.00422)
get_last_lr : [0.001]
--------躲--踢--昕-------愉--颜------呅------嚣--那-------磺--帝----------------- => 躲踢昕愉颜呅嚣那磺帝, gt: 躲踢昕愉颜呅嚣那磺帝 60208
--------慝-磚--帽--------釅--幅------摹-------汝--如--------銧--陕--------------- => 慝磚帽釅幅摹汝如銧陕, gt: 慝磚帽釅幅摹汝如銧陕 60208
--------纮-印印-弛弛-------比--菱------沓-------吶--龃-------伍--揀---------------- => 纮印弛比菱沓吶龃伍揀, gt: 纮印弛比菱沓吶龃伍揀 60208
--------剪--崝--藥-------咽--镞------鮭------嬛--灌-------該--繶----------------- => 剪崝藥咽镞鮭嬛灌該繶, gt: 剪崝藥咽镞鮭嬛灌該繶 60208
--------谷--蒜--哗-------吃--蹓------绢------福--繳-------孰--為----------------- => 谷蒜哗吃蹓绢福繳孰為, gt: 谷蒜哗吃蹓绢福繳孰為 60208
--------太--剩--駿-------庒--蝇------喇------蘸--笒-------韻--緹----------------- => 太剩駿庒蝇喇蘸笒韻緹, gt: 太剩駿庒蝇喇蘸笒韻緹 60208
--------裔--給--鹊-------石--魯------钉------战-芦芦-------鬣--瑕----------------- => 裔給鹊石魯钉战芦鬣瑕, gt: 裔給鹊石魯钉战芦鬣瑕 60208
--------地-鳶--州--------诠--卫------搓-------庠--施--------蔆--咫--------------- => 地鳶州诠卫搓庠施蔆咫, gt: 地鳶州诠卫搓庠施蔆咫 60208
--------琦--占--符-------踵--从------佞------瓢--氖-------時--騵----------------- => 琦占符踵从佞瓢氖時騵, gt: 琦占符踵从佞瓢氖時騵 60208
--------諂-罩--磯--------补--巍------菠-------搜--左-------墮--廢---------------- => 諂罩磯补巍菠搜左墮廢, gt: 諂罩磯补巍菠搜左墮廢 60208
[#correct:49444 / #total:50000]
Test loss: 0.0064, accuray: 0.9889
is best: True
best acc is: 0.98888
```
![](https://i.imgur.com/hHwNqer.png)
checkpoint_222_acc_0.9866.pth
停下來，測試一下 inference，測試項目1.訓練規格樣本測試 2.更長的樣本測試 3.批次樣本測試
![](https://i.imgur.com/bC0PPBV.png)
![](https://i.imgur.com/O87LUv8.png)
![](https://i.imgur.com/4nkebkA.png)
![](https://i.imgur.com/5ik4s9e.png)



# 訓練標準、直式混和的資料集
```
python run.py -t 20 -c 10000 -l bo -w 10 -cs 0 -sw 0 -na 2 -or 1 -al 1 -fi 
```
![](https://i.imgur.com/xFUgDFv.png)
![](https://i.imgur.com/VrcA3Fc.jpg)
即使 -cs 0 -sw 0 字間一樣有一點空間
```
python run.py -t 20 -c 10000 -l bo -w 10 -cs 0 -sw 1 -na 2 -or 1 -al 1 -fi
```
![](https://i.imgur.com/LvhRXVK.png)
![](https://i.imgur.com/Ca4PPkY.jpg)
所以弄字數少一點，使用訓練好的模型，看看不同字數會怎樣(因為repo中說固定字數)
或是如果要固定字數，就產生長一點的固定字數樣本，重新訓練模型，目前先第一種測試
```
python run.py -t 20 -c 10000 -l bo -w 9 -cs 0 -sw 0 -na 2 -or 1 -al 1 -fi
```
![](https://i.imgur.com/YQuyhSP.png)
產生樣本 1m :
```
python run.py -t 20 -c 500000 -l bo -w 9 -cs 0 -sw 0 -na 2 -or 1 -al 1 -fi
python run.py -t 20 -c 500000 -l bo -w 10 -cs 0 -sw 0 -na 2 -wd 280 -al 1 -fi

```
訓練結果如下: 可以用不同字數沒問題 所以跳過第二題不測試了
```
Epoch: [255][701/928]   Time 0.922s (1.016s)    Speed 1110.9 samples/s  Data 0.000s (0.098s)    Loss 0.00739 (0.00422)
Epoch: [255][801/928]   Time 0.922s (1.004s)    Speed 1110.9 samples/s  Data 0.000s (0.086s)    Loss 0.00416 (0.00421)
Epoch: [255][901/928]   Time 0.922s (0.996s)    Speed 1110.9 samples/s  Data 0.000s (0.077s)    Loss 0.00500 (0.00420)
get_last_lr : [0.001]
--------村--佛----绮-----弈------何--刨--------蓬----荐------锠-----椿----------- => 村佛绮弈何刨蓬荐锠椿, gt: 村佛绮弈何刨蓬荐锠椿 60208
--------垃---卓-----悉----湑-----诱--逶--------嶺----訾-----永-----禀------------ => 垃卓悉湑诱逶嶺訾永禀, gt: 垃卓悉湑诱逶嶺訾永禀 60208
----怆----蝶----跺-----餘-----宴-----闋----籤-----腕-----瓜--------------------- => 怆蝶跺餘宴闋籤腕瓜 , gt: 怆蝶跺餘宴闋籤腕瓜  60208
--------丰---跷----秦-----雙-----炬--扯-------隅----芩芩----苏-----瞬------------- => 丰跷秦雙炬扯隅芩苏瞬, gt: 丰跷秦雙炬扯隅芩苏瞬 60208
----醋---駐----襁-----容----訷----憧------锴---恨-----树------------------------ => 醋駐襁容訷憧锴恨树 , gt: 醋駐襁容訷憧锴恨树  60208
--------杪--啜-----鄱-----雄-----尋--誶-------稽-----礽-----澄-----楹------------ => 杪啜鄱雄尋誶稽礽澄楹, gt: 杪啜鄱雄尋誶稽礽澄楹 60208
----剂----滢------忻------疾-----菩------駒------母-----钧------餒-------------- => 剂滢忻疾菩駒母钧餒 , gt: 剂滢忻疾菩駒母钧餒  60208
---孀----耀----蘅-----唔----壕-----戛-----鈺----詞----誦------------------------ => 孀耀蘅唔壕戛鈺詞誦 , gt: 孀耀蘅唔壕戛鈺詞誦  60208
--------郖---硎-----蜷----烹-----搜--慚-------戒-----人-----痲----嘐------------- => 郖硎蜷烹搜慚戒人痲嘐, gt: 郖硎蜷烹搜慚戒人痲嘐 60208
----俞----P------彰-----垎------陴------孓-----叙------记------背-------------- => 俞P彰垎陴孓叙记背 , gt: 俞P彰垎陴孓叙记背  60208
[#correct:49096 / #total:50000]
Test loss: 0.0064, accuray: 0.9819
is best: False
best acc is: 0.98512
Epoch: [256][1/928]     Time 72.262s (72.262s)  Speed 14.2 samples/s    Data 70.933s (70.933s)  Loss 0.00423 (0.00423)
Epoch: [256][101/928]   Time 0.891s (1.610s)    Speed 1149.6 samples/s  Data 0.000s (0.703s)    Loss 0.00385 (0.00319)
Epoch: [256][201/928]   Time 0.906s (1.260s)    Speed 1129.7 samples/s  Data 0.000s (0.353s)    Loss 0.00285 (0.00308)
Epoch: [256][301/928]   Time 0.906s (1.145s)    Speed 1130.1 samples/s  Data 0.000s (0.236s)    Loss 0.00921 (0.00314)
Epoch: [256][401/928]   Time 0.906s (1.089s)    Speed 1130.0 samples/s  Data 0.000s (0.177s)    Loss 0.00857 (0.00412)
Epoch: [256][501/928]   Time 0.922s (1.057s)    Speed 1110.9 samples/s  Data 0.000s (0.142s)    Loss 0.00315 (0.00417)
Epoch: [256][601/928]   Time 0.937s (1.036s)    Speed 1092.4 samples/s  Data 0.000s (0.118s)    Loss 0.00974 (0.00450)
Epoch: [256][701/928]   Time 0.922s (1.021s)    Speed 1110.9 samples/s  Data 0.000s (0.102s)    Loss 0.00583 (0.00464)
Epoch: [256][801/928]   Time 0.906s (1.009s)    Speed 1130.0 samples/s  Data 0.000s (0.089s)    Loss 0.00320 (0.00468)
Epoch: [256][901/928]   Time 0.906s (0.999s)    Speed 1130.0 samples/s  Data 0.000s (0.079s)    Loss 0.00466 (0.00464)
get_last_lr : [0.001]
----晌----筑---竮-----瑯----店-----螢-----缄----快-----揭----------------------- => 晌筑竮瑯店螢缄快揭 , gt: 晌筑竮瑯店螢缄快揭  60208
--------灰--鳅-----句-----枭-----焚--凎-------忏-----韁韁----楔-----敏------------ => 灰鳅句枭焚凎忏韁楔敏, gt: 灰鳅句枭焚凎忏韁楔敏 60208
---鐫----穜---蝌-----拷-----瘫----颶--墮-------域----璃------------------------- => 鐫穜蝌拷瘫颶墮域璃 , gt: 鐫穜蝌拷瘫颶墮城璃  60208
--------夺--比-----烤----】------融--尹-------蓿------鐫----瘠-----售------------ => 夺比烤】融尹蓿鐫瘠售, gt: 夺比烤】融尹蓿鐫瘠售 60208
----荃----灾-----殊------替------麒------礙-----弯------霜------逦-------------- => 荃灾殊替麒礙弯霜逦 , gt: 荃灾殊替麒礙弯霜逦  60208
--------糧----舶----呎呎----推-----虺-----莅----孕----^---使------簽------------- => 糧舶呎推虺莅孕^使簽, gt: 糧舶呎推虺莅孕^使簽 60208
----楊----裙------逮-----囂-------蓅-----崁------荟------礁------超------------- => 楊裙逮囂蓅崁荟礁超 , gt: 楊裙逮囂蓅崁荟礁超  60208
----眠----鲣-----努-----疢-----炳----索-------槐------痴-----于----------------- => 眠鲣努疢炳索槐痴于 , gt: 眠鲣努疢炳索槐痴于  60208
----盟----森---h-----熖----禮-----君-----让---年-----駑------------------------ => 盟森h熖禮君让年駑 , gt: 盟森h熖禮君让年駑  60208
----旰----晝-----嫊-------衙-----冷------皈------喧------靜-----豳-------------- => 旰晝嫊衙冷皈喧靜豳 , gt: 旰晝嫊衙冷皈喧靜豳  60208
[#correct:49083 / #total:50000]
Test loss: 0.0066, accuray: 0.9817
is best: False
best acc is: 0.98512
```
![](https://i.imgur.com/h1WKLFp.png)
# 做新的樣本訓練
```
# 標準
python run.py -t 20 -c 200000 -l bo -w 10 -cs 0 -sw 0 -na 2 -wd 280 -al 1 -fi -bl 1 -rbl
python run.py -t 20 -c 200000 -l bo -w 7 -cs 0 -sw 1 -na 2 -wd 280 -al 1 -fi -bl 1 -rbl
python run.py -t 20 -c 200000 -l bo -w 10 -cs 0 -sw 0 -na 2 -wd 280 -al 1 -fi -bl 1 -rbl -k 1 -rk
python run.py -t 20 -c 200000 -l bo -w 7 -cs 0 -sw 1 -na 2 -wd 280 -al 1 -fi -bl 1 -rbl -k 1 -rk
python run.py -t 20 -c 200000 -l bo -w 10 -cs 0 -sw 0 -na 2 -wd 280 -al 1 -fi -bl 1 -rbl -d 1 -do 0
python run.py -t 20 -c 200000 -l bo -w 7 -cs 0 -sw 1 -na 2 -wd 280 -al 1 -fi -bl 1 -rbl -d 1 -do 0
python run.py -t 20 -c 50000 -l bo -w 10 -cs 0 -sw 0 -na 2 -wd 280 -al 1 -fi -bl 1 -rbl -tc "#000000,#888888" -b 3
python run.py -t 20 -c 50000 -l bo -w 10 -cs 0 -sw 0 -na 2 -wd 280 -al 1 -fi -bl 1 -rbl -tc "#EEEEEE,#FFFFFF" -b 3
python run.py -t 20 -c 50000 -l bo -w 7 -cs 0 -sw 1 -na 2 -wd 280 -al 1 -fi -bl 1 -rbl -tc "#000000,#888888" -b 3
python run.py -t 20 -c 50000 -l bo -w 7 -cs 0 -sw 1 -na 2 -wd 280 -al 1 -fi -bl 1 -rbl -tc "#EEEEEE,#FFFFFF" -b 3
# 直式 # 反白 字間 模糊 背景
python run.py -t 20 -c 200000 -l bo -w 9 -cs 0 -sw 0 -na 2 -or 1 -al 1 -fi -bl 1 -rbl 
python run.py -t 20 -c 200000 -l bo -w 5 -cs 0 -sw 1 -na 2 -or 1 -al 1 -fi -bl 1 -rbl 
python run.py -t 20 -c 200000 -l bo -w 9 -cs 0 -sw 0 -na 2 -or 1 -al 1 -fi -bl 1 -rbl -k 1 -rk 
python run.py -t 20 -c 200000 -l bo -w 5 -cs 0 -sw 1 -na 2 -or 1 -al 1 -fi -bl 1 -rbl -k 1 -rk 
python run.py -t 20 -c 50000 -l bo -w 9 -cs 0 -sw 0 -na 2 -or 1 -al 1 -fi -bl 1 -rbl -tc "#000000,#888888" -b 3 
python run.py -t 20 -c 50000 -l bo -w 5 -cs 0 -sw 1 -na 2 -or 1 -al 1 -fi -bl 1 -rbl -tc "#000000,#888888" -b 3 
python run.py -t 20 -c 50000 -l bo -w 9 -cs 0 -sw 0 -na 2 -or 1 -al 1 -fi -bl 1 -rbl -tc "#EEEEEE,#FFFFFF" -b 3
python run.py -t 20 -c 50000 -l bo -w 5 -cs 0 -sw 1 -na 2 -or 1 -al 1 -fi -bl 1 -rbl -tc "#EEEEEE,#FFFFFF" -b 3
 
# 產生英文字 數字 不能用 -wd 280 否則會被截斷
python run.py -t 20 -c 20000 -w 2 -cs 0 -sw 1 -na 2 -al 1 -fi -b 3 -bl 1 -rbl 
python run.py -t 20 -c 20000 -w 2 -rs -num -cs 0 -sw 1 -na 2 -al 1 -fi -b 3 -bl 1 -rbl
python run.py -t 20 -c 20000 -w 2 -cs 0 -sw 1 -na 2 -al 1 -fi -b 3 -bl 1 -rbl -tc "#000000,#888888" 
python run.py -t 20 -c 20000 -w 2 -rs -num -cs 0 -sw 1 -na 2 -al 1 -fi -b 3 -bl 1 -rbl -tc "#000000,#888888" 
python run.py -t 20 -c 20000 -w 2 -cs 0 -sw 1 -na 2 -al 1 -fi -b 3 -bl 1 -rbl -tc "#EEEEEE,#FFFFFF" -b 3
python run.py -t 20 -c 20000 -w 2 -rs -num -cs 0 -sw 1 -na 2 -al 1 -fi -b 3 -bl 1 -rbl -tc "#EEEEEE,#FFFFFF" -b 3
```
# 因為太多放一個資料夾跑不動 太恐怖 所以小改程式放原來的路徑
```
for folder in folders:
    print(folder)
    # 根據檔案清單，合併到 train/labels.txt中，但是圖片原處處理不搬移，因為檔案太多讀不動

DATASET:
  DATASET: 360CC
# 因資料量太大放同一個資料夾會很慢，所以改成不同資料夾(原資料夾)
  ROOT: "../CRNN_Chinese_Characters_Rec_data/datasets"
```

```
(dbnet_wenmu) c:\Application\Develop\CRNN_Chinese_Characters_Rec>python train.py
=> creating output\360CC\checkpoints
=> creating output\360CC\log
torch.cuda.device_count() 2
load 3242588 images!
load 170663 images!
C:\Application\Anaconda3\envs\dbnet_wenmu\lib\site-packages\torch\cuda\nccl.py:15: UserWarning: PyTorch is not compiled with NCCL support
  warnings.warn('PyTorch is not compiled with NCCL support')
Epoch: [258][1/3167]    Time 140.113s (140.113s)        Speed 7.3 samples/s     Data 126.583s (126.583s)        Loss 11.76402 (11.76402)
Epoch: [258][101/3167]  Time 0.857s (2.226s)    Speed 1194.9 samples/s  Data 0.005s (1.258s)    Loss 1.33114 (2.27973)
Epoch: [258][201/3167]  Time 0.879s (1.550s)    Speed 1165.0 samples/s  Data 0.004s (0.634s)    Loss 0.91092 (1.70475)
Epoch: [258][301/3167]  Time 0.880s (1.328s)    Speed 1163.6 samples/s  Data 0.004s (0.425s)    Loss 0.74016 (1.43545)
Epoch: [258][401/3167]  Time 0.913s (1.221s)    Speed 1121.6 samples/s  Data 0.006s (0.320s)    Loss 0.69553 (1.26204)
Epoch: [258][501/3167]  Time 0.906s (1.160s)    Speed 1130.2 samples/s  Data 0.004s (0.258s)    Loss 0.62895 (1.13753)
Epoch: [258][601/3167]  Time 0.966s (1.122s)    Speed 1060.0 samples/s  Data 0.006s (0.216s)    Loss 0.48100 (1.03848)
Epoch: [258][701/3167]  Time 0.947s (1.096s)    Speed 1081.3 samples/s  Data 0.005s (0.186s)    Loss 0.40512 (0.95728)
```

```
Epoch: [263][3001/3167] Time 1.000s (1.033s)    Speed 1024.0 samples/s  Data 0.000s (0.048s)    Loss 0.04609 (0.06559)
Epoch: [263][3101/3167] Time 1.016s (1.032s)    Speed 1008.2 samples/s  Data 0.016s (0.047s)    Loss 0.05265 (0.06559)
get_last_lr : [0.001]
Epoch: [263][100/167]
----或----囂------保-----倞------鍞----数------趣-----扇-----豆----------------- => 或囂保倞鍞数趣扇豆 , gt: 或囂保倞鍞数趣扇豆  48209
----野--- ---殃---   ---愠---  ---关---- ----偷----------------------------- => 野 殃 愠 关 偷 , gt: 野 殃 愠 关 偷  48209
-------授---晴晴-----杼-----淚----发-----繅-----这-----诲-----显-----愁----------- => 授晴杼淚发繅这诲显愁, gt: 授晴杼淚发繅这诲显愁 48209
----傢---贬--稀----啁---垮---期----痴---墉----擄-------------------------------- => 傢贬稀啁垮期痴墉擄 , gt: 傢贬稀啁垮期痴墉擄  48209
-------故---絕-----敷-----尊-----恿----齜------甥----郅郅----勾-----蓁------------ => 故絕敷尊恿齜甥郅勾蓁, gt: 故絕敷尊恿齜甥郅勾蓁 48209
----旎---婢-----鲳-----釆-----粘-----觉----甄-----譜-----贿--------------------- => 旎婢鲳釆粘觉甄譜贿 , gt: 旎婢鲳釆粘觉甄譜贿  48209
----织---训-----蘊----储-----閨----肖-----五---噎-----维------------------------ => 织训蘊储閨肖五噎维 , gt: 织训蘊储閨肖五噎维  48209
----------窝---  -弘---   埒----   -：--  -忿---  --鞏--   -命---------------- => 窝 弘 埒 ： 忿 鞏 命, gt: 窝 弘 埒 ： 忿 鞏 命 48209
-------------蝓---  -核--  -霉--  -轿--  --葡--  -琴--  -衖------------------- => 蝓 核 霉 轿 葡 琴 衖, gt: 蝓 核 霉 轿 葡 琴 衖 48209
-------寨----福-----澱-----聋----缢----各-----侶-----类-----辜----参------------- => 寨福澱聋缢各侶类辜参, gt: 寨福澱聋缢各侶类辜参 48209
[#correct:158519 / #total:170663]
Test loss: 0.0656, accuray: 0.9288
is best: True
best acc is: 0.9288422212195965
Epoch: [264][1/3167]    Time 125.135s (125.135s)        Speed 8.2 samples/s     Data 123.901s (123.901s)        Loss 0.06298 (0.06298)
Epoch: [264][101/3167]  Time 0.937s (2.163s)    Speed 1092.3 samples/s  Data 0.016s (1.232s)    Loss 0.06238 (0.06164)
Epoch: [264][201/3167]  Time 0.953s (1.557s)    Speed 1074.4 samples/s  Data 0.016s (0.622s)    Loss 0.06179 (0.06111)
Epoch: [264][301/3167]  Time 0.969s (1.355s)    Speed 1057.1 samples/s  Data 0.000s (0.417s)    Loss 0.08494 (0.06194)
```

# 2023/05/24
原本訓練模型的時候都是用 280 x 32 大約產生 2 英文單字 or 5~10 中文字(有空白、無空白)
試試看產生長一點的樣本來訓練，看看效果會不會更支援長字串，同時也增加樣本(字)數
先試一下參數調整

```
# 比較有無 -fi (tight crop) 差別
(圖一)
python run.py -t 20 -c 200 -l bo -w 36 -cs 0 -sw 0 -na 2 -wd 888 -al 1 -fi -bl 1 -rbl
(圖二)
python run.py -t 20 -c 200 -l bo -w 36 -cs 0 -sw 0 -na 2 -wd 888 -al 1 -bl 1 -rbl
```
![](https://hackmd.io/_uploads/SkQms7iB3.jpg)
![](https://hackmd.io/_uploads/BJcgomjr2.jpg)

模型要調整參數的地方，在\lib\config\360CC_config.yaml裡面
```
TRAIN:
  BATCH_SIZE_PER_GPU: 200
  
  OPTIMIZER: 'adam'
  LR: 0.001
  
TEST:
  BATCH_SIZE_PER_GPU: 200
  
MODEL:
  NAME: 'crnn'
  IMAGE_SIZE:
    OW: 888 # origial width: 280
    H: 32
    W: 888   # resized width: 160
```
實際測試後確定變更樣本尺寸模型大小都一樣沒變，用finetune試試
也都沒問題，不用重新訓練。

```
# 產生(圖一)小字(沒 -fi) 置中 無空白 標準字
python run.py -t 20 -c 300000 -l bo -w 36 -cs 0 -sw 0 -na 2 -wd 888 -al 1 -bl 1 -rbl
# 產生(圖二)滿字(-fi) 置中 無空白 標準字
python run.py -t 20 -c 300000 -l bo -w 36 -cs 0 -sw 0 -na 2 -wd 888 -al 1 -fi -bl 1 -rbl
# 產生(圖三)小字(沒 -fi) 置中 空白 標準字
python run.py -t 32 -c 300000 -l bo -w 26 -cs 0 -sw 1 -na 2 -wd 888 -al 1 -bl 1 -rbl
# 產生(圖四)滿字(-fi) 置中 空白 標準字
python run.py -t 32 -c 300000 -l bo -w 24 -cs 0 -sw 1 -na 2 -wd 888 -al 1 -fi -bl 1 -rbl
# 產生(圖五)小字(沒 -fi) 置中 無空白 標準字 垂直 (max 839)
python run.py -t 20 -c 300000 -l bo -w 30 -cs 0 -sw 0 -na 2 -wd 888 -al 1 -bl 1 -rbl -or 1
# 產生(圖六)滿字(-fi) 置中 無空白 標準字 垂直 (max 823)
python run.py -t 20 -c 300000 -l bo -w 28 -cs 0 -sw 0 -na 2 -wd 888 -al 1 -fi -bl 1 -rbl -or 1
# 產生(圖七)小字(沒 -fi) 置中 空白 標準字 垂直 (max )
python run.py -t 32 -c 300000 -l bo -w 16 -cs 0 -sw 1 -na 2 -wd 888 -al 1 -bl 1 -rbl -or 1
# 產生(圖八)滿字(-fi) 置中 空白 垂直 (max )
python run.py -t 32 -c 300000 -l bo -w 14 -cs 0 -sw 1 -na 2 -wd 888 -al 1 -fi -bl 1 -rbl -or 1

# 目前共240萬樣本

```
![](https://hackmd.io/_uploads/HklXoZ2S2.jpg)
![](https://hackmd.io/_uploads/Hyjh1zhB3.jpg)
![](https://hackmd.io/_uploads/Hkk8ZzhBn.jpg)
![](https://hackmd.io/_uploads/rJiDrf3B3.jpg)
![](https://hackmd.io/_uploads/ByHw_z3Bn.jpg)
![](https://hackmd.io/_uploads/SJPklQhBn.jpg)
![](https://hackmd.io/_uploads/H1RKwUnr2.jpg)
![](https://hackmd.io/_uploads/BJiiv8nH2.jpg)

# 2024/04/21
拿上一次(段) 2023/05/24 的修改
```
# 主要修改 都加 -fi -m 2 -al 對齊 0,1,2
# 產生(圖一) 置左 無空白 標準字 繁中
python run.py -t 32 -c 300000 -l zh -w 28 -cs 0 -sw 0 -na 2 -wd 888 -al 0 -bl 1 -rbl -fi -m 2
# 產生(圖二) 置左 無空白 標準字 簡中 
python run.py -t 32 -c 300000 -l cn -w 28 -cs 0 -sw 0 -na 2 -wd 888 -al 0 -bl 1 -rbl -fi -m 2
# 產生(圖三) 置中 空白 標準字 繁中
python run.py -t 32 -c 300000 -l zh -w 18 -cs 0 -sw 1 -na 2 -wd 888 -al 1 -bl 1 -rbl -fi -m 2
# 產生(圖四) 置中 空白 標準字 簡中
python run.py -t 32 -c 300000 -l cn -w 18 -cs 0 -sw 1 -na 2 -wd 888 -al 1 -bl 1 -rbl -fi -m 2 
# 產生(圖五) 只會置中 無空白 標準字 垂直 (max 839) 繁中
python run.py -t 32 -c 300000 -l zh -w 22 -cs 0 -sw 0 -na 2 -wd 888 -bl 1 -rbl -or 1 -fi -m 2 
# 產生(圖六) 只會置中 無空白 標準字 垂直 (max 823) 簡中
python run.py -t 32 -c 300000 -l cn -w 22 -cs 0 -sw 0 -na 2 -wd 888 -bl 1 -rbl -or 1 -fi -m 2 
# 產生(圖七) 只會置中 空白 標準字 垂直 (max ) 繁中
python run.py -t 32 -c 300000 -l zh -w 12 -cs 0 -sw 1 -na 2 -wd 888 -bl 1 -rbl -or 1 -fi -m 2 
# 產生(圖八) 只會置中 空白 標準字 垂直 (max ) 簡中
python run.py -t 32 -c 300000 -l cn -w 12 -cs 0 -sw 1 -na 2 -wd 888 -bl 1 -rbl -or 1 -fi -m 2 
```

# 2024-06-02
```
python run.py -t 20 -c 500000 -l bo -w 30 -cs 0 -sw 1 -na 2 -wd 1153 -al 1 -fi -bl 1 -rbl -ft fonts\bo\mingliu.ttc
```











