NanCunChild commited on
Commit
e89b06b
·
0 Parent(s):

Initial release: nano/small/full captcha recognition models

Browse files

- nano (95.49%, 94KB): minimal size for embedded use
- small (99.96%, 390KB): recommended for general deployment
- full (99.97%, 780KB): highest accuracy
- distill-nano: knowledge distillation experiment

.gitattributes ADDED
@@ -0,0 +1 @@
 
 
1
+ *.pth filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ checkpoint_epoch_*.pth
2
+ best_model.pth
README.md ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - zh
4
+ license: mit
5
+ tags:
6
+ - pytorch
7
+ - image-classification
8
+ - captcha
9
+ - ocr
10
+ - cnn
11
+ pipeline_tag: image-classification
12
+ metrics:
13
+ - accuracy
14
+ model-index:
15
+ - name: zfw-captcha-model
16
+ results:
17
+ - task:
18
+ type: image-classification
19
+ name: Captcha Recognition
20
+ metrics:
21
+ - type: accuracy
22
+ value: 99.96
23
+ name: Whole-image Accuracy (small)
24
+ - type: accuracy
25
+ value: 99.97
26
+ name: Whole-image Accuracy (full)
27
+ - type: accuracy
28
+ value: 95.49
29
+ name: Whole-image Accuracy (nano)
30
+ ---
31
+
32
+ # ZFW Captcha Recognition Model
33
+
34
+ 针对**正方教务系统自服务平台**的 4 位纯数字验证码识别模型。纯 CNN 架构,无需 RNN/CTC,轻量高效。
35
+
36
+ ## Model Variants
37
+
38
+ | 文件 | 变体 | 参数量 | 文件大小 | 验证集准确率 | 推荐场景 |
39
+ |------|------|--------|----------|-------------|----------|
40
+ | `small/final_model.pth` | **small** | ~96K | 390 KB | **99.96%** | 通用部署(推荐) |
41
+ | `full/final_model.pth` | full | ~196K | 780 KB | 99.97% | 追求极致精度 |
42
+ | `nano/final_model.pth` | nano | ~21K | 94 KB | 95.49% | 极致压缩 / 嵌入式 |
43
+ | `distill-nano/final_model.pth` | nano (distilled) | ~21K | 94 KB | — | 蒸馏实验产物 |
44
+
45
+ > **推荐选择 `small`**:390KB 即可达到 99.96% 准确率,性价比最高。
46
+
47
+ ## Task Description
48
+
49
+ - **验证码类型**:4 位纯数字(0-9),固定长度
50
+ - **来源平台**:正方教务系统(ZFW)自服务平台
51
+ - **干扰形式**:旋转、噪点、干扰线
52
+ - **输入尺寸**:90 × 34 像素,RGB
53
+
54
+ ### Sample
55
+
56
+ ```
57
+ ┌──────────────────┐
58
+ │ 3 8 0 7 │ ← 带噪点和干扰线的 4 位数字
59
+ └──────────────────┘
60
+ ```
61
+
62
+ ## Architecture
63
+
64
+ ```
65
+ Input (3, 34, 90)
66
+ → [Conv3×3 + BN + ReLU + MaxPool] × 3 (空间降采样)
67
+ → [Conv3×3 + BN + ReLU] × N (特征提取)
68
+ → AdaptiveAvgPool2d(1, 4) (压缩为 4 列,对应 4 个数字位置)
69
+ → 4 × Linear(C, 10) (每个位置独立 10 分类)
70
+ Output: (B, 4, 10) logits
71
+ ```
72
+
73
+ 设计理由:验证码为固定 4 位、位置固定的纯数字,不存在变长对齐问题,因此使用空间池化 + 多头分类代替 RNN/CTC,简单高效。
74
+
75
+ ## Quick Start
76
+
77
+ ```python
78
+ import torch
79
+ from torchvision import transforms
80
+ from PIL import Image
81
+
82
+ # 1. Define model (copy from src/model.py or install the package)
83
+ from model import build_model
84
+
85
+ # 2. Load
86
+ model = build_model('small')
87
+ model.load_state_dict(torch.load('small/final_model.pth', map_location='cpu'))
88
+ model.eval()
89
+
90
+ # 3. Preprocess
91
+ transform = transforms.Compose([
92
+ transforms.Resize((34, 90)),
93
+ transforms.ToTensor(),
94
+ transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
95
+ ])
96
+
97
+ img = Image.open('captcha.png').convert('RGB')
98
+ x = transform(img).unsqueeze(0) # (1, 3, 34, 90)
99
+
100
+ # 4. Predict
101
+ with torch.no_grad():
102
+ logits = model(x) # (1, 4, 10)
103
+ digits = logits.argmax(dim=2) # (1, 4)
104
+ result = ''.join(str(d.item()) for d in digits[0])
105
+
106
+ print(result) # e.g. "3807"
107
+ ```
108
+
109
+ ## Training
110
+
111
+ - **框架**:PyTorch
112
+ - **损失函数**:CrossEntropyLoss × 4(每位数字独立)
113
+ - **优化器**:Adam (lr=0.001, fused)
114
+ - **学习率调度**:StepLR (step=10, gamma=0.5)
115
+ - **早停**:patience=8
116
+ - **数据增强**:无(仅 Normalize)
117
+ - **训练监控**:[SwanLab](https://swanlab.cn/@nancunchild/zfw_captcha_train)
118
+
119
+ ### Training Curves
120
+
121
+ 完整训练过程(loss、accuracy、learning rate 曲线)请查看:
122
+
123
+ **[SwanLab Dashboard](https://swanlab.cn/@nancunchild/zfw_captcha_train)**
124
+
125
+ ## Source Code
126
+
127
+ 训练代码开源:[GitHub - zfw_captcha_train](https://github.com/NanCunChild/zfw_captcha_train)
128
+
129
+ ## Limitations
130
+
131
+ - 仅支持正方教务系统特定样式的验证码
132
+ - 仅识别 4 位纯数字(0-9),不支持字母或其他字符
133
+ - 输入图片应为 90×34 或等比例尺寸
134
+
135
+ ## License
136
+
137
+ MIT
distill-nano/final_model.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1a0fbc11de12ed2119488117d452618dbe739f2a6f54d51b3fcccd0160e774db
3
+ size 96219
full/final_model.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:649437efd869878acc566894e9c072b696a6353fe2da05bf2c7269769ea426a7
3
+ size 799393
nano/final_model.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e128ba0c158e4eda9c2d7d80ed3ac053b1ae7dc462e488dba0b4e3006dd27999
3
+ size 96219
small/final_model.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ea503209e471e4bfc5fd27c4eb8fc26ceee39bf230fa1f7cc89d5dca48878e87
3
+ size 400225