StreamPETR
StreamPETR一种使用query实现多帧object-centric的时序融合策略3D物体检测器.
- 更多bev算法部署参考
- 如果您觉得本帖对您有帮助,感谢您一键三连支持一波
^_^
1 环境配置
- ubuntu20.04, cuda-11.3, torch-1.11.0,mmcv-full==1.6.0,mmdetection3d-1.0.0rc6 不想折腾的伙伴请直接抄作业, 请全抄,别只抄半路_
- CUDA安装参考
1.1 python环境构建
mmcv-cu113-torch1.11.0-whl下载地址
# 1.1 创建虚拟环境
conda create -n streampetr python=3.8
# 1.2 激活虚拟环境
conda activate streampetr
# 1.3 安装torch
pip install torch==1.11.0+cu113 torchvision==0.12.0+cu113 torchaudio==0.11.0 --extra-index-url https://download.pytorch.org/whl/cu113
# 1.4 安装mmcv-full相关 推荐使用上面的whl地址或者mim安装方式
## 1.4.1 下载whl后进行离线安装
## 注意下载whl时cuda版本, torch版本,python版本要对应上!!! 切记 切记 切记
pip install mmcv_full-1.6.0-cp38-cp38-manylinux1_x86_64.whl
## 1.4.2 或者在线安装,速度慢,可以加-v参数打印log,就不会觉得终端是卡住了
pip install mmcv-full==1.6.0 -v
## 1.4.3 或者使用openmim安装也可, 比pip安装mmcv要快
pip install openmim
mim install mmcv-full==1.6.0 -v
## 1.4.4 安装mmdet和mmsegmentation, 使用mim和pip都可
mim install mmdet==2.28.2 mmsegmentation==0.30.0
# 1.5 安装mmdetection3d-v1.0.0rc6版本, 作者用的这个版本
git clone https://github.com/open-mmlab/mmdetection3d.git -b v1.0.0rc6
cd mmdetection3d
pip install -v -e .
# 1.6 安装flash_attn 推荐使用上面的whl地址,
## 1.6.1 下载whl后进行离线安装
pip install flash_attn-0.2.2+cu113torch1.11.0-cp38-cp38-linux_x86_64.whl
## 1.6.2 或者可直接在线安装,只是速度非常慢,
## 可加-v参数, 打印安装过程的log, 有打印就不会觉得终端是卡住了, 如下
pip install flash_attn==0.2.2 -v
# 1.7 更新numpy和yapf版本
pip install IPython einops numpy==1.23.4 yapf==0.40.1
# 1.8 库版本查看
## 1.8.1 torch相关库版本
pip list | grep torch
torch 1.11.0+cu113
torchaudio 0.11.0
torchvision 0.12.0+cu113
## 1.8.2 mmopenlab相关库版本
pip list | grep mm
# 显示如下:
mmcls 0.25.0
mmcv-full 1.6.0
mmdet 2.28.2
mmdet3d 1.0.0rc6 /root/share/code/StreamPETR/mmdetection3d
mmsegmentation 0.30.0
1.2 报错汇总
# 错误1
...
from numba.np.ufunc import _internal
SystemError: initialization of _internal failed without raising an exception
# 修改方法: 降低numpy版本即可
pip install numpy==1.23.4
# 错误2
ModuleNotFoundError: No module named 'spconv'
# 修改方法 需要跟cuda配置上, 本人是cuda-11.3, 安装版本如下
pip install spconv-cu113
# 错误3
ModuleNotFoundError: No module named 'IPython'
# 修改方法
pip install IPython
# 错误4
# 情况1:No module named 'projects.mmdet3d_plugin'
# 情况2:ModuleNotFoundError: No module named 'tools'
# 情况3: ModuleNotFoundError: No module named 'tools.data_converter'
# 情况4:ModuleNotFoundError: No module named 'projects'`
# 因为tools、projects、projects.mmdet3d_plugin都是从本地导入模块,
# 导入失败要么是python环境变量没生效, 要么是模块的路径不对
# 修改办法: 更新python-path环境即可, 当前python虚拟环境的终端执行下面语句
export PYTHONPATH=$PYTHONPATH:"./"
# 如果还报错检查这句代码的路径是否正确, 可是使用绝对路径代替
# 错误5
TypeError: FormatCode() got an unexpected keyword argument 'verify'
# 修改办法: 降低yapf版本
pip install yapf==0.40.1
# 错误6
ImportError: libcudart.so.11.0: cannot open shared object file: No such file or directory
# 原因: 安装的mmcv与cuda版本没对用上,建议去whl官方下载离线安装
# 修改参考1.4.1安装mmcv-full教程
# 错误7
# AttributeError: module 'distutils' has no attribute 'version'
修改:更新setuptools版本
pip install setuptools==58.4.0
# 错误8
# docker里面提示libGL.so.1不存在
ImportError: libGL.so.1: cannot open shared object file: No such file or directory
# 修改方法:安装ffmpeg即可
apt-get install ffmpeg -y
# 错误9 pip安装mmcv-full时报错
subprocess.CalledProcessError: Command '['which', 'g++']' returned non-zero exit status 1.
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for mmcv-full
# 修改方法:由于g++,gcc工具没安装,安装build-essential即可
sudo apt-get install build-essential
# 错误10 训练时显存爆炸 RuntimeError: CUDA out of memory
# 修改:先将配置文件中samples_per_gpu改为1即可workers_per_gpu改0测试环境,
# 后期正式训练时逐渐增加这2个参数的数字, 直到显存占满
# 如果设置成1和0都显存不够, 可以更换显卡了
samples_per_gpu=1, workers_per_gpu=0
- 运行报错先看1.2节
2 nuscenes数据集生成
nuscenes-mini数据集下载
下载参考Fast-BEV代码复现实践第2.1节下载数据集篇
- nuscenes-mini百度网盘下载地址 提取码: v3cv
# 2.1 nus-mini数据集生成
python tools/create_data_nusc.py --root-path ./data/nuscenes --out-dir ./data/nuscenes --extra-tag nuscenes2d --version v1.0-mini
# 2.2 nus-full
python tools/create_data_nusc.py --root-path ./data/nuscenes --out-dir ./data/nuscenes --extra-tag nuscenes2d --version v1.0
# 2.3 结果保存
# 本人使用的nuscenes-mini数据集, 执行2.1语句,
# 在data/nuscenes生成了nuscenes2d_temporal_infos_train.pkl与nuscenes2d_temporal_infos_val.pkl两个文件
3 训练
## 3.1 单步训练
python tools/train.py projects/configs/StreamPETR/stream_petr_r50_flash_704_bs2_seq_24e.py --work-dir work_dirs/run1/
## 3.2 多卡训练
tools/dist_train.sh projects/configs/StreamPETR/stream_petr_r50_flash_704_bs2_seq_24e.py 8 --work-dir work_dirs/run1/
## 3.3 训练结果
# 会在该工程目录下自动生成work_dirs文件夹, 训练结果保存在work_dirs文件夹下
4 测试评估
# "--out", "--eval", "--format-only", "--show" or "--show-dir" 具体参数细节可以参考test.py的参数加载函数, 有英文注释
## 4.1 单步运行, 需要将if not distributed这句下面的函数改成如下所示:
if not distributed:
# assert False
model = MMDataParallel(model, device_ids=[0])
outputs = single_gpu_test(model, data_loader, args.show, args.show_dir)
## 运行test.py
python tools/test.py work_dirs/run1/stream_petr_r50_flash_704_bs2_seq_24e.py work_dirs/run1/latest.pth --eval bbox
## 4.2 分布式运行 上面的单步运行貌似不会保存文件
tools/dist_test.sh work_dirs/run1/stream_petr_r50_flash_704_bs2_seq_24e.py work_dirs/run1/latest.pth 1 --eval bbox
## 4.3 测试官方readme提供的权重和配置文件进行测试, 数据集太少自己训练的没效果
python tools/test.py projects/configs/StreamPETR/test.py ckpts/stream_petr_r50_flash_704_bs2_seq_428q_nui_60e.pth --eval bbox
## 4.4 test结果
# 会在该工程目录下自动生成test文件夹, 结果保存在test文件夹下
# test文件夹下的results_nusc.json文件就是可视化需要的文本
5 vis可视化
# 修改visualize.py的result_json路径
# 由于是用的nus-mini训练, version = "v1.0-trainval" 改成 version = "v1.0-mini"
result_json = "test/test/Thu_Jan__4_06_31_19_2024/pts_bbox/results_nusc"
version = "v1.0-mini"
## 5.1 运行visualize.py
python3 tools/visualize.py
## 5.2 可视化结果
# 会在该工程目录下自动生成result_vis文件夹, 可视化图像结果保存在result_vis文件夹下
- 可视化结果如下: