BEVFormer环境配置及训练

系统:ubuntu20.04  显卡4090

作者说Base 使用 A100*8 大约56个小时

1 拉取源码 github加速代理GitHub Proxy 代理加速

git clone https://github.com/fundamentalvision/BEVFormer.git

2 创建和激活虚拟环境

conda create -n bev python=3.8 -y
conda activate bev

3 安装torch,torchvision,torchaudio

#科学上网
pip install torch==1.10.0+cu113 torchvision==0.11.0+cu113 torchaudio==0.10.0 -f https://download.pytorch.org/whl/torch_stable.html

#或使用镜像
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ torch==1.10.0+cu113 torchvision==0.11.0+cu113 torchaudio==0.10.0 -f https://download.pytorch.org/whl/torch_stable.html

#或使用conda安装(官网查询自己电脑的安装命令)
conda install pytorch==1.10.0 torchvision==0.11.0 torchaudio==0.10.0 cudatoolkit=11.3 -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/linux-64/

4 官网下载nuscenes数据集的mini版 及canbus.zip

5 gcc版本 (可选,我安了)

conda install -c omgarcia gcc-6 # gcc-6.2

6 安装mmopenlib系列

mmcv-full会装很久,因此建议使用mim安装,一定要注意安装顺序,安mmcv-full前确认没有安装mmdet和mmsegmentation,否则会报错

pip install -U openmim
pip install mmcv-full==1.4.0
pip install mmdet==2.14.0
pip install mmsegmentation==0.14.1

7 安装mmdet3d-v0.17.1

#进入bevformer目录

cd BEVformer

#下载mmdetection3d github加速代理https://ghproxy.com/ git clone https://github.com/open-mmlab/mmdetection3d.git

#进入mmdetection3d:

cd mmdetection3d

#切换到v0.17.1

git checkout v0.17.1

#安装mmdet3d-v0.17.1版本,之前使用ubuntu22.04在同样的python、torch、cuda版本下,这步未安装成功

python setup.py install

8 安装 Detectron2 and Timm

#8.1 安装基本python依赖包

pip install einops fvcore seaborn iopath==0.1.9 timm==0.6.13 typing-extensions==4.5.0 pylint ipython==8.12 numpy==1.19.5 matplotlib==3.5.2 numba==0.48.0 pandas==1.4.4 scikit-image==0.19.3 setuptools==59.5.0 yapf==0.40.1

#8.2 安装 Detectron2

python -m pip install 'git+https://github.com/facebookresearch/detectron2.git'

9 下载预训练模型

#创建并进入ckpts文件夹

#进入bevformer目录后
mkdir ckpts
cd ckpts

#下载预训练权重r101_dcn_fcos3d_pretrain.pth,github加速代理https://ghproxy.com/ wget https://github.com/zhiqi-li/storage/releases/download/v1.0/r101_dcn_fcos3d_pretrain.pth

10.准备和处理数据集

# data文件夹展开结构,can_bus内容太多,这就不展开

# 1 mini数据集训练

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

# 2 full数据集 可以将v1.0-mini复制一份命名v1.0-trainval

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

运行上面代码后会在 data/nuscenes/目录下生成2个 pkl 和 2 个 json 文件。

11.训练:

修改配置文件

#训练前,修改配置文件./projects/configs/bevformer/bevformer_base.py参数, 主要下面4个参数: max_epoch=2

sample_per_gpu=1

worker_per_gpu=0

(显存48g设置为2时就爆内存了,设置为2需要57g,至少显存30g朝上) #命令行进入bevformerb,输入训练命令,最后一个参数是显卡个数, 只有一张显卡写1,8张写8

./tools/dist_train.sh ./projects/configs/bevformer/bevformer_base.py 1 ./tools/dist_train.sh ./projects/configs/bevformer/bevformer_small.py 1

使用bevformer_small.py训练过程:

12.测试评估

#使用base预训练模型

./tools/dist_test.sh ./projects/configs/bevformer/bevformer_base.py ckpts/bevformer_r101_dcn_24ep.pth 1

#使用tiny预训练模型

./tools/dist_test.sh ./projects/configs/bevformer/bevformer_tiny.py ckpts/bevformer_tiny_epoch_24.pth 1

#使用自己训练出来的模型权重

./tools/dist_test.sh ./projects/configs/bevformer/bevformer_tiny.py ckpts/latest.pth 1

13.报错修改:

1.distrbuted相关:

解决方法:修改分布式训练模式为单一GPU训练

进入bevformer/mmdetection3d/tools/test.py

去掉注释部分的#

#在else:后添加:

find_unused_parameters = True

  • 47
    点赞
  • 56
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
BEVFormer是一种纯视觉的自动驾驶感知算法。它通过融合环视相机图像的空间和时序特征来生成具有强表征能力的BEV(Bird's Eye View)特征,并应用于下游的3D检测、分割等任务,取得了SOTA(State-of-the-Art)的结果。在BEVFormer算法的部署中,主要包括以下几个部分。 首先是backbone,用于从6个角度的环视图像中提取多尺度的multi-camera feature。这个过程主要通过对多个相机的内外参信息进行特征提取,以获得统一的BEV视角的multi-camera feature。 其次是BEV encoder,该模块主要包括Temporal self-Attention和Spatial Cross-Attention两个部分。Spatial Cross-Attention结合多个相机的内外参信息对对应位置的multi-camera feature进行query,从而在统一的BEV视角下将multi-camera feature进行融合。Temporal self-Attention将History BEV feature和current BEV feature通过self-attention module进行融合,以获取具有时序信息的BEV feature。 最后是Det&Seg Head,这是针对特定任务的task head。它进一步使用BEV feature进行3D检测和分割任务。 在BEVFormer的部署中,我们还对训练代码进行了优化,包括数据读取和减少内存拷贝消耗等方面的优化。此外,我们还使用了推理优化工具PAI-Blade对模型进行了优化,以提高推理速度。通过PAI-Blade优化后的模型,在A100机器下能够获得42%的优化加速。 总而言之,BEVFormer的部署主要包括backbone、BEV encoder和Det&Seg Head三个部分,并通过优化训练代码和使用推理优化工具来提高算法的训练速度和推理速度。
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值