MVP复现过程

一、环境基本要求

显卡:4090&2080ti

CUDA=11.1

python=3.8 (不重要,python3.7,python3.9都行)

torch=1.9.0+cu111

torchvision=0.10.0+cu111

spconv=1.2.1

二、相关文件

所有相关的安装文件都放到这里了

链接:https://pan.baidu.com/s/1caBTNRX_VcO6o-xNLCFecg?pwd=6666 

  三、环境搭建

1、配置MVP环境

(1)创建虚拟环境(无需安装包,Anconda自动安装python):

conda create -n MVP python=3.8

(2)激活环境

 conda activate MVP

 (3)安装torch、torchvision

安装说明:推荐本地安装,否则pip会不小心安装成cpu版本。

①下载文件

找到以下文件夹,放着torch、torchvision安装包

②安装

使用pip指令实现本地安装

pip install torch-1.9.0+cu111-cp38-cp38-linux_x86_64.whl torchvision-0.10.0+cu111-cp38-cp38-linux_x86_64.whl

③测试

先输入python进入环境,输入以下指令:

import torch    # 如正常则静默
torch.__version__ #查看torch版本
import torchvision
torchvision.__version__ #查看torchvision版本
torch.cuda.is_available() #正常的话返回“True”
a = torch.Tensor([1.])    # 如正常则静默
a.cuda()    # 如正常则返回"tensor([ 1.], device='cuda:0')"
from torch.backends import cudnn # 如正常则静默
cudnn.is_acceptable(a.cuda())    # 如正常则返回 "True"

显示可以正常使用:

  ④官方下载网站

如果不想用百度云,下面是官方下载网站:

torch下载网站:https://download.pytorch.org/whl/torch_stable.html

 torch 1.9.0+cu111:https://download.pytorch.org/whl/cu111/torch-1.9.0%2Bcu111-cp38-cp38-linux_x86_64.whl

torchvision 0.10.0+cu111:https://download.pytorch.org/whl/cu111/torchvision-0.10.0%2Bcu111-cp38-cp38-linux_x86_64.whl 


 (4)安装spconv-1.2.1

这里只能采用本地安装,因为pip不提供spconv2.0以下的安装方式。

进入到spconv文件夹下,执行:

python setup.py bdist_wheel

cd ./dist && pip install *

注意最后要进入dist文件夹下安装whl文件。

安装完成结果如下:

(5)安装det3d

将det3d-master放在CenterPoint文件夹下

在此之前,请将CenterPoint-master/det3d的文件拷贝到/det3d-master/det3d中进行合并+替换。

​​

在/det3d-master主目录下,执行指令:

安装apex

git clone https://github.com/NVIDIA/apex
cd apex
pip install -v --no-cache-dir --global-option="--cpp_ext" --global-option="--cuda_ext" ./

安装nuscenes-devkit

pip install nuscenes-devkit

 安装第三方库

pip install -r requirements.txt

安装det3d

python setup.py build develop

​​

 (6)安装CenterPoint

进入到CenterPoint主文件夹下:

git clone https://github.com/tianweiy/CenterPoint.git
cd CenterPoint-master

下载第三方库

pip install -r requirements.txt

# add CenterPoint to PYTHONPATH by adding the following line to ~/.bashrc (change the path accordingly)
export PYTHONPATH="${PYTHONPATH}:PATH_TO_CENTERPOINT"
 

安装cuda拓展

首先先将/CenterPoint/det3d/与原来的/det3d-master/det3d合并:

​​

然后执行以下命令: 

export PATH=/usr/local/cuda-10.0/bin:$PATH
export CUDA_PATH=/usr/local/cuda-10.0
export CUDA_HOME=/usr/local/cuda-10.0
export LD_LIBRARY_PATH=/usr/local/cuda-10.0/lib64:$LD_LIBRARY_PATH

# Rotated NMS 
cd ROOT_DIR/det3d/ops/iou3d_nms
python setup.py build_ext --inplace

