BEVFusion-mit复现与实践(nuscenes数据集)

一、CUDA版本11.1

二、创建虚拟环境并激活

conda create -n bevfusion python=3.8
conda activate bevfusion

三、安装pytorch

1、下载cuda对应版本的torch和torchvision到本地文件夹

下载地址:https://download.pytorch.org/whl/torch_stable.html

在这里插入图片描述
2、进入安装包文件夹安装:

pip install torch-1.10.0+cu111-cp38-cp38-linux_x86_64.whl
pip install torchvision-0.11.0+cu111-cp38-cp38-linux_x86_64.whl

3、验证:

python
import torch
print(torch.__version__)
#1.10.0+cu111
import torchvision
print(torchvision.__version__)
#0.11.0+cu111

四、安装openmpi

1、下载安装:

wget https://download.open-mpi.org/release/open-mpi/v4.1/openmpi-4.1.4.tar.gz
tar zxf openmpi-4.1.4.tar.gz

cd openmpi-4.1.4
./configure --prefix=/usr/local/openmpi
make -j8
sudo make install

2、 配置环境~/.bashrc

MPI_HOME=/usr/local/openmpi
OMPI_MCA_opal_cuda_support=true
export PATH=${MPI_HOME}/bin:$PATH
export LD_LIBRARY_PATH=${MPI_HOME}/lib:$LD_LIBRARY_PATH
export MANPATH=${MPI_HOME}/share/man:$MANPATH

3、测试

cd openmpi-4.1.4/examples
make
mpirun -np 4 hello_c

出现以下:
在这里插入图片描述

五、安装功能包

conda 虚拟环境下

pip install mmcv-full==1.4.0 -f https://download.openmmlab.com/mmcv/dist/cu111/torch1.10.0/index.html
pip install mmdet==2.20.0
conda install openmpi
conda install mpi4py
pip install Pillow==8.4.0
pip install tqdm
pip install torchpack
pip install nuscenes-devkit
pip install ninja
pip install numpy==1.19
pip install numba==0.48.0
pip install shapely==1.8.0

六、源码下载

源码下载地址:https://github.com/mit-han-lab/bevfusion

git clone https://github.com/mit-han-lab/bevfusion.git

七、参数修改与编译

1、更改indice_cuda.cu

在mmdet3d/ops/spconv/src/indice_cuda.cu下,将里面的4096都改成256,否则会爆显存

2、更改目录的setup.py

需要把显卡算力改成自己对应的,其余的注释掉。例如我的3090是86(具体的算力对应大家可以查查)

"-D__CUDA_NO_HALF_OPERATORS__",
"-D__CUDA_NO_HALF_CONVERSIONS__",
"-D__CUDA_NO_HALF2_OPERATORS__",
"-gencode=arch=compute_70,code=sm_70",
"-gencode=arch=compute_80,code=sm_80",
"-gencode=arch=compute_86,code=sm_86",

3、当前目录下编译

python setup.py develop

八、nuscenes-mini版本

1、配置文件

1.1 下载nuScenes数据集

下载地址:https://www.nuscenes.org/nuscenes

1.2 文件夹结构

bevfusion
├── tools
├── configs
├── data
│   ├── nuscenes
│   │   ├── maps
│   │   ├── samples
│   │   ├── sweeps
│   │   ├── v1.0-mini

Map expansion pack(v1.3) 下载解压到maps文件夹中。否则后面运行分割的时候会报错!
在这里插入图片描述

1.3 运行数据转换的脚本

python tools/create_data.py  nuscenes --root-path ./data/nuscenes/ --version v1.0-mini --out-dir data/nuscenes/ --extra-tag nuscenes

报错1ImportError: cannot import name ‘feature_decorator_ext’ from partially initialized module ‘mmdet3d.ops.feature_decorator’ (most likely due to a circular import) (/home/mengwen/bevfusion/mmdet3d/ops/feature_decorator/init.py)

解决

(1)注释掉 mmdet3d/ops/init.py 中的 from .feature_decorator import feature_decorator

报错2FileNotFoundError: NuScenesDataset: [Errno 2] No such file or directory: ‘data/nuscenes//nuscenes_infos_train.pkl’

解决:更改tools/data_converter/nuscenes_converter.py 中第95~100行

info_path = osp.join(root_path,
'{}_infos_train.pkl'.format(info_prefix))
info_val_path = osp.join(root_path,
'{}_infos_val.pkl'.format(info_prefix))

在这里插入图片描述

转换之后nuscenes文件夹:

在这里插入图片描述

2、开始复现

2.1 下载预训练权重

下载地址:http://drive.google.com/drive/folders/1Jru7VTfgvFF949DlP1oDfriP3wrmOd3c

在这里插入图片描述

2.2 训练

(1)修改参数

  • 设置训练轮数:
    configs/default.yaml中修改epoch:max_epochs: 6
    configs/nuscenes/det/transfusion/secfpn/camera+lidar/default.yaml, max_epoch:6
  • 显存溢出:
    configs/nuscenes/default.yaml, samples_per_gpu: 2(bitch_size),workers_per_gpu: 2
    configs/nuscenes/det/centerhead/lssfpn/camera/256x704/swint/ default.yaml, 建议设置samples_per_gpu: 3

(2)开始训练

原文readme里-np后面是8,这里要改成1(因为我们PC上跑是单GPU),不然会卡住不动

torchpack dist-run -np 1 python tools/train.py configs/nuscenes/det/transfusion/secfpn/camera+lidar/swint_v0p075/convfuser.yaml --model.encoders.camera.backbone.init_cfg.checkpoint pretrained/swint-nuimages-pretrained.pth --load_from pretrained/lidar-only-det.pth

报错1TypeError: FormatCode() got an unexpected keyword argument ‘verify’

