记一下跑PointRCNN算法+点云可视化的艰难历程……

lzy 4.4K 9
写在前面

环境:Ubuntu18.04,基于Anaconda3
虽然我已经在服务器写过操作日志了,但还是来整理一下过程吧,说不定啥时候就得重新来一遍呢。报错都单独放后边了。

早就装好CUDA9.0.176+CuDNN7.6.4+Anaconda3了(参照下面的文章链接 ),GPU驱动也没有问题,所以这次直接新建环境安装就行了。

RTM3D/KM3D环境配置指南(防踩坑)

2年前 (2022-03-11) 0
RTM3D/KM3D环境配置指南(防踩坑)

跑通PointRCNN

配置环境

新建一个conda虚拟环境,安上pytorch,按理来说不用装cudatoolkit=9.0的,不知道为啥当时装上了。

conda create -n po_lzy python=3.6
conda activate po_lzy
conda install pytorch=1.0 torchvision cudatoolkit=9.0 -c pytorch

clone代码

一定别掉了--recursive

git clone --recursive https://github.com/sshaoshuai/PointRCNN.git

安装工具包

可能下边的这些不太全,缺啥再装上就行,尤其注意numba和pyyaml的版本,其他版本会报错的。其他版本冲突的话pip提示的够详细了。

pip install easydict
pip install tqdm
pip insatll tensorboardX 
pip install fire
pip install numba==0.49.0
pip install pyyaml==5.4.1
pip install scikit-image 
pip install shapely

安装pointnet2_libiou3droipool3d libraries等

cd PointRCNN
sh build_and_install.sh

准备数据

把planes也准备了吧,要不就得改数据增强部分的代码了。

planes下载:

Google Drive

百度云

PointRCNN
├── data
│   ├── KITTI
│   │   ├── ImageSets
│   │   ├── object
│   │   │   ├──training
│   │   │      ├──calib
│   │   │      ├──velodyne
│   │   │      ├──label_2
│   │   │      ├──image_2
│   │   │      ├──planes
│   │   │   ├──testing
│   │   │      ├──calib
│   │   │      ├──velodyne
│   │   │      ├──image_2
├── lib
├── pointnet2_lib
├── tools

Demo Test

下载官方给的预训练模型,放在tools文件夹里。

Google Drive

百度云( 提取码:f7oy)

cd tools
python eval_rcnn.py --cfg_file cfgs/default.yaml --ckpt PointRCNN.pth --batch_size 1 --eval_mode rcnn --set RPN.LOC_XZ_FINE False
# 如果是自己用单个GPU训练的模型的话,最后的--set RPN.LOC_XZ_FINE False不用加。

demo得到的结果跟论文结果基本一致。

记一下跑PointRCNN算法+点云可视化的艰难历程......

自己训练

准备数据:

python generate_gt_database.py --class_name 'Car' --split train

第一阶段——训练RPN:

python train_rcnn.py --cfg_file cfgs/default.yaml --batch_size 16 --train_mode rpn --epochs 200

第二阶段——训练RCNN:

python train_rcnn.py --cfg_file cfgs/default.yaml --batch_size 4 --train_mode rcnn --epochs 70  --ckpt_save_interval 2 --rpn_ckpt ../output/rpn/default/ckpt/checkpoint_epoch_200.pth

点云可视化

使用的工具:kuixu/kitti_object_vis

新建一个conda环境

需要python3.7,当时想的直接新建个环境吧,要是把我的其他环境整坏了可就得不偿失了。

conda create -n vis python=3.7
conda activate vis

按照readme安装工具包

不要从第三方源安装mayavi,否则报错我也没解决。

pip install opencv-python pillow scipy matplotlib
conda install mayavi -c conda-forge

测试是否安装成功

python kitti_object.py --show_lidar_with_depth --img_fov --const_box --vis

大概率会报错,详见后文中《报错与解决》。

成功的话会看到显示出点云和图像。

可视化PointRCNN的结果

PointRCNN/output/rcnn/default/eval/epoch_no_number/val/final_result中找到data文件夹,改名为pred后复制到数据集的training文件夹下。

将数据集软链接到可视化代码的data文件夹中:

ln -s 数据集文件夹 可视化文件夹/data/object

然后可视化:

只显示LiDAR  仅真值

python kitti_object.py --show_lidar_with_depth --img_fov --const_box --vis
# 终端按回车键进行下一张图

显示LiDAR和image  仅真值

python kitti_object.py --show_lidar_with_depth --img_fov --const_box --vis --show_image_with_boxes
# 终端按回车键进行下一张图

显示特定某张图的LiDAR和image 仅真值

python kitti_object.py --show_lidar_with_depth --img_fov --const_box --vis --show_image_with_boxes --ind 100
# ind 100表示就是图像编号为000100.txt