# Deformable Convolution (Optional and only works with old torch versions e.g. 1.1)
cd ROOT_DIR/det3d/ops/dcn
python setup.py build_ext --inplace

前四句是为了确保cuda环境可以正常调用,后面四句是为了安装NMS和Deformable DETR的cuda版本,这里要根据自己的目录更改ROOT_DIR哦,这里正常来说应该是/CenterPoint/det3d-master/det3d/。

​​

如果期间碰到AT_CHECK的问题,参考我后面写的问题汇总。

 (7)安装detectron2

这里我们根据官方的教程进行安装,并做少量改动:

①pip安装法

以下是cuda11.1的安装指令:

python -m pip install detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cu111/torch1.9/index.html

下面还有其他版本的安装指令:

# CUDA 11.1
python -m pip install detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cu111/torch1.9/index.html

# CUDA 10.2
python -m pip install detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cu102/torch1.9/index.html

# CPU
python -m pip install detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cpu/torch1.9/index.html

②本地安装法

git clone https://github.com/facebookresearch/detectron2.git
python -m pip install -e detectron2

如果上面的指令不能用,那么直接将百度云中的detectron2-main.zip解压到MVP-main/文件夹下,并且更改名字为detectron2。然后进入到detectron2/文件夹下,执行指令:

python setup.py develop

最后说明的一点是,如果能本地安装,还是推荐本地安装,毕竟你要添加或者改什么东西会方便一点。

注:需要将detectron2-main改名为detectron2

③测试

为了测试detectron2是否可用,我们可以从我的百度云上下载相应的测试图片(存放在/data/imgs/,数据节选自Detectron-main),并将其放在/detectron2/demo文件夹下。

执行指令:
 

cd demo/
python demo.py --config-file ../configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml --input 1.jpg   --opts MODEL.WEIGHTS detectron2://COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl

 

(8)安装CenterNet2

CenterNet2也是依赖于detectron2,因此我们可以直接在CenterNet2文件夹下进行测试,无需过多的build或者setup.py。

①安装第三方库

因此,这里我们只需要执行:

pip install -r requirements.txt

安装一下第三方库 。

②建立软连接

根据作者的描述,我们需要将CenterNet2软连接到MVP-main文件夹下,或者我们直接将其拷贝过来也行,文件夹里面没有特别需要build 的文件。

③测试

首先把CenterNet2_R50_1x.pth存入到model/文件夹内。和detectron一样,我们把百度云中/data/imgs/整个文件夹拷贝到CenterNet2/中,执行指令:

python demo.py --config-file configs/CenterNet2_R50_1x.yaml --input imgs/ --opts MODEL.WEIGHTS models/CenterNet2_R50_1x.pth

 最后会检测出多张图片。

④创建根目录环境

因为没有setup,因此需要创建一个根目录环境,以便于MVP能够找到CenterNet2/:

export PYTHONPATH=$PYTHONPATH:/home/xd/xyy/MVP-main/CenterNet2

后面那个改为你的CenterNet2的绝对地址即可。

(9)配置MVP

①生成虚拟点

官方给出了个已经生成好的虚拟点:Sign in to your accounticon-default.png?t=N7T8https://mitprod-my.sharepoint.com/personal/tianweiy_mit_edu/_layouts/15/onedrive.aspx?id=%2Fpersonal%2Ftianweiy_mit_edu%2FDocuments%2FCenterPoint%2FMVP%2Fvirtual_points-001.zip&parent=%2Fpersonal%2Ftianweiy_mit_edu%2FDocuments%2FCenterPoint%2FMVP&ga=1或者我们想用一小部分数据集or其他数据集进行生成,我们可以下载作者已经生成好的pth进行生成,将/centernet_checkpoint.pth放在MVP-main/根目录下,执行以下指令进行生成虚拟点:

python virtual_gen.py --info_path data/nuScenes/infos_train_10sweeps_withvelo_filter_True.pkl  MODEL.WEIGHTS centernet2_checkpoint.pth 

以上我采用nuscenes-mini测试,生成时采用默认参数,显存占用:9G 。


注意:如果在运行过程中出现诸如以下情况:

FileNotFoundError: [Errno 2] No such file or directory: 'data/nuScenes/dbinfos_train_10sweeps_withvelo.pkl'

这是因为作者在代码将lidar_path(也就是nuscenes的位置)切片后再合并时,把最开头的'/'去除了,我们可以进到源代码中在其后面加一行:

 


2、生成数据集

(1)生成

首先将数据集文件整理如下:

# For nuScenes Dataset         
└── NUSCENES_DATASET_ROOT
       ├── samples       <-- key frames
       ├── sweeps        <-- frames without annotation
       ├── maps          <-- unused
       ├── v1.0-trainval <-- metadata

然后在/CenterPoint文件夹下执行指令(注意对应好文件路径): 

# nuScenes
python tools/create_data.py nuscenes_data_prep --root_path=NUSCENES_TRAINVAL_DATASET_ROOT --version="v1.0-trainval" --nsweeps=10

最后生成的文件目录大致如下:

# For nuScenes Dataset 
└── CenterPoint
       └── data    
              └── nuScenes 
                     ├── maps          <-- unused
                     |── v1.0-trainval <-- metadata and annotations
                     |── infos_train_10sweeps_withvelo_filter_True.pkl <-- train annotations
                     |── infos_val_10sweeps_withvelo_filter_True.pkl <-- val annotations
                     |── dbinfos_train_10sweeps_withvelo_virtual.pkl <-- GT database info files
                     |── gt_database_10sweeps_withvelo_virtual <-- GT database 
                     |── samples       <-- key frames
                        |── LIDAR_TOP
                        |── LIDAR_TOP_VIRTUAL
                     └── sweeps       <-- frames without annotation
                        |── LIDAR_TOP
                        |── LIDAR_TOP_VIRTUAL

进入到/nuScenes/LIDAR/如果本次打包完成后就生成了dbinfos_train_10sweeps_withvelo_virtual.pkl,这个名字在后面训练的时候会报错,我们最简单的方法就是将他改名为dbinfos_train_10sweeps_withvelo.pkl。

注:数据集位置尽量不要再次变动 ,否则可能在训练或测试时报错。

(2)创建软连接

可以将提前生成好的数据集软连接到当前文件夹下(注意,如果你的nuScenes数据集就放在当前MVP/data的目录中,直接跳过这一步):

sudo ln -s /media/xd/hpc/data/nuScene-MVP/v1.0-mini/ /home/xd/xyy/MVP-main/CenterPoint/data/nuScenes

3、训练&评估

剩下的就严格按照CenterPoint方法进行执行,这篇文章在测试框架上没做什么改动,就是提前生成好了virtual points。

(1)training

使用以下命令启动使用4个gpu的分布式训练。模型和日志将被保存到“work_dirs/CONFIG_NAME”

python -m torch.distributed.launch --nproc_per_node=4 ./tools/train.py CONFIG_PATH

(2)testing

对于4个gpu的分布式测试,

python -m torch.distributed.launch --nproc_per_node=4 ./tools/dist_test.py CONFIG_PATH --work_dir work_dirs/CONFIG_NAME --checkpoint work_dirs/CONFIG_NAME/latest.pth 

对于使用单个gpu进行测试并查看推断时间,

python ./tools/dist_test.py CONFIG_PATH --work_dir work_dirs/CONFIG_NAME --checkpoint work_dirs/CONFIG_NAME/latest.pth --speed_test 

四、问题汇总

https://blog.csdn.net/weixin_44013732/article/details/133203485icon-default.png?t=N7T8https://blog.csdn.net/weixin_44013732/article/details/133203485

评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值