解决:yapf包的版本问题,我原来yapf包的0.40.2,降低为yapf==0.40.1

pip install yapf==0.40.1

报错2AttributeError: module ‘distutils’ has no attribute ‘version’

解决:setuptools版本过高导致的问题

pip install setuptools==58.0.4

报错3RuntimeError: Given groups=1, weight of size [8, 1, 1, 1], expected input[24, 6, 256, 704] to have 1 channels, but got 6 channels instead

解决:将 mmdet3d/models/vtransforms/base 中第38行: add_depth_features=True 改为 False ,37行也改为 False

报错4RuntimeError: CUDA out of memory. Tried to allocate 168.00 MiB (GPU 0; 23.70 GiB total capacity; 2.41 GiB already allocated; 96.50 MiB free; 2.43 GiB reserved in total by PyTorch) If reserved memory i

解决:单卡gpu不能满足,采用分布式训练,在mmdet3d/apis/train.py文件中把distributed参数设置为True,直接vs-code全局搜索找到distributed

在这里插入图片描述
(3)训练结束:

在这里插入图片描述2.3 测试

#预训练模型测试
torchpack dist-run -np 1 python tools/test.py configs/nuscenes/det/transfusion/secfpn/camera+lidar/swint_v0p075/convfuser.yaml pretrained/bevfusion-det.pth --eval bbox
  • 测试完成:

在这里插入图片描述

3、实践

3.1 训练BEVFusion detection

多卡更换顺序在前面加上:CUDA_VISIBLE_DEVICES=‘3,2,1,0’

CUDA_VISIBLE_DEVICES='3,2,1,0' torchpack dist-run -np 2 python tools/train.py configs/nuscenes/det/transfusion/secfpn/camera+lidar/swint_v0p075/convfuser.yaml --model.encoders.camera.backbone.init_cfg.checkpoint pretrained/swint-nuimages-pretrained.pth --run-dir train_result

训练完成后会在train_result目录下生成下面文件 结构如下:

在这里插入图片描述
configs.yaml和latest.pth在测试和可视化需要使用

3.2 测试

#生成box.pkl文档

#自己训练模型测试
torchpack dist-run -np 1 python tools/test.py train_result/configs.yaml train_result/latest.pth --eval bbox --out box.pkl

测试完成:

在这里插入图片描述

3.3 生成可视化

torchpack dist-run -np 1 python tools/visualize.py train_result/configs.yaml --mode gt --checkpoint train_result/latest.pth --bbox-score 0.5 --out-dir vis_result

报错1ModuleNotFoundError: No module named ‘torchpack.utils.tqdm’

解决:把tools/visualize.py文件中from torchpack.utils.tqdm import tqdm改成from tqdm import tqdm

解决:在mmdet3d/models/vtransforms/base.py中2个forward函数的参数都加上metas变量,加到**kwargs前

在这里插入图片描述
3.4 查看结果

在vis_result下生成可视化文件

在这里插入图片描述

可视化结果:

在这里插入图片描述

九、nuscenes正常版本

1、运行数据转换的脚本

调用根目录下的数据集

python tools/create_data.py nuscenes --root-path /data/public_dataset/nuscenes --out-dir /home/mengwen/BEV/bevfusion/data/nuscenes --extra-tag nuscenes 

2、训练BEVFusion detection

torchpack dist-run -np 4 python tools/train.py configs/nuscenes/det/transfusion/secfpn/camera+lidar/swint_v0p075/convfuser.yaml --model.encoders.camera.backbone.init_cfg.checkpoint pretrained/swint-nuimages-pretrained.pth --load_from pretrained/lidar-only-det.pth 

参考:
1、复现BEVFusion遇到过的坎儿
2、BEVFusion(mit)最强环境安装,部署复现
3、BEV Fusion (MIT) 环境配置
4、BEVFusion代码复现实践

### 实现 MIT BEVFusion 项目代码复现教程 #### 准备工作 为了顺利进行BEVFusion项目的代码复现,确保安装了必要的依赖库和工具。这些准备步骤包括但不限于Python版本的选择、虚拟环境的创建以及特定软件包的安装。 #### 安装依赖项 按照官方文档说明来设置开发环境是非常重要的。通常情况下,建议使用`conda`管理环境以简化依赖关系处理过程[^2]: ```bash conda create -n bev_env python=3.8 conda activate bev_env pip install -r requirements.txt ``` #### 数据集获取预处理 获得适当的数据集对于训练模型至关重要。根据BEVFusion的要求下载所需数据集,并遵循其指定的方式完成数据预处理操作。这可能涉及到将原始传感器读数转化为适合输入给定网络架构的形式,比如通过VoxelNet处理激光雷达点云数据[^1]。 #### 模型构建 理解并实现多模态融合的核心在于掌握不同传感模式间信息交互机制的设计原理。具体来说,在本案例中是指如何有效地将在BEV视角下的图像特征同LiDAR特征相结合。此部分涉及到了解两个主要流程——即从摄像头视频帧提取语义丰富的视觉描述子及其向BEV坐标的映射方法;还有就是怎样利用全卷积神经网络(FCN)达成异构源间的无缝衔接[^3]。 #### 训练评估 一旦完成了上述准备工作,则可以着手于实际的实验环节。调整超参数直至找到最优组合,并定期保存检查点以便后续分析性能表现。此外,还需定义合理的评价指标体系用于衡量最终成果的好坏程度。 #### 调试优化 面对可能出现的各种问题时,耐心细致地排查错误根源所在显得尤为关键。无论是硬件资源不足还是算法逻辑缺陷都可能是造成进度受阻的原因之一。针对这些问题采取有效的解决措施能够显著提升工作效率。
评论 54
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值