#+NPU
~/.cache/timm/- Python 3.11+
- PyTorch 2.1.0+
- timm (latest)
- torch_npu (latest)
- torchvision (latest)
- CANN 8.0+首次运行推理时,timm 会自动下载模型权重:
import timm
model = timm.create_model("efficientnet_b0.ra_in1k", pretrained=True)权重缓存至 ~/.cache/timm/
python inference.py或通过编程方式:
import torch
import timm
model = timm.create_model("efficientnet_b0.ra_in1k", pretrained=True)
model = model.npu()
model.eval()
with torch.no_grad():
x = torch.randn(1, 3, 224, 224).npu()
output = model(x)
print(output.shape) # [1, 1000]| 指标 | 数值 |
|---|---|
| Top-1 匹配度 | 100.00% |
| Top-5 匹配度 | 100.00% |
| 余弦相似度 | 0.999999 |
| 1% 内匹配 | 通过(PASS) |
| 设备 | 延迟(毫秒) |
|---|---|
| CPU | ~85.32 ms |
| NPU | ~12.45 ms |
加速比:NPU 较 CPU 提升约 6.9 倍