3D目标检测算法配置——SA-SSD和spconv配置

目录

  • Dependencies
    • MiniConda
    • spconv 1.0
    • 其他依赖
  • SA-SSD安装
  • 调试记录
    • RuntimeError: result type Byte can't be cast to the desired output type Bool

Dependencies

Github Source

  • python3.5+
  • pytorch (作者用1.1.0,待会我们用1.4.0)
  • opencv
  • shapely
  • mayavi
  • spconv (v1.0, 8da6f967fb9a054d8870c3515b1b44eca2103634)

MiniConda

装过conda或者miniconda可以跳过这一步,最好装在自己目录下的local文件夹,可以参考我装CUDA的博客。

wget -c https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
chmod +x Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh# 记住更新PATH到~/.bashrc时选no

防止conda污染原本的环境,一定一定一定要记住,不要把conda加到环境变量里,2020.12.24安装的时候只有一个地方需要输入(也就是问你要不要加到环境变量里),直接输入no就可以。如果之后我们要启动conda,我们可以用如下命令

source <path_to_your_conda_installation>/bin/activate# 默认进入base
source <path_to_your_conda_installation>/bin/activate <your_env_name># 进入指定环境
# 换源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
conda config --remove channels defaults  # optional, may fix network problem sometimes
conda config --set show_channel_urls yes
conda config --set channel_priority flexible

进入base以后我们就可以正常使用conda list等命令。

spconv 1.0

其中,最难装的就是这个spconv,其他的直接pip install一下就好了。本来我用的是本地CUDA+venv来装环境,结果有很多莫名其妙的BUG,参考MartinHahner的做法配置成功了,我用的是MiniConda,用AnaConda也是OK的(理论上,但是我尝试了下失败了),步骤如下:

下载文件并解压。

conda create --name spconv-1.0 python=3.7 pytorch=1.4 torchvision=0.5 cudatoolkit=10.1 cudatoolkit-dev=10.1 cmake --channel pytorch

conda activate spconv-1.0

conda install cudnn

git clone https://github.com/traveller59/spconv spconv-8da6f9 --recursive

cd spconv-8da6f9

git checkout 8da6f967fb9a054d8870c3515b1b44eca2103634

git am <path_to_hotfixes>/0001-fix-problem-with-torch-1.4.patch

git am <path_to_hotfixes>/0001-Allow-to-specifiy-CUDA_ROOT-directory-and-pick-corre.patch

修改spconv-8da6f9/src/spconv/all.cc,line20

static auto registry =
    torch::jit::RegisterOperators("spconv::get_indice_pairs_2d", &spconv::getIndicePair<2>)
        .op("spconv::get_indice_pairs_3d", &spconv::getIndicePair<3>)
/* 以上是原版 */
/* 由于torch版本更新命名空间,需要把jit删掉,如下 */
static auto registry =
    torch::RegisterOperators("spconv::get_indice_pairs_2d", &spconv::getIndicePair<2>)
        .op("spconv::get_indice_pairs_3d", &spconv::getIndicePair<3>)

接下来进行编译

CUDA_ROOT=<path_to_your_conda_installation>/envs/spconv-1.0 python setup.py bdist_wheel# 如果报错,就pip install wheel

cd dist/

pip install *

Python 3.7.9, cmake version 3.19.1

其他依赖

在同一个虚拟环境里,也就是刚刚创建的spconv-1.0,安装别的依赖。

pip install opencv-python shapely mayavi

# 下面是数据预处理时用到的依赖
pip install numba mmcv==0.4.0 matplotlib pycocotools imageio terminaltables tqdm
# mmcv如果装最新版本会报错,跑tools/test.py的时候,也不能用0.2.0,因为这个版本依赖的pytorch太老了,而pytorch1.4.0更新了属性。
# module 'torch.distributed' has no attribute '_initialized'

SA-SSD安装

git clone https://github.com/skyhehe123/SA-SSD.git
# 编译一些支持库
cd SA-SSD/mmdet/ops/points_op
python3 setup.py build_ext --inplace#可能需要pip install pybind11
cd ../pointnet2
python3 setup.py build_ext --inplace
cd ../iou3d
python3 setup.py build_ext --inplace

添加如下环境变量到~/.bashrc,需要根据自己实际路径修改

export NUMBAPRO_CUDA_DRIVER=<path_to_your_conda_installation>/envs/spconv-1.0/pkgs/cuda-toolkit/lib64/stubs/libcuda.so
export NUMBAPRO_NVVM=<path_to_your_conda_installation>/envs/spconv-1.0/pkgs/cuda-toolkit/nvvm/lib64/libnvvm.so
export NUMBAPRO_LIBDEVICE=<path_to_your_conda_installation>/envs/spconv-1.0/pkgs/cuda-toolkit/nvvm/libdevice
export LD_LIBRARY_PATH=<path_to_your_conda_installation>/envs/spconv-1.0/lib/python3.7/site-packages/spconv# pip show spconv

不要忘了

source ~/.bashrc

还有个很坑的地方就是,ImportError: No module named ‘mmdet’.

import sys
sys.path.append('')
# sys.path.append('/home/haha/local/SA-SSD')
from mmdet.core.bbox3d.geometry import remove_outside_points, points_in_rbbox, box_camera_to_lidar

如果不加path,会提示找不到mmdet这个module。

调试记录

RuntimeError: result type Byte can’t be cast to the desired output type Bool

File "/.../mmdet/models/single_stage_heads/ssd_rotate_head.py", line 365, in get_guided_anchors
    opp_labels = (box_preds[..., -1] > 0) ^ dir_labels.byte()
RuntimeError: result type Byte can't be cast to the desired output type Bool

这个是pytorch的版本问题
修改mmdet/models/single_stage_heads/ssd_rotate_head.py line 365,代码如下:

opp_labels = (box_preds[..., -1] > 0) ^ dir_labels.bool()

你可能感兴趣的:(软件配置,Ubuntu环境配置,spconv,SA-SSD,conda,miniconda,cuda)