FlanChanXwO commited on
Commit
d36c40a
·
verified ·
1 Parent(s): 8c75150

Upload README_zh.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README_zh.md +45 -57
README_zh.md CHANGED
@@ -2,7 +2,6 @@
2
  language:
3
  - zh
4
  license: agpl-3.0
5
- library_name: onnxruntime
6
  tags:
7
  - captcha
8
  - ocr
@@ -11,93 +10,82 @@ tags:
11
  - phpwind
12
  pipeline_tag: image-to-text
13
  model_type: phpwind-captcha-ocr
14
- metrics:
15
- - name: validation accuracy
16
- type: accuracy
17
- value: 0.8861
18
  ---
19
 
20
  # PHPWind 验证码识别
21
 
22
- [![Hugging Face 模型](https://img.shields.io/badge/Hugging%20Face-Model-FFD21E?logo=huggingface&logoColor=000)](https://huggingface.co/FlanChanXwO/phpwind-captcha-ocr)
23
- [![ONNX](https://img.shields.io/badge/Runtime-ONNX-005CED?logo=onnx&logoColor=fff)](https://onnx.ai/)
24
- [![PHPWind](https://img.shields.io/badge/Target-PHPWind-3776AB)](https://github.com/alibaba/phpwind)
25
- [![许可证:AGPL-3.0](https://img.shields.io/badge/License-AGPL--3.0-blue.svg)](LICENSE)
26
-
27
- 面向 PHPWind 内置四位数字验证码组件(`PwVerifyCode` / `PwGDCode`)的 ONNX OCR
28
- 模型。模型完全在本地运行,不依赖外部 API,也不需要 GPU。
29
-
30
- **PHPWind 参考实现源码**:[alibaba/phpwind](https://github.com/alibaba/phpwind),其中包含本模型
31
- 对应的 `PwVerifyCode` 与 `PwGDCode` 类。
32
 
33
  **English version**: [README.md](README.md)
34
 
35
- ![PHPWind 验证码样例](assets/example_captcha.png)
36
-
37
- > **上图验证码的正确答案:** `9125`
38
-
39
- ## 适用范围与负责任使用
40
 
41
- 本模型面向 PHPWind 站点的运营者、开发者及研究者,用于其自有或已获明确授权的
42
- PHPWind 部署。适合本地集成测试、无障碍研究,或评估自身验证码实现;不得用于
43
- 自动化账户登录或绕过访问控制。
44
 
45
- 不同 PHPWind 版本及自定义主题可能生成外观不同的验证码。部署前请以有授权的代表性
46
- 样本验证实际效果。
47
 
48
- ## 快速开始
49
 
50
- 安装运行时:
51
 
52
  ```bash
53
  pip install onnxruntime pillow numpy
54
  ```
55
 
56
- 对已获授权处理的验证码图片执行本地推理:
57
-
58
  ```python
59
  import numpy as np
60
  import onnxruntime as ort
61
  from PIL import Image
62
 
63
- session = ort.InferenceSession("model.onnx", providers=["CPUExecutionProvider"])
64
 
65
- def predict_captcha(path: str) -> str:
66
- image = Image.open(path).convert("RGB").resize((160, 64), Image.BILINEAR)
67
- inputs = np.asarray(image, dtype=np.float32).transpose(2, 0, 1)[None] / 255.0
68
- logits = session.run(None, {"input": inputs})[0]
69
- return "".join(str(int(logits[0, position].argmax())) for position in range(4))
70
 
71
- print(predict_captcha("captcha.png"))
72
  ```
73
 
74
- ## 模型接口
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
 
76
- | 项目 | 规格 |
77
  |---|---|
78
- | 输入 | `input`:`[batch, 3, 64, 160]`,`float32`,RGB 值域 `[0, 1]` |
79
- | 输出 | `logits`:`[batch, 4, 10]`;逐位置 argmax 得到一位数字 |
80
- | 预处理 | RGB → 缩放至 `160 × 64`(双线性)→ 除以 `255` |
81
- | 格式 | ONNX,opset 18 |
82
- | 运行环境 | 支持 CPU,无 GPU 依赖 |
83
 
84
- ## 评估
85
 
86
- 已发布 checkpoint 在 997 张人工标注的 PHPWind 验证码图片留出集上达到
87
- **88.61% 验证集准确率**。该值仅是模型卡参考指标,不保证特定 PHPWind 版本、主题或
88
- 部署环境中的表现。评估范围与复现要求见[评估说明](docs/zh/EVALUATION.md)。
89
 
90
- ## 文档
 
 
91
 
92
- - [推理指南](docs/zh/INFERENCE.md) —— Python 与 Go 集成细节
93
- - [训练与微调](docs/zh/TRAINING.md) —— 数据准备及模型训练
94
- - [评估说明](docs/zh/EVALUATION.md) —— 离线验证方法
95
- - [文档索引](docs/zh/README.md)
96
 
97
- ## 训练数据与许可证
 
98
 
99
- 该 checkpoint 使用位置保留 CNN 从零训练,训练数据为 997 张人工标注图片。需要适配时,
100
- 请只使用自有或已获授权的 PHPWind 部署所产生的验证码图片。
101
 
102
- 本项目采用 [GNU AGPL-3.0](LICENSE) 许可。修改版或通过网络提供服务的衍生作品须满足
103
- 许可证的对应源码提供义务。
 
2
  language:
3
  - zh
4
  license: agpl-3.0
 
5
  tags:
6
  - captcha
7
  - ocr
 
10
  - phpwind
11
  pipeline_tag: image-to-text
12
  model_type: phpwind-captcha-ocr
 
 
 
 
13
  ---
14
 
15
  # PHPWind 验证码识别
16
 
17
+ 识别 **PHPWind 论坛内置验证码**(4 位数字)的 OCR 模型。完全本地推理、无外部 API 依赖、ONNX 模型仅 4 MB。
 
 
 
 
 
 
 
 
 
18
 
19
  **English version**: [README.md](README.md)
20
 
21
+ ![验证码样例](assets/example_captcha.png)
 
 
 
 
22
 
23
+ ```
24
+ 示例输入 → 模型输出: 9125
25
+ ```
26
 
27
+ 这是 PHPWind 论坛软件的内置验证码组件(`PwVerifyCode` / `PwGDCode`),彩色数字、干扰线、扭曲都是它的标准特征。
 
28
 
29
+ ## 快速使用
30
 
31
+ ### Python (onnxruntime)
32
 
33
  ```bash
34
  pip install onnxruntime pillow numpy
35
  ```
36
 
 
 
37
  ```python
38
  import numpy as np
39
  import onnxruntime as ort
40
  from PIL import Image
41
 
42
+ sess = ort.InferenceSession("model.onnx", providers=["CPUExecutionProvider"])
43
 
44
+ def solve(path):
45
+ im = Image.open(path).convert("RGB").resize((160, 64), Image.BILINEAR)
46
+ x = np.asarray(im, dtype=np.float32).transpose(2, 0, 1)[None] / 255.0
47
+ logits = sess.run(None, {"input": x})[0]
48
+ return "".join(str(int(logits[0, p].argmax())) for p in range(4))
49
 
50
+ print(solve("captcha.png")) # 例如 "9125"
51
  ```
52
 
53
+ ### Go (onnxruntime_go)
54
+
55
+ 见 [docs/zh/INFERENCE.md](docs/zh/INFERENCE.md)。
56
+
57
+ ## 输入 / 输出规格
58
+
59
+ | 项 | 规格 |
60
+ |---|---|
61
+ | 输入 `input` | `[batch, 3, 64, 160]` float32,RGB,取值 `[0, 1]` |
62
+ | 输出 `logits` | `[batch, 4, 10]`,每位置 argmax → 数字 |
63
+ | ONNX opset | 18 |
64
+ | 预处理 | RGB → 缩放到 160x64(双线性)→ 除以 255 |
65
+
66
+ ## 评估结果
67
+
68
+ 用**真实论坛登录**作为 ground truth(登录成功 = 识别正确)。详见 [docs/zh/EVALUATION.md](docs/zh/EVALUATION.md)。
69
 
70
+ | 指标 | 数值 |
71
  |---|---|
72
+ | 验证集精度 | 88.6% |
73
+ | 真实登录单次命中 | **87.6%** (85/97) |
74
+ | 带重试登录成功率 | ≈99.9997% |
 
 
75
 
76
+ ## 训练 / 微调
77
 
78
+ 997 张人工标注验证码,CNN 从零训练(位置保留架构)。
 
 
79
 
80
+ - 数据集(997 张已标注图片):[FlanChanXwO/phpwind-captcha-dataset](https://huggingface.co/datasets/FlanChanXwO/phpwind-captcha-dataset)
81
+ - 脚本:`scripts/train_fixed.py`
82
+ - 指南:[docs/zh/TRAINING.md](docs/zh/TRAINING.md)
83
 
84
+ ## 说明
 
 
 
85
 
86
+ - 验证码为 PHPWind 内置组件(非站点定制)。
87
+ - 不同 PHPWind 版本参数可能有差异,换站使用前建议对比样例确认风格。
88
 
89
+ ## 许可证
 
90
 
91
+ GNU AGPL-3.0 —— 可自由使用、修改、分发(含商用),但修改版/衍生作品必须同样以 AGPL 开源;网络服务使用也需提供源码。详见 [LICENSE](LICENSE)。