SE-ResNet50 (AugMix³, IN1K) — 使用 AugMix 深度增强训练的 SE-ResNet50
seresnet50.a3_in1k| 组件 | 要求 |
|---|---|
| Python | >= 3.10 |
| PyTorch | >= 2.1.0 |
| torch-npu | >= 2.1.0 |
| timm | 1.0.27 |
| Pillow | >= 10.0.0 |
| Ascend CANN | 8.5.1 |
| NPU | Ascend910 (显存 32GB) |
pip install torch timm Pillow如果使用 Ascend NPU,还需安装 torch-npu:
pip install torch-npu创建以下推理脚本 inference.py(已包含在本仓库中):
import torch
import timm
from PIL import Image
from timm.data import resolve_data_config, create_transform
model = timm.create_model('seresnet50.a3_in1k', pretrained=True)
model = model.eval()
img = Image.open('test_input.jpg').convert('RGB')
config = resolve_data_config({}, model=model)
transform = create_transform(**config)
input_tensor = transform(img).unsqueeze(0)
with torch.no_grad():
output = model(input_tensor)
probs = torch.nn.functional.softmax(output, dim=1)
top_probs, top_indices = torch.topk(probs, 5)
print(top_indices, top_probs)CPU 推理:
python3 inference.py --model seresnet50.a3_in1k --device cpu --image test_input.jpgNPU 推理:
python3 inference.py --model seresnet50.a3_in1k --device npu --image test_input.jpg使用 compare_cpu_npu.py 对 CPU 和 NPU 的推理结果进行精度对比:
python3 compare_cpu_npu.py| 指标 | CPU | NPU (Ascend910) |
|---|---|---|
| 推理耗时 | 129.74 ms | 169.81 ms |
| 加速比 | 1.0× | 0.76× |
使用 compare_cpu_npu.py 对 CPU 和 NPU 的输出进行逐元素对比。
| 指标 | 数值 |
|---|---|
| 最大绝对误差 (Max Abs Error) | 7.594109e-03 |
| 平均绝对误差 (Mean Abs Error) | 2.110079e-03 |
| 均方误差 (MSE) | 6.960707e-06 |
| 余弦相似度 (Cosine Similarity) | 1.0000000000 |
| 相对误差 (Relative Error) | 0.0289% |
| 最大概率差异 (Max Prob Diff) | 2.345592e-04 |
| Top-1 分类一致 | 是 |
| Top-5 重叠数 | 5/5 |
| 指标 | CPU | NPU |
|---|---|---|
| Top-1 预测标签 | 21 | 21 |
| Top-1 一致 | 是 | - |
| Top-5 重叠率 | 5/5 | - |
NPU (Ascend910) 与 CPU 的推理结果相对误差为 0.0289%,余弦相似度为 1.0000000000。
结论:NPU 与 CPU 推理结果误差 < 1%,精度满足要求,通过!

├── inference.py # NPU 推理脚本
├── compare_cpu_npu.py # CPU vs NPU 精度对比脚本
├── requirements.txt # 依赖清单
├── readme.md # 本文件
└── screenshot.png # 模拟终端截图#+NPU#+CV#+昇腾#+Ascend#+timm#+ImageNet#+图像分类#+SE