前言
本节将对环视车道线MapTR算法进行复现,使用nuscenes-mini数据集!
一、环境配置
1、基础环境:
ubuntu20.04,pytorch1.10.0,python3.8,cuda11.3
2、源码下载
下载地址:
git clone https://github.com/hustvl/MapTR.git
3、环境安装
# 1 下载torch
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 mmcv-full==1.4.0 mmdet==2.14.0 mmsegmentation==0.14.1 timm==0.9.5
# 2 安装mmdetection3d
cd mmdetection3d
export CUDA_HOME=/usr/local/cuda-11.3
pip install -v e .
# 3 其他功能包
cd ./
pip install -r requirement.txt
# 4 安装maptr相关的插件
cd ./projects/mmdet3d_plugin/maptr/modules/ops/geometric_kernel_attn
python setup.py build install
'''
终端显示:Processing dependencies for GeometricKernelAttention==1.0
Finished processing dependencies for GeometricKernelAttention==1.0
'''
# 5 更新networkx,numpy,setuptools版本,2.2在maptr-v2运行时会报错
pip install networkx==2.3 numpy==1.22.2 setuptools==58.2.0
# 6 spconv-cu113可以不安装, 本人没有安装
pip install spconv-cu113 -i https://pypi.tuna.tsinghua.edu.cn/simple
(1)在安装pip install mmcv-full==1.4.0出现以下报错
报错:ap/mmcv-full_aab08f9dc5e94beea857df9c1022f8b4/mmcv/ops/csrc/common -I/root/miniconda3/lib/python3.8/site-packages/torch/include -I/root/miniconda3/lib/python3.8/site-packages/torch/include/torch/csrc/api/include -I/root/miniconda3/lib/python3.8/site-packages/torch/include/TH -I/root/miniconda3/lib/python3.8/site-packages/torch/include/THC -I/root/miniconda3/include/python3.8 -c ./mmcv/ops/csrc/pytorch/assign_score_withk.cpp -o build/temp.linux-x86_64-3.8/./mmcv/ops/csrc/pytorch/assign_score_withk.o -std=c++14 -DTORCH_API_INCLUDE_EXTENSION_H -DPYBIND11_COMPILER_TYPE="_gcc" -DPYBIND11_STDLIB="_libstdcpp" -DPYBIND11_BUILD_ABI="_cxxabi1011" -DTORCH_EXTENSION_NAME=_ext -D_GLIBCXX_USE_CXX11_ABI=0
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
gcc: fatal error: Killed signal terminated program cc1plus
compilation terminated.
error: command 'gcc' failed with exit status 1
----------------------------------------
ERROR: Command errored out with exit status 1: /root/miniconda3/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-p5i_7fap/mmcv-full_aab08f9dc5e94beea857df9c1022f8b4/setup.py'"'"'; __file__='"'"'/tmp/pip-install-p5i_7fap/mmcv-full_aab08f9dc5e94beea857df9c1022f8b4/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-mnfvty4w/install-record.txt --single-version-externally-managed --compile --install-headers /root/miniconda3/include/python3.8/mmcv-full Check the logs for full command output.
解决:
可以把pip安装换成mim安装,先来安装mim
pip install -U openmim
pip install mmcv-full==1.4.0
解决:
4、查看版本号
(1)mmlab相关
pip list | grep mm
( 2)torch相关
pip list | grep torch
二、制作数据集
1、下载can bus
下载地址:nuscenes.org/download
2020 年 2 月,官方发布了 CAN 总线扩展。它包含有关车辆路线、IMU、姿势、转向角反馈、电池、制动器、档位、信号、车轮速度、油门、扭矩、太阳能传感器、里程计等的低级车辆数据。点击US下载:
2、下载nuscenes-mini
文件目录结构如下:
data
├── can_bus
└── nuscenes
├── maps
├── nuscenes_gt_database
├── samples
├── sweeps
└── v1.0-mini
3、生成训练数据集
python tools/create_data.py nuscenes --root-path ./data/nuscenes --out-dir ./data/nuscenes --extra-tag nuscenes --version v1.0-mini --canbus ./data
报错:ModuleNotFoundError: No module named 'tools'
Traceback (most recent call last):
File "tools/create_data.py", line 10, in <module>
from data_converter import indoor_converter as indoor
File "/root/MapTR/tools/data_converter/indoor_converter.py", line 6, in <module>
from tools.data_converter.s3dis_data_utils import S3DISData, S3DISSegData
ModuleNotFoundError: No module named 'tools'
解决:在终端执行
export PYTHONPATH=./
成功运行!
三、训练train
(1)以下两种权重文件皆可使用
mkdir ckpts
cd ckpts
# 1 下载resnet50预训练权重
wget https://download.pytorch.org/models/resnet50-19c8e357.pth
# 2 下载resnet18预训练权重
wget https://download.pytorch.org/models/resnet18-f37072fd.pth
(2)修改projects/configs/maptr/maptr_nano_r18_110e.py
配置文件中相关参数
# 1. 预训练权重
pretrained=dict(img='ckpts/resnet18-f37072fd.pth'),
# 2. BN层修改 单卡BN,多卡用SyncBN
# norm_cfg=dict(type='SyncBN', requires_grad=True), # 多卡BN层
norm_cfg=dict(type='BN', requires_grad=True), # 单卡BN层
# 3. 数据集位置
data_root = 'data/nuscenes/'
# 4. samples_per_gpu和workers_per_gpu
samples_per_gpu=8,
workers_per_gpu=4,
# 训练周期
total_epochs = 100
# 5训练 单卡训练代码最后跟个`1`,八卡最后跟个`8`
./tools/dist_train.sh ./projects/configs/maptr/maptr_nano_r18_110e.py 1
(3)运行train指令
chmod +x ./tools/dist_train.sh
./tools/dist_train.sh ./projects/configs/maptr/maptr_nano_r18_110e.py 1
报错:
TypeError: FormatCode() got an unexpected keyword argument 'verify'
ERROR:torch.distributed.elastic.multiprocessing.api:failed (exitcode: 1) local_rank: 0 (pid: 1401) of binary: /root/miniconda3/bin/python3
解决:
pip install yapf==0.40.1
开始运行: