ConvNeXt-Tiny 是来自论文 A ConvNet for the 2020s 的图像分类模型,由 Ross Wightman 在 timm 库中实现。
本模型在 ImageNet-12k(11821 类子集)上预训练,并在 ImageNet-1k 上微调。
| 属性 | 值 |
|---|---|
| 模型类型 | Image Classification (ConvNeXt) |
| 参数量 | 28.59M |
| GMACs | 4.5 |
| 输入尺寸 | 224x224 (训练), 288x288 (测试) |
| 输出类别 | 1000 |
| 预训练数据 | ImageNet-12k + ImageNet-1k |
| 依赖项 | 版本要求 | 说明 |
|---|---|---|
| 操作系统 | CentOS 7.6+ / Ubuntu 18.04+ | 支持主流 Linux 发行版 |
| CANN | 5.0.RC2+ | 华为昇腾计算架构 |
| Python | 3.10 / 3.12 | 推荐 3.10+ |
| PyTorch | 2.0.0+ | 推荐 2.10 |
| torch_npu | 与 PyTorch 版本匹配 | 昇腾 PyTorch 扩展 |
| timm | >=1.0.0 | 模型加载 |
| safetensors | >=0.4.0 | 权重加载 |
# 1) 激活已预装 torch / torch_npu 的 conda 环境
conda activate pt2100
# 2) 安装模型依赖(使用华为云源)
pip install --index-url https://repo.huaweicloud.com/repository/pypi/simple \
timm>=1.0.0 safetensors torch_npu
# 3) 验证环境
python -c "
import torch, torch_npu, timm
print('torch:', torch.__version__)
print('torch_npu:', torch_npu.__version__)
print('timm:', timm.__version__)
print('NPU 可用:', torch.npu.is_available())
"# 进入适配目录
cd /workspace/agent1/convnext_tiny.in12k_ft_in1k-ascend
# 确认上游权重存在
ls -la /workspace/agent2/timm/convnext_tiny.in12k_ft_in1k/
# 期望输出:config.json model.safetensors (~109MB) pytorch_model.bin ...# 检查 NPU 设备状态
npu-smi info
# 验证 torch_npu 安装
python -c "import torch; import torch_npu; print('NPU 可用:', torch.npu.is_available())"# 基本用法:默认参数 (NPU:0)
python inference.py --device npu:0
# 指定其他 NPU 卡
python inference.py --device npu:1
# CPU 模式(仅在 NPU 不可用时使用)
python inference.py --device cpuconda activate pt2100
cd /workspace/agent1/convnext_tiny.in12k_ft_in1k-ascend
python inference.py --device npu:0实际输出:
[W822 13:20:54.491103370 FunctionLoader.cpp:48] Warning: LD_PRELOAD detected...
[W822 13:21:03.849731670 NPUCachingAllocator.cpp:201] Warning: The current CANN and Soc versions require processing for 32 padding size, with memory allocation. (function operator())
============================================================
ConvNeXt-Tiny 昇腾 NPU 推理
============================================================
[Device] npu:0
[Model Path] /workspace/agent2/timm/convnext_tiny.in12k_ft_in1k
[Loading] ConvNeXt-Tiny model from timm...
Model loaded from safetensors
Total params: 28.59M
[Model Loaded] Allocated: 0.11 GB, Reserved: 0.12 GB
[npu-smi info]
+------------------------------------------------------------------------------------------------+
| npu-smi 25.5.2 Version: 25.5.2 |
+---------------------------+---------------+----------------------------------------------------+
| NPU Name | Health | Power(W) Temp(C) Hugepages-Usage(page)|
| Chip | Bus-Id | AICore(%) Memory-Usage(MB) HBM-Usage(MB) |
+===========================+===============+====================================================+
| 0 910B2 | OK | 103.0 41 0 / 0 |
| 0 | 0000:C1:00.0 | 0 0 / 0 3613 / 65536 |
+===========================+===============+====================================================+
+---------------------------+---------------+----------------------------------------------------+
| NPU Chip | Process id | Process name | Process memory(MB) |
+===========================+===============+====================================================+
| 0 0 | 1316521 | python | 244 |
+===========================+===============+====================================================+
[Creating] Dummy input image (3x224x224)...
Input shape: torch.Size([1, 3, 224, 224])
[npu-smi info]
+------------------------------------------------------------------------------------------------+
| npu-smi 25.5.2 Version: 25.5.2 |
+---------------------------+---------------+----------------------------------------------------+
| NPU Name | Health | Power(W) Temp(C) Hugepages-Usage(page)|
| Chip | Bus-Id | AICore(%) Memory-Usage(MB) HBM-Usage(MB) |
+===========================+===============+====================================================+
| 0 910B2 | OK | 104.0 40 0 / 0 |
| 0 | 0000:C1:00.0 | 0 0 / 0 3613 / 65536 |
+===========================+===============+====================================================+
+---------------------------+---------------+----------------------------------------------------+
| NPU Chip | Process id | Process name | Process memory(MB) |
+===========================+===============+====================================================+
| 0 0 | 1316521 | python | 244 |
+===========================+===============+====================================================+
[Running Classification]...
[npu-smi info]
+------------------------------------------------------------------------------------------------+
| npu-smi 25.5.2 Version: 25.5.2 |
+---------------------------+---------------+----------------------------------------------------+
| NPU Name | Health | Power(W) Temp(C) Hugepages-Usage(MB)|
| Chip | Bus-Id | AICore(%) Memory-Usage(MB) HBM-Usage(MB) |
+===========================+===============+====================================================+
| 0 910B2 | OK | 104.3 41 0 / 0 |
| 0 | 0000:C1:00.0 | 0 0 / 0 3646 / 65536 |
+===========================+===============+====================================================+
+---------------------------+---------------+----------------------------------------------------+
| NPU Chip | Process id | Process name | Process memory(MB) |
+===========================+===============+====================================================+
| 0 0 | 1316521 | python | 276 |
+===========================+===============+====================================================+
[Results]
Output shape: torch.Size([1, 1000])
Top-5 classes: [21, 78, 644, 111, 600]
Top-5 probabilities: ['0.0054', '0.0050', '0.0046', '0.0043', '0.0042']
[Memory After Inference] Allocated: 0.11 GB, Reserved: 0.15 GB
[Done]✅ 验证要点:
解决方案:
source /usr/local/Ascend/ascend-toolkit/latest/set_env.sh)npu-smi info 检查设备状态解决方案:
pip install --upgrade timmCUDA_VISIBLE_DEVICES=0 python inference.py解释:当前推理使用随机输入进行演示。真实使用时,需要:
convnext_tiny.in12k_ft_in1k-ascend/
├── inference.py # 推理脚本(torch_npu 推理)
├── README.md # 本文档
├── requirements.txt # 依赖列表
└── assets/ # 资源占位目录上游权重目录(只读,未被修改):
/workspace/agent2/timm/convnext_tiny.in12k_ft_in1k/
├── config.json # 模型配置
├── model.safetensors # 权重 (~109MB)
├── pytorch_model.bin # PyTorch 格式权重 (~109MB)
└── README.md # 原始文档# ConvNeXt-Tiny 昇腾 NPU 推理环境依赖
# 核心依赖(必须)
torch>=2.0.0
torch_npu
timm>=1.0.0
safetensors>=0.4.0
numpy使用方式:
# 激活环境
conda activate pt2100
# 安装依赖(华为云源)
pip install --index-url https://repo.huaweicloud.com/repository/pypi/simple -r requirements.txt