SE-ResNet33ts (RandomAugment², IN1K) — 轻量级 SE-ResNet 变体,33 层
seresnet33ts.ra2_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('seresnet33ts.ra2_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 seresnet33ts.ra2_in1k --device cpu --image test_input.jpgNPU 推理:
python3 inference.py --model seresnet33ts.ra2_in1k --device npu --image test_input.jpg使用 compare_cpu_npu.py 对 CPU 和 NPU 的推理结果进行精度对比:
python3 compare_cpu_npu.py| 指标 | CPU | NPU (Ascend910) |
|---|---|---|
| 推理耗时 | 255.64 ms | 171.28 ms |
| 加速比 | 1.0× | 1.49× |
使用 compare_cpu_npu.py 对 CPU 和 NPU 的输出进行逐元素对比。
| 指标 | 数值 |
|---|---|
| 最大绝对误差 (Max Abs Error) | 2.939939e-03 |
| 平均绝对误差 (Mean Abs Error) | 5.856056e-04 |
| 均方误差 (MSE) | 5.387095e-07 |
| 余弦相似度 (Cosine Similarity) | 0.9999994301 |
| 相对误差 (Relative Error) | 0.7629% |
| 最大概率差异 (Max Prob Diff) | 3.734604e-05 |
| Top-1 分类一致 | 是 |
| Top-5 重叠数 | 5/5 |
| 指标 | CPU | NPU |
|---|---|---|
| Top-1 预测标签 | 111 | 111 |
| Top-1 一致 | 是 | - |
| Top-5 重叠率 | 5/5 | - |
NPU (Ascend910) 与 CPU 的推理结果相对误差为 0.7629%,余弦相似度为 0.9999994301。
结论: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