Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- zh
|
| 4 |
+
tags:
|
| 5 |
+
- image-classification
|
| 6 |
+
- orientation-detection
|
| 7 |
+
- document-scanning
|
| 8 |
+
- onnx
|
| 9 |
+
library_name: onnxruntime
|
| 10 |
+
license: mit
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
# Fachuan 图片方向分类器
|
| 14 |
+
|
| 15 |
+
基于 ConvNeXtV2-Atto 微调的四方向图片分类 ONNX 模型,专为票据/文档图片自动旋转设计。
|
| 16 |
+
|
| 17 |
+
## 模型信息
|
| 18 |
+
|
| 19 |
+
| 项目 | 值 |
|
| 20 |
+
|------|-----|
|
| 21 |
+
| 基础模型 | facebook/convnextv2-atto-1k-224 |
|
| 22 |
+
| 参数量 | 3.7M |
|
| 23 |
+
| 输入分辨率 | 384 × 384 |
|
| 24 |
+
| 输入格式 | float32 [1, 3, 384, 384],ImageNet 归一化 |
|
| 25 |
+
| 输出 | float32 [1, 4] → 0° / 90° / 180° / 270° |
|
| 26 |
+
| 验证准确率 | 99.6% |
|
| 27 |
+
| 模型大小 | ~13 MB(INT8 量化) |
|
| 28 |
+
|
| 29 |
+
## 分类含义
|
| 30 |
+
|
| 31 |
+
| 类别索引 | 目录名 | 含义 | 后端旋转角度 |
|
| 32 |
+
|---------|--------|------|-------------|
|
| 33 |
+
| 0 | 0 | 正向,无需旋转 | 0° |
|
| 34 |
+
| 1 | 180 | 上下颠倒 | 180° |
|
| 35 |
+
| 2 | 270 | 逆时针旋转 | -90° |
|
| 36 |
+
| 3 | 90 | 顺时针旋转 | -270° |
|
| 37 |
+
|
| 38 |
+
## 快速使用
|
| 39 |
+
|
| 40 |
+
```python
|
| 41 |
+
import numpy as np
|
| 42 |
+
import onnxruntime as ort
|
| 43 |
+
from PIL import Image
|
| 44 |
+
|
| 45 |
+
session = ort.InferenceSession("fachuan-orientation-classifier.onnx")
|
| 46 |
+
|
| 47 |
+
img = Image.open("receipt.jpg").convert("RGB").resize((384, 384))
|
| 48 |
+
arr = np.array(img, dtype=np.float32).transpose(2, 0, 1) / 255.0
|
| 49 |
+
mean = np.array([0.485, 0.456, 0.406]).reshape(3, 1, 1)
|
| 50 |
+
std = np.array([0.229, 0.224, 0.225]).reshape(3, 1, 1)
|
| 51 |
+
arr = ((arr - mean) / std).unsqueeze(0)
|
| 52 |
+
|
| 53 |
+
logits = session.run(None, {"pixel_values": arr})[0]
|
| 54 |
+
predicted_class = int(np.argmax(logits, axis=1)[0])
|
| 55 |
+
ROTATION_MAP = {0: 0, 1: 180, 2: -90, 3: -270}
|
| 56 |
+
print(f"预测方向: {predicted_class}°, 需旋转: {ROTATION_MAP[predicted_class]}°")
|
| 57 |
+
```
|
| 58 |
+
|
| 59 |
+
## 训练数据
|
| 60 |
+
|
| 61 |
+
使用法穿(Fachuan)项目内部票据图片训练,包含发票、收据、微信聊天截图等场景。
|
| 62 |
+
|
| 63 |
+
- 训练集:1116 张(279 张原始图 × 4 个旋转角度)
|
| 64 |
+
- 验证集:276 张
|
| 65 |
+
- 数据增强:RandomResizedCrop、ColorJitter
|
| 66 |
+
|
| 67 |
+
## 训练元信息
|
| 68 |
+
|
| 69 |
+
详见 [convnextv2-acc996.json](convnextv2-acc996.json)
|
| 70 |
+
|
| 71 |
+
## 许可证
|
| 72 |
+
|
| 73 |
+
MIT License
|