显示pointRCNN预测值+真值对比

# 添加参数-p
python kitti_object.py --show_lidar_with_depth --img_fov --const_box --vis --show_image_with_boxes -p

可视化中红色是预测框,绿色是真值框。

记一下跑PointRCNN算法+点云可视化的艰难历程......

 

报错与解决

cuda.h找不到

# 报错
src/iou3d.cpp:4:18: fatal error: cuda.h: 没有那个文件或目录
compilation terminated.
error: command 'gcc' failed with exit status 1

编译安装iou3d的时候出现的错误,在iou3d的setup.py中:

include_dirs = [os.path.realpath('../include'), '/usr/local/cuda/include/']

include_dirs添加到CUDAExtension中:

CUDAExtension(
            'roi_align.crop_and_resize_gpu',
            ['roi_align/src/crop_and_resize_gpu.cpp',
             'roi_align/src/cuda/crop_and_resize_kernel.cu'],
            include_dirs=include_dirs,
            extra_compile_args={'cxx': ['-g', '-fopenmp'],
                                'nvcc': ['-O2']}
            
        )

nvcc找不到

# 报错
unable to execute ':/usr/local/cuda/bin/nvcc': No such file or directory
error: command ':/usr/local/cuda/bin/nvcc' failed with exit status 1

原因是路径中多了一个冒号!!gedit ~/.bashrc改一下环境变量就好了。

export CUDA_HOME=/usr/local/cuda

gcc版本太高

# 报错
error -- unsupported GNU version! gcc versions later than 6 are not supported!
error: command '/usr/local/cuda/bin/nvcc' failed with exit status 1

我是以前装过gcc-5了,修改一下软链接使用gcc-5/g++-5编译就行了,具体的参照本文开头引用的关于RTM3D环境配置的文章。

CUDA out of memory

这......看自己的硬件了,基本是训练的时候出现的,显存不够用了,nvidia-smi看一下如果是有程序占用GPU的话先taskkill掉吧,如果显存实在不够的话就把batch_size调小一点吧。(我自己的电脑,batch_size调到最小都跑不动Demo哈哈哈哈哈hhhhh....)

size mismatch

eval的时候会遇到,自己训练的模型,eval最后一个参数应该使用默认的True,前文中提到过了。

可视化报错

# 报错
File "/home/lance/anaconda3/envs/vis/lib/python3.7/site-packages/pyface/ui/qt4/dialog.py", line 29, in <module>
    int(QtGui.QDialog.DialogCode.Accepted): OK,
AttributeError: type object 'DialogCode' has no attribute 'Accepted'

google了一下,找到pyface的更新文档看了一下,大概是说pyqt4在新的pyface中被弃用了,所以降个级勉强用一下吧。

参考的文档:Pyface Changelog — pyface 7.4 documentation (enthought.com),重点看Release 7.4.0-->Highlights of this release的最后一段。

pip install pyface==7.3.0
# 然后提示:traitsui 7.3.1 requires pyface>=7.4.1, but you have pyface 7.3.0 which is incompatible.
# 所以降级降级!!!!!!!!!!
pip install traitsui==7.1.0

20221010补充:/usr/bin/gcc failed

服务器cuda版本高,编译cpp代码安装iou3d等libs报这个错,在cpp文件所有#include<>后面添加3行代码即可:

参考:KM3D/RTM3D代码复现_unbekannten的博客-CSDN博客

#ifndef AT_CHECK
#define AT_CHECK TORCH_CHECK 
#endif
发表评论 取消回复
表情 图片 链接 代码

  1. Orange Fish
    Orange Fish Lv 1

    预训练模型的百度云链接失效了,大佬可以重新更新一下吗[aru_12]

    • admin
      admin 站长

      @Orange Fish谢谢提醒,已更新!

      • Orange Fish
        Orange Fish Lv 1

        @admin呜呜呜太及时了十分感谢!!

  2. 鬓霜天涯
    鬓霜天涯 Lv 1

    呜呜呜,大佬解决了我的大问题,谢谢[aru_12]

    • admin
      admin 站长

      @鬓霜天涯哈哈哈我也是新手,刚开始学3D视觉[aru_23]

      • 鬓霜天涯
        鬓霜天涯 Lv 1

        @admin大佬,不嫌弃加我一下好友吧,QQ号167486084@qq.com

        • admin
          admin 站长
          • 鬓霜天涯
            鬓霜天涯 Lv 1

            @admin不好意思大佬,我没收到好友申请,麻烦您再加一下,谢谢

            • admin
              admin 站长

              @鬓霜天涯我这显示等待验证,要不您加我吧。1254674769

分享