testmodel.py 1.23 KB
Newer Older
raojy's avatar
raojy committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import torch
from mmengine.config import Config
from mmdet3d.registry import MODELS

# 1. 唤醒 MMDetection3D 的全家桶注册表 (修复报错的这行极其关键!)
from mmdet3d.utils import register_all_modules
register_all_modules(init_default_scope=True)

# 2. 显式导入 BEVFusion 项目,触发自定义算子和模块的注册!
import projects.BEVFusion.bevfusion

print("🔍 正在解析 BEVFusion 配置文件...")
# 使用官方提供的默认配置文件
config_file = 'projects/BEVFusion/configs/bevfusion_lidar-cam_voxel0075_second_secfpn_8xb4-cyclic-20e_nus-3d.py'
cfg = Config.fromfile(config_file)

print("🧱 正在海光 DCU 上构建 BEVFusion 模型架构...")
try:
    # 实例化模型
    model = MODELS.build(cfg.model)
    
    # 推入海光 GPU (DCU) 显存
    model.cuda()
    
    # 打印一下网络参数量,确认实体存在
    num_params = sum(p.numel() for p in model.parameters() if p.requires_grad)
    print(f"\n✅ 帅!模型在显存中构建成功!")
    print(f"📊 模型总可训练参数量: {num_params / 1e6:.2f} M (百万)")
    print("🚀 恭喜!高层 API 与配置文件解析完美通关!")
    
except Exception as e:
    print(f"\n❌ 模型构建失败,报错信息如下:\n{e}")