本文介紹如何搭建3D目標(biāo)檢測框架,使用docker快速搭建MMDetection3D的開發(fā)環(huán)境,實(shí)現(xiàn)視覺3D目標(biāo)檢測、點(diǎn)云3D目標(biāo)檢測、多模態(tài)3D目標(biāo)檢測等等。
需要大家提前安裝好docker,并且docker版本>= 19.03。
1、下載MMDetection3D源碼
https://github.com/open-mmlab/mmdetection3d
?git clone https://github.com/open-mmlab/mmdetection3d.git
主要特性
-
支持多模態(tài)/單模態(tài)的檢測器
支持多模態(tài)/單模態(tài)檢測器,包括 MVXNet,VoteNet,PointPillars 等。
-
支持戶內(nèi)/戶外的數(shù)據(jù)集
支持室內(nèi)/室外的 3D 檢測數(shù)據(jù)集,包括 ScanNet,SUNRGB-D,Waymo,nuScenes,Lyft,KITTI。對于 nuScenes 數(shù)據(jù)集,我們也支持?nuImages 數(shù)據(jù)集。
-
與 2D 檢測器的自然整合
MMDetection?支持的?300+ 個(gè)模型,40+ 的論文算法,和相關(guān)模塊都可以在此代碼庫中訓(xùn)練或使用。
模塊組件
主干網(wǎng)絡(luò) | 檢測頭 | 特性 |
|
|
|
算法模型
激光雷達(dá) 3D 目標(biāo)檢測 | 相機(jī) 3D 目標(biāo)檢測 | 多模態(tài) 3D 目標(biāo)檢測 | 3D 語義分割 |
|
|
|
|
2、獲取MMDetection3D鏡像
我們先看看mmdetection3d-main/docker/Dockerfile文件,用來構(gòu)建docker鏡像的
ARG PYTORCH="1.9.0"
ARG CUDA="11.1"
ARG CUDNN="8"
FROM pytorch/pytorch:${PYTORCH}-cuda${CUDA}-cudnn${CUDNN}-devel
ENV TORCH_CUDA_ARCH_LIST="6.0 6.1 7.0 7.5 8.0 8.6+PTX" \
TORCH_NVCC_FLAGS="-Xfatbin -compress-all" \
CMAKE_PREFIX_PATH="$(dirname $(which conda))/../" \
FORCE_CUDA="1"
# Avoid Public GPG key error
# https://github.com/NVIDIA/nvidia-docker/issues/1631
RUN rm /etc/apt/sources.list.d/cuda.list \
&& rm /etc/apt/sources.list.d/nvidia-ml.list \
&& apt-key del 7fa2af80 \
&& apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/3bf863cc.pub \
&& apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/7fa2af80.pub
# (Optional, use Mirror to speed up downloads)
# RUN sed -i 's/http:\/\/archive.ubuntu.com\/ubuntu\//http:\/\/mirrors.aliyun.com\/ubuntu\//g' /etc/apt/sources.list && \
# pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
# Install the required packages
RUN apt-get update \
&& apt-get install -y ffmpeg libsm6 libxext6 git ninja-build libglib2.0-0 libsm6 libxrender-dev libxext6 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Install MMEngine, MMCV and MMDetection
RUN pip install openmim && \
mim install "mmengine" "mmcv>=2.0.0rc4" "mmdet>=3.0.0"
# Install MMDetection3D
RUN conda clean --all \
&& git clone https://github.com/open-mmlab/mmdetection3d.git -b dev-1.x /mmdetection3d \
&& cd /mmdetection3d \
&& pip install --no-cache-dir -e .
WORKDIR /mmdetection3d
這里有ARG PYTORCH="1.9.0"、ARG CUDA="11.1"、ARG CUDNN="8"這些關(guān)鍵參數(shù),可以根據(jù)需求修改
然后執(zhí)行命令:docker build -t mmdetection3d docker/
拉取docker鏡像會比較慢,如果大家也是這個(gè)版本的,可以放到網(wǎng)盤,分享給大家
等待構(gòu)建完成:
用命令docker images查看鏡像信息,能看到mmdetection3d鏡像:
3、使用MMDetection3D鏡像
打開鏡像:方式一(常規(guī)模式--支持使用GPU)
docker run --gpus all -it mmdetection3d:latest /bin/bash
打開鏡像:方式二(增強(qiáng)模式--支持使用GPU、映射目錄、設(shè)置內(nèi)存)
docker run -i -t -v /home/liguopu/:/guopu:rw --gpus all --shm-size 16G mmdetection3d:latest /bin/bash
平常進(jìn)入了docker環(huán)境,然后創(chuàng)建或產(chǎn)生的文件,在退出docker環(huán)境后會“自動(dòng)銷毀”;或者想運(yùn)行本地主機(jī)的某個(gè)程序,發(fā)現(xiàn)在docker環(huán)境中找不到。
我們可以通過映射目錄的方式,把本地主機(jī)的某個(gè)目錄,映射到docker環(huán)境中,這樣產(chǎn)生的文件會保留在本地主機(jī)中。
通過-v 把本地主機(jī)目錄 /home/liguopu/ 映射到docker環(huán)境中的/guopu 目錄;其權(quán)限是rw,即能讀能寫。
默認(rèn)分配很小的內(nèi)參,在訓(xùn)練模型時(shí)不夠用,可以通過參數(shù)設(shè)置:比如,我電腦有32G內(nèi)參,想放16G到docker中使用,設(shè)置為 --shm-size 16G。
?
4、測試MMDetection3D開放環(huán)境
驗(yàn)證安裝是否成功,在終端先輸入python,然后輸入以下代碼打印版本號
import mmdet3d
print(mmdet3d.__version__)
效果如下:
測試一下模型推理
?我們需要下載配置文件和模型權(quán)重文件。
mim download mmdet3d --config pointpillars_hv_secfpn_8xb6-160e_kitti-3d-car --dest .
下載將需要幾秒鐘或更長時(shí)間,這取決于的網(wǎng)絡(luò)環(huán)境。
完成后會在當(dāng)前文件夾中發(fā)現(xiàn)兩個(gè)文件
-
pointpillars_hv_secfpn_8xb6-160e_kitti-3d-car.py
? hv_pointpillars_secfpn_6x8_160e_kitti-3d-car_20220331_134606-d42d15ed.pth
寫一個(gè)代碼如下:
from mmdet3d.apis import init_model, inference_detector
config_file = 'pointpillars_hv_secfpn_8xb6-160e_kitti-3d-car.py'
checkpoint_file = 'hv_pointpillars_secfpn_6x8_160e_kitti-3d-car_20220331_134606-d42d15ed.pth'
model = init_model(config_file, checkpoint_file)
output = inference_detector(model, 'demo/data/kitti/000008.bin')
print("inference_detector output:", output)
print("ok !!!")
能看到模型成功推理,并輸出結(jié)果信息:
文章來源:http://www.zghlxwxcb.cn/news/detail-719549.html
分享完成啦~文章來源地址http://www.zghlxwxcb.cn/news/detail-719549.html
到了這里,關(guān)于3D目標(biāo)檢測框架 MMDetection3D環(huán)境搭建 docker篇的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!