训练

开源地址

https://github.com/kerlomz/captcha_trainer/tree/cnn

训练集与测试集

样本可以先做灰度处理,能提高识别率

训练集

数据尽量多,注意文件命名规范 值_任意名称.png
a

测试集

文件个数需要大于500个
a

训练配置

config.yaml
# Device: [gpu:0, cpu:0] The default device is GPU.
# - requirement.txt - GPU: tensorflow-gpu, CPU: tensorflow
# - If you use the GPU version, you need to install some additional applications.
# TrainRegex and TestRegex: Default matching apple_20181010121212.jpg file.
# TrainsPath and TestPath: The local absolute path of your training and testing set.
System:
NeuralNet: 'CNNNet'
Device: 'cpu:0'
DeviceUsage: 0.9
TrainsPath: 'D:\train\1\'
TrainRegex: '.*?(?=_.*\.)'
TestPath: 'D:\train\2\'
TestRegex: '.*?(?=_.*\.)'

# SavedStep: A Session.run() execution is called a Step,
# - Used to save training progress, Default value is 100.
# TestNum: The number of samples for each test batch.
# - A test for every saved steps.
# CompileAcc: When the accuracy reaches the set threshold,
# - the model will be compiled together each time it is archived.
# - Available for specific usage scenarios.
# EndAcc: Finish the training when the accuracy reaches [EndAcc*100]%.
# EndStep: Finish the training when the step is greater than the [-1: Off, EndStep >0: On] step.
# LearningRate: Find the fastest relationship between the loss decline and the learning rate.
Trains:
SavedStep: 100
TestNum: 500
CompileAcc: 0.9
EndAcc: 0.95
EndStep: -1
LearningRate: 0.001
model.yaml
# Convolution: The number of layers is at least 3.
# - The number below corresponds to the size of each layer of convolution.
# Provide flexible neural network construction,
# Adjust the neural network structure that suits you best
# [Convolution, Pool, Optimization: {Dropout}]
CNNNet:
Layer:
- Convolution: 32
- Pool: [1, 2, 2, 1]
- Optimization: Dropout
- Convolution: 64
- Pool: [1, 2, 2, 1]
- Optimization: Dropout
- Convolution: 64
- Pool: [1, 2, 2, 1]
- Optimization: Dropout
ConvCoreSize: 3
FullConnect: 1024

# ModelName: Corresponding to the model file in the model directory,
# - such as YourModelName.pb, fill in YourModelName here.
# CharSet: Provides a default optional built-in solution:
# - [ALPHANUMERIC, ALPHANUMERIC_LOWER, ALPHANUMERIC_UPPER, NUMERIC]
# - Or you can use your own customized character set like: ['a', '1', '2'].
# ImageChannel: [1 - Gray Scale, 3 - RGB].
# CharLength: Captcha Length.
Model:
ModelName: GuoModel
ImageChannel: 1
CharLength: 5
CharSet: NUMERIC

# Magnification: [ x2 -> from size(50, 50) to size(100,100)].
# OriginalColor: [false - Gray Scale, true - RGB].
# Binaryzation: [-1: Off, >0 and < 255: On].
# Smoothing: [-1: Off, >0: On].
# Blur: [-1: Off, >0: On].
# Resize: [WIDTH, HEIGHT].
Pretreatment:
Magnification: 0
OriginalColor: false
Binaryzation: 240
Smoothing: 3
Invert: false
Blur: 5
# Resize: [160, 60]

开始训练

python3 trains.py

打包好的gpu exe训练程序,可配置好后直接cmd运行

链接:https://pan.baidu.com/s/1rvZ4FBJ94iC9rZJ0yQtyvg
提取码:my4i

部署识别

开源地址

https://github.com/kerlomz/captcha_platform/tree/cnn
注意config.py有一行错误 可能会导致运行异常 需要注释掉
a

model.yaml
# Device: [gpu:0, cpu:0]
System:
Device: 'gpu:0'

# ModelName: Corresponding to the model file in the model directory,
# - such as YourModelName.pb, fill in YourModelName here.
# CharSet: Provides a default optional built-in solution:
# - [ALPHANUMERIC, ALPHANUMERIC_LOWER, ALPHANUMERIC_UPPER, NUMERIC]
# - Or you can use your own customized char set like: ['a', '1', '2'].
# ImageChannel: [1 - Gray Scale, 3 - RGB].
# CharLength: Captcha Length.
Model:
ModelName: GuoModel
ImageChannel: 1
CharLength: 5
CharSet: NUMERIC

# Magnification: [ x2 -> from size(50, 50) to size(100,100)].
# OriginalColor: [false - Gray Scale, true - RGB].
# Binaryzation: [-1: Off, >0 and < 255: On].
# Smoothing: [-1: Off, >0: On].
# Invert [Binaryzation Color Invert]
# Blur: [-1: Off, >0: On].
# Resize: [WIDTH, HEIGHT].
Pretreatment:
Magnification: 0
OriginalColor: false
Binaryzation: 240
Smoothing: 3
Invert: false
Blur: 5
# Resize: [160, 60]

端口可以更改 通过命令行

python flask_server.py -p 8888
pip install -r requirements.txt  -i https://pypi.tuna.tsinghua.edu.cn/simple   

tensorflow版本未限制 可能会异常 要加一下限制 完整的txt版本

tensorflow==1.6.0
flask>=0.12.3
gevent>=1.2.2
Flask-Caching>=1.3.3
gevent-websocket>=0.10.1
futures>=3.1.1
tensorflow>=1.6.0
pillow>=4.3.0
opencv-python>=3.3.0.10
numpy==1.14.1
grpcio>=1.14.2
grpcio_tools>=1.14.2
requests>=2.18.4
pyyaml>=3.13
tornado>=5.1.1