Skip to content
ModelListedExternal
Browse files

Zfw Captcha Model

针对正方教务系统自服务平台的 4 位纯数字验证码识别模型。纯 CNN 架构,无需 RNN/CTC,轻量高效。

KindOtherVersionRevision 4682a4b

Model source

Kind
Other
File size
94.0–781 KB
Version
vRevision 4682a4b
Updated
Sep 19, 2026
Downloads
0
Source
Hugging Face

Source description

ZFW Captcha Recognition Model

针对正方教务系统自服务平台的 4 位纯数字验证码识别模型。纯 CNN 架构,无需 RNN/CTC,轻量高效。

Model Variants

文件变体参数量文件大小验证集准确率推荐场景
small/final_model.pthsmall~96K390 KB99.96%通用部署(推荐)
full/final_model.pthfull~196K780 KB99.97%追求极致精度
nano/final_model.pthnano~21K94 KB95.49%极致压缩 / 嵌入式
distill-nano/final_model.pthnano (distilled)~21K94 KB—蒸馏实验产物

推荐选择 small:390KB 即可达到 99.96% 准确率,性价比最高。

Task Description

  • 验证码类型:4 位纯数字(0-9),固定长度
  • 来源平台:正方教务系统(ZFW)自服务平台
  • 干扰形式:旋转、噪点、干扰线
  • 输入尺寸:90 × 34 像素,RGB

Samples

样本标签
98009800
93509350

Architecture

Input (3, 34, 90)
    → [Conv3×3 + BN + ReLU + MaxPool] × 3   (空间降采样)
    → [Conv3×3 + BN + ReLU] × N             (特征提取)
    → AdaptiveAvgPool2d(1, 4)                (压缩为 4 列,对应 4 个数字位置)
    → 4 × Linear(C, 10)                     (每个位置独立 10 分类)
Output: (B, 4, 10) logits

设计理由:验证码为固定 4 位、位置固定的纯数字,不存在变长对齐问题,因此使用空间池化 + 多头分类代替 RNN/CTC,简单高效。

Quick Start

import torch
from torchvision import transforms
from PIL import Image

# 1. Define model (copy from src/model.py or install the package)
from model import build_model

# 2. Load
model = build_model('small')
model.load_state_dict(torch.load('small/final_model.pth', map_location='cpu'))
model.eval()

# 3. Preprocess
transform = transforms.Compose([
    transforms.Resize((34, 90)),
    transforms.ToTensor(),
    transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
])

img = Image.open('captcha.png').convert('RGB')
x = transform(img).unsqueeze(0)  # (1, 3, 34, 90)

# 4. Predict
with torch.no_grad():
    logits = model(x)              # (1, 4, 10)
    digits = logits.argmax(dim=2)  # (1, 4)
    result = ''.join(str(d.item()) for d in digits[0])

print(result)  # e.g. "3807"

Training

  • 框架:PyTorch
  • 损失函数:CrossEntropyLoss × 4(每位数字独立)
  • 优化器:Adam (lr=0.001, fused)
  • 学习率调度:StepLR (step=10, gamma=0.5)
  • 早停:patience=8
  • 数据增强:无(仅 Normalize)
  • 训练监控:SwanLab

Training Curves

完整训练过程(loss、accuracy、learning rate 曲线)请查看:

SwanLab Dashboard

Source Code

训练代码开源:GitHub - zfw_captcha_train

Limitations

  • 仅支持正方教务系统特定样式的验证码
  • 仅识别 4 位纯数字(0-9),不支持字母或其他字符
  • 输入图片应为 90×34 或等比例尺寸

License

MIT

Sources

1 source
Hugging FacePrimaryVersion 4682a4bfd24e825b30bcece945d12676aef1703d
huggingface.co/NanCunChild/zfw-captcha-model/tree/4682a4bfd24e825b30bcece945d12676aef1703d

Verified Sep 10

Download files

Model artifacts

4 artifacts

distill-nano/final_model.pth

pth · 94.0 KB · SHA-256 1a0fbc11de12…74db · Hugging Face

Download file

full/final_model.pth

pth · 781 KB · SHA-256 649437efd869…26a7 · Hugging Face

Download file

nano/final_model.pth

pth · 94.0 KB · SHA-256 e128ba0c158e…7999 · Hugging Face

Download file

small/final_model.pth

pth · 391 KB · SHA-256 ea503209e471…8e87 · Hugging Face

Download file

Source excerpts

2 excerpts

--- language: - zh license: mit tags: - pytorch - image-classification - captcha - ocr - cnn pipeline_tag: image-classification metrics: - accuracy model-index: - name: zfw-captcha-model results: - task: type: image-classification name: Captcha Recognition metrics: - type: accuracy value: 99.96 name: Whole-image Accuracy (small) - type: accuracy value: 99.97 name: Whole-image Accuracy (full) - type: accuracy value: 95.49 name: Whole-image Accuracy (nano) --- # ZFW Captcha Recognition Model 针对**正方教务系统自服务平台**的 4 位纯数字验证码识别模型。纯 CNN 架构,无需 RNN/CTC,轻量高效。 ## Model Variants | 文件 | 变体 | 参数量 | 文件大小 | 验证集准确率 | 推荐场景 | |------|------|--------|----------|-------------|----------| | `small/final_model.pth` | **small** | ~96K | 390 KB | **99.96%** | 通用部署(推荐) | | `full/final_model.pth` | full | ~196K | 780 KB | 99.97% | 追求极致精度 | | `nano/final_model.pth` | nano | ~21K | 94 KB | 95.49% | 极致压缩 / 嵌入式 | | `distill-nano/final_model.pth` | nano (distilled) | ~21K | 94 KB | — | 蒸馏实验产物 | > **推荐选择 `small`**:390KB 即可达到 99.96% 准确率,性价比最高。 ## Task Description - **验证码类型**:4 位纯数字(0-9),固定长度 - **来源平台**:正方教务系统(ZFW)自服务平台 - **干扰形式**:旋转、噪点、干扰线 - **输入尺寸**:90 × 34 像素,RGB ### Samples | 样本 | 标签 | |------|------| | ![9800](samples/9800.png) | `9800` | | ![9350](samples/9350.png) | `9350` | ## Architecture ``` Input (3, 34, 90) → [Conv3×3 + BN + ReLU + MaxPool] × 3 (空间降采样) → [Conv3×3 + BN + ReLU] × N (特征提取) → AdaptiveAvgPool2d(1, 4) (压缩为 4 列,对应 4 个数字位置) → 4 × Linear(C, 10) (每个位置独立 10 分类) Output: (B, 4, 10) logits ``` 设计理由:验证码为固定 4 位、位置固定的纯数字,不存在变长对齐问题,因此使用空间池化 + 多头分类代替 RNN/CTC,简单高效。 ## Quick Start ```python import torch from torchvision import transforms from PIL import Image # 1. Define model (copy from src/model.py or install the package) from model import build_model # 2. Load model = build_model('small') model.load_state_dict(torch.load('small/final_model.pth', map_location='cpu')) model.eval() # 3. Preprocess transform = transforms.Compose([ transforms.Resize((34, 90)), transforms.ToTensor(), transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]), ]) img = Image.open('captcha.png').convert('RGB') x = transform(img).unsqueeze(0) # (1, 3, 34, 90) # 4. Predict with torch.no_grad(): logits = model(x) # (1, 4, 10) digits = logits.argmax(dim=2) # (1, 4) result = ''.join(str(d.item()) for d in digits[0]) print(result) # e.g. "3807...

Source context: 0 downloads · 0 likes · Pipeline image-classification · Repo NanCunChild/zfw-captcha-model