| --- |
| language: |
| - zh |
| tags: |
| - image-classification |
| - orientation-detection |
| - document-scanning |
| - onnx |
| library_name: onnxruntime |
| license: mit |
| --- |
| |
| # Fachuan 图片方向分类器 |
|
|
| 基于 ConvNeXtV2-Atto 微调的四方向图片分类 ONNX 模型,专为票据/文档图片自动旋转设计。 |
|
|
| ## 模型信息 |
|
|
| | 项目 | 值 | |
| |------|-----| |
| | 基础模型 | facebook/convnextv2-atto-1k-224 | |
| | 参数量 | 3.7M | |
| | 输入分辨率 | 384 × 384 | |
| | 输入格式 | float32 [1, 3, 384, 384],ImageNet 归一化 | |
| | 输出 | float32 [1, 4] → 0° / 90° / 180° / 270° | |
| | 验证准确率 | 99.6% | |
| | 模型大小 | ~13 MB(INT8 量化) | |
|
|
| ## 分类含义 |
|
|
| | 类别索引 | 目录名 | 含义 | 后端旋转角度 | |
| |---------|--------|------|-------------| |
| | 0 | 0 | 正向,无需旋转 | 0° | |
| | 1 | 180 | 上下颠倒 | 180° | |
| | 2 | 270 | 逆时针旋转 | -90° | |
| | 3 | 90 | 顺时针旋转 | -270° | |
|
|
| ## 快速使用 |
|
|
| ```python |
| import numpy as np |
| import onnxruntime as ort |
| from PIL import Image |
| |
| session = ort.InferenceSession("fachuan-orientation-classifier.onnx") |
| |
| img = Image.open("receipt.jpg").convert("RGB").resize((384, 384)) |
| arr = np.array(img, dtype=np.float32).transpose(2, 0, 1) / 255.0 |
| mean = np.array([0.485, 0.456, 0.406]).reshape(3, 1, 1) |
| std = np.array([0.229, 0.224, 0.225]).reshape(3, 1, 1) |
| arr = ((arr - mean) / std).unsqueeze(0) |
| |
| logits = session.run(None, {"pixel_values": arr})[0] |
| predicted_class = int(np.argmax(logits, axis=1)[0]) |
| ROTATION_MAP = {0: 0, 1: 180, 2: -90, 3: -270} |
| print(f"预测方向: {predicted_class}°, 需旋转: {ROTATION_MAP[predicted_class]}°") |
| ``` |
|
|
| ## 训练数据 |
|
|
| 使用法穿(Fachuan)项目内部票据图片训练,包含发票、收据、微信聊天截图等场景。 |
|
|
| - 训练集:1116 张(279 张原始图 × 4 个旋转角度) |
| - 验证集:276 张 |
| - 数据增强:RandomResizedCrop、ColorJitter |
|
|
| ## 训练元信息 |
|
|
| 详见 [convnextv2-acc996.json](convnextv2-acc996.json) |
|
|
| ## 许可证 |
|
|
| MIT License |
|
|