<<<<<<< HEAD
基于 ConvNeXt-Tiny 的图像分类模型,适配华为 Ascend 910B/910C NPU。
原模型: timm/convnext_tiny.in12k_ft_in1k
镜像: ai.gitcode.com/hf_mirrors/timm/convnext_tiny.in12k_ft_in1k
| 属性 | 说明 |
|---|---|
| 任务 | 图像分类(ImageNet-1k 1000 类) |
| 架构 | ConvNeXt-Tiny |
| 输入尺寸 | 224 × 224 RGB |
| 输出 | 1000 类 logits → Softmax 概率 |
| 参数量 | 28.6M |
| Top-1 准确率 | 84.186% |
| Top-5 准确率 | 97.124% |
| 预训练数据 | ImageNet-12k (11,821 类子集) → ImageNet-1k 微调 |
| 许可证 | Apache 2.0 |
确保已安装昇腾 NPU 驱动和 CANN 软件包,版本建议 CANN 7.0.RC1 及以上。
# 验证 NPU 可用
npu-smi info# 创建虚拟环境(推荐 Python 3.9+)
python3 -m venv venv
source venv/bin/activate
# 安装依赖
pip install -r requirements.txttorch_npu 需根据 CANN 版本安装,参考 Ascend PyTorch:
pip install torch-npu==2.1.0.post8
import torch
import torch_npu # noqa: F401
print(torch.npu.is_available()) # 应输出 True
print(torch.npu.device_count()) # NPU 卡数量python inference.py --image_path /path/to/image.jpg默认从 HuggingFace 镜像 timm/convnext_tiny.in12k_ft_in1k 自动下载模型权重。
# 从 HuggingFace Hub
python inference.py --image_path test.jpg --model_path timm/convnext_tiny.in12k_ft_in1k
# 从镜像源
python inference.py --image_path test.jpg --model_path ai.gitcode.com/hf_mirrors/timm/convnext_tiny.in12k_ft_in1k
# 从本地目录
python inference.py --image_path test.jpg --model_path ./model_weights
# 强制 CPU 推理
python inference.py --image_path test.jpg --cpu
# 显示 Top-3 结果
python inference.py --image_path test.jpg --topk 3[INFO] 推理设备: npu:0
[INFO] 加载模型: timm/convnext_tiny.in12k_ft_in1k
[INFO] 模型加载完成,参数量: 28,589,416
[INFO] 输入尺寸: (3, 224, 224)
[INFO] 输入图像: test.jpg (1024×768)
============================================================
Top-5 预测结果
============================================================
#1: golden retriever (207) — 92.35%
#2: Labrador retriever (208) — 3.21%
#3: English setter (170) — 1.12%
#4: flat-coated retriever (209) — 0.89%
#5: curly-coated retriever (210) — 0.67%
============================================================
推理耗时: 12.34 ms
设备: npu:0
============================================================convnext_tiny.in12k_ft_in1k/
├── inference.py # 推理脚本(Ascend NPU 适配)
├── README.md # 本部署说明文档
├── requirements.txt # 环境依赖清单
└── assets/ # 截图素材
├── agent_workflow.png # 部署/推理流程截图
├── npu_device_call.png# NPU 设备调用截图
└── model_result.png # 推理结果截图输入图像 ──→ 预处理 (Resize 256 + CenterCrop 224 + Normalize) ──→ ConvNeXt-Tiny ──→ Softmax ──→ Top-5 预测
↑
Ascend NPU (torch_npu)本仓库已集成至 AtomGit 模型仓,支持一键拉取:
git clone https://ai.atomgit.com/ohhoohho/convnext_tiny.in12k_ft_in1k.git
cd convnext_tiny.in12k_ft_in1k
pip install -r requirements.txt
python inference.py --image_path example.jpg