RADIO-B (Reduce All Domains Into One) 是 NVIDIA 的视觉基础模型,本项目提供其在华为 Ascend NPU 环境下的部署方案。
/data/ysws/agentsp/RADIO-B-ascend/
├── inference.py # 精度测试脚本
├── log.txt # 测试日志
├── README.md # 本文档
├── test_image.pt # 测试图像 (3x224x224)
└── test_image_448.pt # 测试图像 (3x448x448)docker exec -it test-modelagent bashsource /usr/local/Ascend/ascend-toolkit/set_env.shcd /data/ysws/agentsp/RADIO-B-ascend/
python3 inference.py| 指标 | 实测值 | 阈值 | 状态 |
|---|---|---|---|
| Summary Relative Error | 0.77% | < 1% | PASS |
| Features Relative Error | 0.11% | < 1% | PASS |
| 操作 | 耗时 |
|---|---|
| NPU 推理 (1x3x224x224) | 0.34s |
完整测试日志保存在 log.txt
| 属性 | 值 |
|---|---|
| Patch Size | 16 |
| Max Resolution | 2048 |
| Preferred Resolution | 768x768 |
| AMP | Enabled (bfloat16) |
| Summary Dim | 2304 |
| Features Dim | 768 |
output = model(pixel_values)
# output.summary: torch.Size([B, 2304]) - 全局图像特征
# output.features: torch.Size([B, 196, 768]) - 空间特征import torch
from transformers import AutoModel
model = AutoModel.from_pretrained("/data/ysws/agentsp/RADIO-B", trust_remote_code=True)
model = model.to("npu:0")
pixel_values = torch.randn(1, 3, 224, 224).to("npu:0")
output = model(pixel_values)
print(f"Summary: {output.summary.shape}") # [1, 2304]
print(f"Features: {output.features.shape}") # [1, 196, 768]from einops import rearrange
spatial = rearrange(
output.features,
'b (h w) d -> b d h w',
h=14, w=14
)
# spatial shape: [1, 768, 14, 14]本模型依赖以下包,已在容器中预装:
A: 检查 NPU 驱动是否正确安装,确保 CANN 环境变量已 source。
A: 使用较短的图像进行测试,或使用批量处理。
A: 模型使用 bfloat16 AMP,会产生约 0.5-1% 的数值差异,这属于正常范围。
本项目遵循 NVIDIA RADIO 原始许可证。