• Stars
    star
    127
  • Rank 281,129 (Top 6 %)
  • Language
    Python
  • Created almost 5 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

验证码识别比赛code,针对数字,大小写字母能达到97-99%的准确率

计算机挑战赛 2019 验证码识别竞赛 一等奖方案

1. Background

基于https://github.com/dee1024/pytorch-captcha-recognition进行改进,原版中数据集采用的captcha库自动生成的图片,可以随意制定生成数量,并且相对而言生成的图片比较简单。

本次项目是全国高校计算机能力挑战赛中的人工智能赛道里的验证码识别,该比赛需要识别26(大写)+26(小写)+数字(10)= 62个字符,随机组成的四位验证码图片。训练集仅有5000张,并且识别的难度系数较大,人眼有时候也很容易识别出错。

2. Environment

  • 显存:4G+

  • Ubuntu16.04

  • numpy

  • pandas

  • torch==1.3.1

  • torchnet==0.0.4

  • torchvision==0.2.0

  • tqdm

  • visdom

可通过pip install -r requirements.txt进行环境的安装

3. Dataset

1575527368225

比赛提供的数据集如图所示,120$\times$40的像素的图片,然后标签是由图片名称提供的。训练集测试集划分:80%的数据用于训练集,20%的数据用于测试集。

  • 训练图片个数为:3988

  • 测试图片个数为:1000

训练的数据还是明显不够的,考虑使用数据增强,通过查找github上很多做数据增强的库,最终选择了Augmentor库作为图像增强的库。

安装方式:pip install Augmentor

API: https://augmentor.readthedocs.io/en/master/index.html

由于验证码与普通的分类图片有一定区别,所以选择的增强方式有一定局限,经过几轮实验,最终选取了distortion类的方法作为具体增强方法,输入为训练所用的图片,输出设置为原来图片个数的2倍,具体代码见dataAug.py, 核心代码如下:

def get_distortion_pipline(path, num):
    p = Augmentor.Pipeline(path)
    p.zoom(probability=0.5, min_factor=1.05, max_factor=1.05)
    p.random_distortion(probability=1, grid_width=6, grid_height=2, magnitude=3)
    p.sample(num)
    return p

将得到的图片重命名为auged_train文件夹,最终数据集组成如下:

root 
	- data
		- train:3988张
		- test:1000张
		- auged_train:7976张

如果需要数据集请联系我,联系方式在最后

链接:https://pan.baidu.com/s/13BmN7Na4ESTPAgyfBAHMxA 提取码:v4nk

数据集结构的组织,从网盘下载数据以后,按照以下文件夹格式进行组织:

- data
	- train
	- test
	- auged_train

然后就可以训练了。

4. Structure

root 
	- config
		- parameters.py 主要包括超参数,最重要的是learning rate
	- lib
		- center_loss.py 将center loss引入,用于训练
		- dataset.py 包装Dataset,针对train文件夹和auged_train文件夹内容各自写了一个处理类
		- generate_captcha.py 生成简单的数据集,在没有官方数据集的情况下
		- optimizer.py RAdam, AdamW, label smooth等新的optimizer
		- scheduler.py 新增了warmup机制
	- model
		- BNNeck.py 基于resnet18使用了bnnect结构,来自罗浩大佬行人检测中的trick
		- CaptchaNet.py 手工构建的一个简单网络,原有库提供的
		- dense.py 更改backbone,使用dense121作为backbone,其他也可以更改
		- dualpooling.py 在resnet18基础上添加了dual pooling,增加了信息
		- IBN.py 使用ibn模块,以resnet18为基础
		- model.py resnet18,添加dropout
		- res18.py 引入了attention机制和dual pooling
		- senet.py 将senet作为backbone
	- result
		- submission.csv 结果保存
	- utils
		- cutoff.py 数据增强方法,不适合验证码,可以用在普通图片
		- dataAug.py 使用Agumentor进行数据增强
		- Visdom.py 使用visdom记录log,进行可视化
- predict.py 引入了多模型预测,然后分析结果
- run.py 与predict类似,不过是单模型的预测
- test.py 规定测试模型权重,待测试图片路径,对测试集进行测试
- train.py 模型的训练,每个epoch先训练所有的train,然后训练所有的auged_train图片

5. Result

最好结果:

ResNet18+Dropout(0.5)+RAdam+DataAugmentation+lr(3e-4) = 98.4%测试集准确率,线上A榜:97%

1575530185666

模型分析:分析四个模型,python predict.py 观察预测出错的结果,评判模型好坏,最终选择了0号模型。

1575530264099

6. Procedure

调参过程记录:null代表未记录

Name item1 item2 item3 item4 item5 测试:线上
baseline0 ResNet18 lr=1e-3 4:1划分 Adam 88%:84%
baseline1 ResNet34 lr=1e-3 4:1划分 Adam 90%:84%
baseline2 ResNet18 lr=1e-3 4:1划分 RAdam null:90%
baseline3 ResNet18 lr=3e-4 4:1划分 RAdam 未收敛
baseline4 ResNet18 lr=1e-1 4:1划分 RAdam 96.4%:87%
baseline5 ResNet18 lr=1e-1 4:1划分 RAdam aug0 98%:93%
baseline6 ResNet18 lr=1e-1 9:1划分 RAdam aug1 60%:null
baseline7 ResNet18 lr=1e-3 4:1划分 RAdam aug2 null:94%
baseline8 ResNet18 lr=1e-3 4:1划分 AdamW aug2 98.4%:92.56%
baseline9 ResNet18 lr=1e-3 4:1划分 RAdam aug3 null:93.52%
baseline10 ResNet18 lr=1e-3 4:1划分 RAdam aug4 null:94.16%
baseline11 ResNet18 lr=1e-3 9:1划分 RAdam aug5 60%:null
baseline12 ResNet18 lr=3.5e-4 4:1划分 RAdam aug2 null:94.72%
baseline13 ResNet18 lr=3.5e-4 decay:6e-4 4:1划分 RAdam aug2 null:95.16%
baseline14 ResNet18 lr=3.5e-4 decay:7e-4 4:1划分 RAdam aug2 bad
baseline15 ResNet18 lr=3.5e-5 decay:6.5e-4 4:1划分 RAdam aug2 null:95%
baseline16 ResNet18 lr=3.5e-5 decay:6.5e-4 4:1划分 RAdam drop(0.5) null:97%

以上的aug代表数据增强:

  • aug0: +distrotion

  • aug1: 9:1划分+扩增3倍

  • aug2: +distortion+zoom

  • aug3: +tilt+扩增两倍

  • aug4: aug2+aug3混合

  • aug5: 9:1划分 +tilt倾斜

数据增强示意图:

example1 example2 example3
1 2 3

后期由于错过了提交时间,只能进行测试集上的测试,主要方案有以下:

  • learning rate scheduler尝试:CosineAnnealingLR, ReduceLROnPlateau,StepLR,MultiStepLR
  • 更改backbone: senet, densenet
  • 在res18基础上添加:attention机制,dual pooling, ibn模块,bnneck等
  • 尝试center loss,收敛很慢,但是效果应该不错

还未尝试的方案:

  • label smooth
  • 多模型ensemble

More Repositories

1

SimpleCVReproduction

Replication of simple CV Projects including attention, classification, detection, keypoint detection, etc.
Jupyter Notebook
1,199
star
2

awesome-attention-mechanism-in-cv

Awesome List of Attention Modules and Plug&Play Modules in Computer Vision
Python
1,032
star
3

SimpleCVPaperReading

😄博客论文列表:分系列整理
JavaScript
391
star
4

voc2007_for_yolo_torch

👊 Prepare VOC format datasets for ultralytics/yolov3 & yolov5
Python
194
star
5

landmark_annotation

👊 Keypoint/Landmark Annotation Software 关键点标注软件
TeX
121
star
6

Awesome-LLM-Prune

Awesome list for LLM pruning.
117
star
7

captcha_identify.pytorch

基于torch进行验证码识别,识别率达94%
Python
103
star
8

Awesome-LLM-Quantization

Awesome list for LLM quantization
Python
73
star
9

PyTorch-CIFAR-Model-Hub

Implementation of Conv-based and Vit-based networks designed for CIFAR.
Python
67
star
10

Pruner-Zero

Pruner-Zero: Evolving Symbolic Pruning Metric from scratch for LLMs
Python
63
star
11

datawhale_cv_competition

布匹缺陷识别练习赛
Python
45
star
12

GoodsRecognition.MindSpore

基于MindSpore AI框架实现零售商品识别 top1方案
Python
32
star
13

reid_for_deepsort

simple reid for deep sort
Python
23
star
14

CVPR2022-NAS-competition-Track1-3th-solution

Implementation of PGONAS for CVPR22W and RD-NAS for ICASSP23
Jupyter Notebook
23
star
15

Vision-Mamba-CIFAR10

Python
21
star
16

QPainter

CPP intern,Sotfware,Painter
C++
20
star
17

faster-rcnn.Supernova

基于faster-rcnn.pytorch改进,超新星识别比赛code
Python
15
star
18

darknet-loss-Drawer

This repository is developed on the basis of pyqt5, mainly through the log files generated during the running of Darknet, and then draw loss files.
Python
15
star
19

PicoNAS

Modularized NAS Framework
Python
8
star
20

yolo_deep_sort_pytorch

attention, cbam, se
Jupyter Notebook
7
star
21

yolov3.keras

yolov3.keras for VOC2007
Python
6
star
22

CUDA_NMS

Use cuda to speed up the implementation of nms algorithm
Cuda
5
star
23

ofa-cifar

⭐ Make Once for All support CIFAR10 dataset.
Python
4
star
24

mixed_precision_imagenet_benchmark

ResNet50在ImageNet上混合精度
Python
4
star
25

lightllm-gradio

Based on LightLLM, we provide interface using Gradio. Feel free to use!
Python
4
star
26

AutoRF

AutoRF: Learning Receptive Fields with Spatial Pooling
Python
3
star
27

52RL

Reforcement Learning in DataWhale
Python
3
star
28

simple_deep_sort

deep sort with yolov3. Modify darknet based yolov3 to pytorch based yolov3.
Python
3
star
29

Mnc-javacc

Implementing the Minic compiler with javacc
Java
3
star
30

ClipLLM

Clipboard-Centric LLM conversation tools
Python
3
star
31

chessProblem

棋盘问题,可视化求解
Python
2
star
32

MutableNAS

Channel Search for ResNet20; cvpr21 NAS workshop 16th
Python
2
star
33

ArchVizD3

zero-cost proxy visualization on NAS-Bench-201 using d3.js
HTML
2
star
34

AlgorithmPractice

大学期间编程练习题目
C++
1
star
35

classify.fastai

Classifier based on fastai
Jupyter Notebook
1
star
36

webAppTemplate

An example for Android webview
HTML
1
star
37

skills-code-with-codespaces

My clone repository
HTML
1
star
38

pprp

1
star
39

NAS-Bench-201-refactor

Original version of NAS-Bench-201 from AngleNAS
Python
1
star
40

ClipLLM_Mac

Swift
1
star
41

CleanStream

Local version of dclm
Python
1
star