国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

【MMDetection3D】環(huán)境搭建,使用PointPillers訓(xùn)練&測試&可視化KITTI數(shù)據(jù)集

這篇具有很好參考價值的文章主要介紹了【MMDetection3D】環(huán)境搭建,使用PointPillers訓(xùn)練&測試&可視化KITTI數(shù)據(jù)集。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報違法"按鈕提交疑問。

前言

2D卷不動了,來卷3D,之后更多地工作會放到3D檢測上

本文將簡單介紹什么是3D目標(biāo)檢測、KITTI數(shù)據(jù)集以及MMDetection3D算法庫,重點(diǎn)介紹如何在MMDetection3D中,使用PointPillars算法訓(xùn)練KITTI數(shù)據(jù)集,并對結(jié)果進(jìn)行測試和可視化。

?

3D目標(biāo)檢測概述

對于一張輸入圖像,2D目標(biāo)檢測旨在給出物體類別并標(biāo)出物體位置,而3D目標(biāo)檢測則要給出物體的位置(x, y, z)、尺寸(x_size, y_size, z_size)以及大致方向(框的朝向角),檢測結(jié)果的示意圖如下所示:
kitti立體匹配數(shù)據(jù)集如何測試,3D目標(biāo)檢測,目標(biāo)檢測,計算機(jī)視覺,3D目標(biāo)檢測

與2D目標(biāo)檢測相比,3D檢測要處理更加多元的數(shù)據(jù)類型,得到更復(fù)雜的目標(biāo)檢測結(jié)果:

2D檢測 3D檢測
輸入數(shù)據(jù) 圖片 點(diǎn)云(LiDAR)、圖片(Camera)、多模態(tài)(點(diǎn)云+圖片)
輸出結(jié)果 4-DoF(矩形框+分類) 7-DoF(位置、尺寸、朝向角)、9-DoF(位置、尺寸、3個方向角)
評估標(biāo)準(zhǔn) IOU、mAP 3D-IoU-based or center-distance-based mAP

?

KITTI數(shù)據(jù)集簡介

KITTI官網(wǎng):The KITTI Vision Benchmark Suite
相關(guān)論文1:Vision meets Robotics: The KITTI Dataset

相關(guān)論文2:Are we ready for Autonomous Driving? The KITTI Vision Benchmark Suite

KITTI數(shù)據(jù)集由德國卡爾斯魯厄理工學(xué)院和豐田美國技術(shù)研究院聯(lián)合創(chuàng)辦,是目前國際上最大的自動駕駛場景下的計算機(jī)視覺算法評測數(shù)據(jù)集。作者收集了長達(dá)6個小時的真實(shí)交通環(huán)境,數(shù)據(jù)集由經(jīng)過校正和同步的圖像、雷達(dá)掃描、高精度的GPS信息和IMU加速信息等多種模態(tài)的信息組成。該數(shù)據(jù)集用于評測立體圖像(stereo),光流(optical flow),視覺測距(visual odometry),3D物體檢測(object detection)和3D跟蹤(tracking)等計算機(jī)視覺技術(shù)在車載環(huán)境下的性能。

場景:Road、City、Residential、Campus、Person

類別:Car、Van、Truck、Pedestrian、Person_sitting、Cyclist、Tram、Misc、DontCare,其中DontCare標(biāo)簽表示該區(qū)域沒有被標(biāo)注

3D目標(biāo)檢測數(shù)據(jù)集由7481個訓(xùn)練圖像和7518個測試圖像以及相應(yīng)的點(diǎn)云數(shù)據(jù)組成,包括總共80256個標(biāo)記對象。具體來看,下圖藍(lán)色框標(biāo)記的為我們需要的數(shù)據(jù),分別是

  1. 彩色圖像數(shù)據(jù)(12GB)
  2. 點(diǎn)云數(shù)據(jù)(29GB)
  3. 相機(jī)矯正數(shù)據(jù)(16MB)
  4. 標(biāo)簽數(shù)據(jù)(5MB)

其中彩色圖像數(shù)據(jù)、點(diǎn)云數(shù)據(jù)、相機(jī)矯正數(shù)據(jù)均包含training(7481)和testing(7518)兩個部分,標(biāo)簽數(shù)據(jù)只有training部分。

kitti立體匹配數(shù)據(jù)集如何測試,3D目標(biāo)檢測,目標(biāo)檢測,計算機(jī)視覺,3D目標(biāo)檢測
?

MMDetection3D

MMDetection3D 是一個基于 PyTorch 的目標(biāo)檢測開源工具箱,面向3D檢測的平臺,是 OpenMMlab 項(xiàng)目的一部分(由香港中文大學(xué)多媒體實(shí)驗(yàn)室和商湯科技聯(lián)合發(fā)起)。對MMDet3D的配置文件不熟悉的小伙伴可以移步至:教程 1: 學(xué)習(xí)配置文件,本文使用版本為: Release V1.1.0rc0,下面,讓我們玩耍起來?。?!
?

環(huán)境搭建

這里直接放上官網(wǎng)文檔中的安裝腳本,言簡意賅,適合無腦follow~

# 在Anaconda中新建虛擬環(huán)境
conda create -n mmdet3d python=3.7 -y
conda activate mmdet3d

# 安裝最新的PyTorch版本
conda install -c pytorch pytorch torchvision -y

# install mmcv
pip install mmcv-full

# install mmdetection
pip install git+https://github.com/open-mmlab/mmdetection.git

# install mmsegmentation
pip install git+https://github.com/open-mmlab/mmsegmentation.git

# install mmdetection3d
git clone https://github.com/open-mmlab/mmdetection3d.git
cd mmdetection3d
pip install -v -e . # or "python setup.py develop"
# -v:verbose, or more output
# -e:editable,修改本地文件,調(diào)用的模塊以最新文件為準(zhǔn)

?

數(shù)據(jù)集準(zhǔn)備

直接參考官網(wǎng)提供的下載-預(yù)處理-訓(xùn)練-測試一條龍服務(wù):3D 目標(biāo)檢測 KITTI 數(shù)據(jù)集

在官網(wǎng)下載 KITTI 3D 檢測數(shù)據(jù)并解壓縮所有 zip 文件,并將數(shù)據(jù)集根目錄鏈接到 ./mmdetection3d/data/,在預(yù)處理數(shù)據(jù)之前,數(shù)據(jù)集結(jié)構(gòu)組織方式如下:

mmdetection3d
├── mmdet3d
├── tools
├── configs
├── data
│   ├── kitti
│   │   ├── ImageSets
│   │   ├── testing
│   │   │   ├── calib
│   │   │   ├── image_2
│   │   │   ├── velodyne
│   │   ├── training
│   │   │   ├── calib
│   │   │   ├── image_2
│   │   │   ├── label_2
│   │   │   ├── velodyne
│   │   │   ├── planes (optional)

下面開始創(chuàng)建 KITTI 點(diǎn)云數(shù)據(jù),首先需要加載原始的點(diǎn)云數(shù)據(jù)并生成相關(guān)的包含目標(biāo)標(biāo)簽和標(biāo)注框的數(shù)據(jù)標(biāo)注文件,同時還需要為 KITTI 數(shù)據(jù)集生成每個單獨(dú)的訓(xùn)練目標(biāo)的點(diǎn)云數(shù)據(jù),并將其存儲在 data/kitti/kitti_gt_database 的 .bin 格式的文件中,此外,需要為訓(xùn)練數(shù)據(jù)或者驗(yàn)證數(shù)據(jù)生成 .pkl 格式的包含數(shù)據(jù)信息的文件。

通過運(yùn)行下面的命令來創(chuàng)建最終的 KITTI 數(shù)據(jù):

# 進(jìn)入mmdetection3d主目錄
cd mmdetection3d
# 創(chuàng)建文件夾
mkdir ./data/kitti/ && mkdir ./data/kitti/ImageSets

# Download data split
wget -c  https://raw.githubusercontent.com/traveller59/second.pytorch/master/second/data/ImageSets/test.txt --no-check-certificate --content-disposition -O ./data/kitti/ImageSets/test.txt
wget -c  https://raw.githubusercontent.com/traveller59/second.pytorch/master/second/data/ImageSets/train.txt --no-check-certificate --content-disposition -O ./data/kitti/ImageSets/train.txt
wget -c  https://raw.githubusercontent.com/traveller59/second.pytorch/master/second/data/ImageSets/val.txt --no-check-certificate --content-disposition -O ./data/kitti/ImageSets/val.txt
wget -c  https://raw.githubusercontent.com/traveller59/second.pytorch/master/second/data/ImageSets/trainval.txt --no-check-certificate --content-disposition -O ./data/kitti/ImageSets/trainval.txt

python tools/create_data.py kitti --root-path ./data/kitti --out-dir ./data/kitti --extra-tag kitti --with-plane

處理完成之后的目錄如下:

kitti
├── ImageSets
│   ├── test.txt
│   ├── train.txt
│   ├── trainval.txt
│   ├── val.txt
├── testing
│   ├── calib
│   ├── image_2
│   ├── velodyne
│   ├── velodyne_reduced
├── training
│   ├── calib
│   ├── image_2
│   ├── label_2
│   ├── velodyne
│   ├── velodyne_reduced
│   ├── planes (optional)
├── kitti_gt_database
│   ├── xxxxx.bin
├── kitti_infos_train.pkl
├── kitti_infos_val.pkl
├── kitti_dbinfos_train.pkl
├── kitti_infos_test.pkl
├── kitti_infos_trainval.pkl
├── kitti_infos_train_mono3d.coco.json
├── kitti_infos_trainval_mono3d.coco.json
├── kitti_infos_test_mono3d.coco.json
├── kitti_infos_val_mono3d.coco.json

?

訓(xùn)練

數(shù)據(jù)集和環(huán)境都配置好后,就可以開始訓(xùn)練,使用命令python tools/train.py -h查看有哪些訓(xùn)練參數(shù):

(mmdet3d) xxx@xxx:~/det3d/mmdetection3d$ python tools/train.py -h
usage: train.py [-h] [--work-dir WORK_DIR] [--resume-from RESUME_FROM]
                [--auto-resume] [--no-validate]
                [--gpus GPUS | --gpu-ids GPU_IDS [GPU_IDS ...] | --gpu-id
                GPU_ID] [--seed SEED] [--diff-seed] [--deterministic]
                [--options OPTIONS [OPTIONS ...]]
                [--cfg-options CFG_OPTIONS [CFG_OPTIONS ...]]
                [--launcher {none,pytorch,slurm,mpi}]
                [--local_rank LOCAL_RANK] [--autoscale-lr]
                config

Train a detector

positional arguments:
  config                train config file path

optional arguments:
  -h, --help            show this help message and exit
  --work-dir WORK_DIR   the dir to save logs and models
  --resume-from RESUME_FROM
                        the checkpoint file to resume from
  --auto-resume         resume from the latest checkpoint automatically
  --no-validate         whether not to evaluate the checkpoint during training
  --gpus GPUS           (Deprecated, please use --gpu-id) number of gpus to
                        use (only applicable to non-distributed training)
  --gpu-ids GPU_IDS [GPU_IDS ...]
                        (Deprecated, please use --gpu-id) ids of gpus to use
                        (only applicable to non-distributed training)
  --gpu-id GPU_ID       number of gpus to use (only applicable to non-
                        distributed training)
  --seed SEED           random seed
  --diff-seed           Whether or not set different seeds for different ranks
  --deterministic       whether to set deterministic options for CUDNN
                        backend.
  --options OPTIONS [OPTIONS ...]
                        override some settings in the used config, the key-
                        value pair in xxx=yyy format will be merged into
                        config file (deprecate), change to --cfg-options
                        instead.
  --cfg-options CFG_OPTIONS [CFG_OPTIONS ...]
                        override some settings in the used config, the key-
                        value pair in xxx=yyy format will be merged into
                        config file. If the value to be overwritten is a list,
                        it should be like key="[a,b]" or key=a,b It also
                        allows nested list/tuple values, e.g.
                        key="[(a,b),(c,d)]" Note that the quotation marks are
                        necessary and that no white space is allowed.
  --launcher {none,pytorch,slurm,mpi}
                        job launcher
  --local_rank LOCAL_RANK
  --autoscale-lr        automatically scale lr with the number of gpus

幾個關(guān)鍵參數(shù):

  • configs:必選參數(shù),訓(xùn)練模型的參數(shù)配置文件
  • work-dir:可選參數(shù),訓(xùn)練日志及權(quán)重文件保存文件夾,默認(rèn)會新建work-dirs文件夾,并保存在以configs文件名命名的文件夾中
  • gpu-id:使用的GPU個數(shù)

上述參數(shù)我們可以在命令行執(zhí)行訓(xùn)練命令時,直接進(jìn)行修改,但有些參數(shù)需要我們進(jìn)入模型配置文件進(jìn)行修改,這里以hv_pointpillars_secfpn_6x8_160e_kitti-3d-3class配置文件為例:

  • 修改訓(xùn)練Epoch數(shù):打開/mmdetection3d/configs/pointpillars/hv_pointpillars_secfpn_6x8_160e_kitti-3d-3class.py文件,修改runner = dict(max_epochs=160)中的max_epochs參數(shù)
kitti立體匹配數(shù)據(jù)集如何測試,3D目標(biāo)檢測,目標(biāo)檢測,計算機(jī)視覺,3D目標(biāo)檢測
  • 修改batch-size:打開/mmdetection3d/configs/_base_/datasets/kitti-3d-3class.py文件,修改samples_per_gpu參數(shù)
kitti立體匹配數(shù)據(jù)集如何測試,3D目標(biāo)檢測,目標(biāo)檢測,計算機(jī)視覺,3D目標(biāo)檢測

設(shè)置好參數(shù)后,我們就可以直接執(zhí)行命令進(jìn)行訓(xùn)練了:

單GPU訓(xùn)練

python tools/train.py configs/pointpillars/hv_pointpillars_secfpn_6x8_160e_kitti-3d-3class.py

多GPU訓(xùn)練

CUDA_VISIBLE_DEVICES=0,1,2,3 tools/dist_train.sh configs/pointpillars/hv_pointpillars_secfpn_6x8_160e_kitti-3d-3class.py 4

訓(xùn)練結(jié)束后,我們可以在/mmdetection3d/work-dirs/hv_pointpillars_secfpn_6x8_160e_kitti-3d-3class文件夾中看到訓(xùn)練結(jié)果,包括日志文件(.log)、權(quán)重文件(.pth)以及模型配置文件(.py)等。
?

測試及可視化

首先使用命令查看測試函數(shù)有哪些可傳入?yún)?shù):python tools/test.py -h

(mmdet3d) xxx@xxx:~/det3d/mmdetection3d$ python tools/test.py -h
usage: test.py [-h] [--out OUT] [--fuse-conv-bn]
               [--gpu-ids GPU_IDS [GPU_IDS ...]] [--gpu-id GPU_ID]
               [--format-only] [--eval EVAL [EVAL ...]] [--show]
               [--show-dir SHOW_DIR] [--gpu-collect] [--tmpdir TMPDIR]
               [--seed SEED] [--deterministic]
               [--cfg-options CFG_OPTIONS [CFG_OPTIONS ...]]
               [--options OPTIONS [OPTIONS ...]]
               [--eval-options EVAL_OPTIONS [EVAL_OPTIONS ...]]
               [--launcher {none,pytorch,slurm,mpi}] [--local_rank LOCAL_RANK]
               config checkpoint

MMDet test (and eval) a model

positional arguments:
  config                test config file path
  checkpoint            checkpoint file

optional arguments:
  -h, --help            show this help message and exit
  --out OUT             output result file in pickle format
  --fuse-conv-bn        Whether to fuse conv and bn, this will slightly
                        increasethe inference speed
  --gpu-ids GPU_IDS [GPU_IDS ...]
                        (Deprecated, please use --gpu-id) ids of gpus to use
                        (only applicable to non-distributed training)
  --gpu-id GPU_ID       id of gpu to use (only applicable to non-distributed
                        testing)
  --format-only         Format the output results without perform evaluation.
                        It isuseful when you want to format the result to a
                        specific format and submit it to the test server
  --eval EVAL [EVAL ...]
                        evaluation metrics, which depends on the dataset,
                        e.g., "bbox", "segm", "proposal" for COCO, and "mAP",
                        "recall" for PASCAL VOC
  --show                show results
  --show-dir SHOW_DIR   directory where results will be saved
  --gpu-collect         whether to use gpu to collect results.
  --tmpdir TMPDIR       tmp directory used for collecting results from
                        multiple workers, available when gpu-collect is not
                        specified
  --seed SEED           random seed
  --deterministic       whether to set deterministic options for CUDNN
                        backend.
  --cfg-options CFG_OPTIONS [CFG_OPTIONS ...]
                        override some settings in the used config, the key-
                        value pair in xxx=yyy format will be merged into
                        config file. If the value to be overwritten is a list,
                        it should be like key="[a,b]" or key=a,b It also
                        allows nested list/tuple values, e.g.
                        key="[(a,b),(c,d)]" Note that the quotation marks are
                        necessary and that no white space is allowed.
  --options OPTIONS [OPTIONS ...]
                        custom options for evaluation, the key-value pair in
                        xxx=yyy format will be kwargs for dataset.evaluate()
                        function (deprecate), change to --eval-options
                        instead.
  --eval-options EVAL_OPTIONS [EVAL_OPTIONS ...]
                        custom options for evaluation, the key-value pair in
                        xxx=yyy format will be kwargs for dataset.evaluate()
                        function
  --launcher {none,pytorch,slurm,mpi}
                        job launcher
  --local_rank LOCAL_RANK

可以看到有兩個必選參數(shù)configcheckpoint,分別為模型配置文件和訓(xùn)練生成的權(quán)重文件,其他參數(shù):

  • eval:使用的評價指標(biāo),取決于數(shù)據(jù)集(“bbox”, “segm”, “proposal” for COCO, and “mAP”, “recall” for PASCAL VOC),這里直接沿用了2D檢測中常用的幾個評價標(biāo)準(zhǔn)
  • show:是否對測試結(jié)果進(jìn)行可視化,要安裝open3d庫(沒有的話,直接pip install open3d即可)
  • out_dir:測試結(jié)果的保存目錄

指定好參數(shù)后,直接執(zhí)行命令進(jìn)行測試:

(mmdet3d) xxx@xxx:~/det3d/mmdetection3d$ python tools/test.py configs/pointpillars/hv_pointpillars_secfpn_6x8_160e_kitti-3d-3class.py work_dirs/hv_pointpillars_secfpn_6x8_160e_kitti-3d-3class/latest.pth --eval mAP --options 'show=True' 'out_dir=./outputs/pointpillars_kitti_160e/show_results'
tools/test.py:125: UserWarning: --options is deprecated in favor of --eval-options
  warnings.warn('--options is deprecated in favor of --eval-options')
[>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>] 3769/3769, 29.0 task/s, elapsed: 130s, ETA:     0s
Converting prediction to KITTI format
[>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>] 3769/3769, 810.7 task/s, elapsed: 5s, ETA:     0s
Result is saved to /tmp/tmpy6dxos64/results.pkl.
OMP: Info #276: omp_set_nested routine deprecated, please use omp_set_max_active_levels instead.


----------- AP11 Results ------------

Pedestrian AP11@0.50, 0.50, 0.50:
bbox AP11:66.2971, 63.2572, 60.1334
bev  AP11:59.5338, 53.1795, 49.7129
3d   AP11:52.5578, 46.1416, 42.2523
aos  AP11:43.38, 45.16, 42.93
Pedestrian AP11@0.50, 0.25, 0.25:
bbox AP11:66.2971, 63.2572, 60.1334
bev  AP11:75.2633, 71.2403, 67.1669
3d   AP11:74.8591, 70.7085, 66.6911
aos  AP11:43.38, 45.16, 42.93
Cyclist AP11@0.50, 0.50, 0.50:
bbox AP11:86.2886, 71.9338, 69.5510
bev  AP11:83.8300, 66.6311, 62.5886
3d   AP11:78.8692, 60.6178, 57.6603
aos  AP11:84.20, 67.30, 64.90
Cyclist AP11@0.50, 0.25, 0.25:
bbox AP11:86.2886, 71.9338, 69.5510
bev  AP11:87.6232, 70.1303, 67.9132
3d   AP11:87.6232, 70.1303, 67.9132
aos  AP11:84.20, 67.30, 64.90
Car AP11@0.70, 0.70, 0.70:
bbox AP11:90.5724, 89.2393, 86.4065
bev  AP11:89.0184, 85.9051, 79.4069
3d   AP11:82.8837, 75.8976, 68.6418
aos  AP11:90.32, 88.57, 85.49
Car AP11@0.70, 0.50, 0.50:
bbox AP11:90.5724, 89.2393, 86.4065
bev  AP11:90.6432, 89.8263, 88.9269
3d   AP11:90.6432, 89.7432, 88.6185
aos  AP11:90.32, 88.57, 85.49

Overall AP11@easy, moderate, hard:
bbox AP11:81.0527, 74.8101, 72.0303
bev  AP11:77.4607, 68.5719, 63.9028
3d   AP11:71.4369, 60.8857, 56.1848
aos  AP11:72.63, 67.01, 64.44

----------- AP40 Results ------------

Pedestrian AP40@0.50, 0.50, 0.50:
bbox AP40:66.8732, 63.0849, 59.3729
bev  AP40:58.9596, 52.1341, 47.7997
3d   AP40:51.0936, 44.6986, 40.1848
aos  AP40:44.17, 42.06, 39.35
Pedestrian AP40@0.50, 0.25, 0.25:
bbox AP40:66.8732, 63.0849, 59.3729
bev  AP40:75.9021, 72.3613, 68.1043
3d   AP40:75.5368, 71.7994, 67.5858
aos  AP40:44.17, 42.06, 39.35
Cyclist AP40@0.50, 0.50, 0.50:
bbox AP40:90.1101, 73.4135, 70.3551
bev  AP40:86.8236, 66.8870, 62.6626
3d   AP40:79.8955, 60.5005, 56.6893
aos  AP40:87.75, 68.17, 65.11
Cyclist AP40@0.50, 0.25, 0.25:
bbox AP40:90.1101, 73.4135, 70.3551
bev  AP40:89.9274, 71.4334, 68.2619
3d   AP40:89.9274, 71.4334, 68.2619
aos  AP40:87.75, 68.17, 65.11
Car AP40@0.70, 0.70, 0.70:
bbox AP40:95.4900, 91.9898, 87.3376
bev  AP40:91.5044, 87.7621, 83.4334
3d   AP40:84.6332, 75.8790, 71.2976
aos  AP40:95.19, 91.24, 86.38
Car AP40@0.70, 0.50, 0.50:
bbox AP40:95.4900, 91.9898, 87.3376
bev  AP40:95.6766, 94.7296, 90.1260
3d   AP40:95.6384, 94.3234, 89.9369
aos  AP40:95.19, 91.24, 86.38

Overall AP40@easy, moderate, hard:
bbox AP40:84.1578, 76.1627, 72.3552
bev  AP40:79.0958, 68.9277, 64.6319
3d   AP40:71.8741, 60.3594, 56.0572
aos  AP40:75.70, 67.16, 63.61

到這里會陸續(xù)顯示測試結(jié)果圖(MobaXterm):
kitti立體匹配數(shù)據(jù)集如何測試,3D目標(biāo)檢測,目標(biāo)檢測,計算機(jī)視覺,3D目標(biāo)檢測

注意?。?! 如果在VScode的終端執(zhí)行測試命令,在可視化的地方會出現(xiàn)以下警告:

[Open3D WARNING] GLFW Error: X11: The DISPLAY environment variable is missing
[Open3D WARNING] Failed to initialize GLFW

這是因?yàn)楫?dāng)前窗口DISPLAY環(huán)境變量為空,無法使用GLFW(創(chuàng)建OpenGL上下文,以及操作窗口的第三方庫)

解決辦法
首先在MobaXterm中輸入:echo $DISPLAY,查看當(dāng)前窗口DISPLAY環(huán)境變量的值

(mmdet3d) xxx@xxx:~/det3d/mmdetection3d$ echo $DISPLAY
localhost:10.0

之后,在VScode的終端輸設(shè)置DISPLAY環(huán)境變量的值為10.0,并查看:

(mmdet3d) xxx@xxx:~/det3d/mmdetection3d$ export DISPLAY=:10.0
(mmdet3d) xxx@xxx:~/det3d/mmdetection3d$ echo $DISPLAY
:10.0

再次運(yùn)行測試命令,可視化正常?。。?!
?

繪制損失函數(shù)曲線

MMDet3D中,提供了tools/analysis_tools/analyze_logs.py文件,用于繪制訓(xùn)練過程中的損失函數(shù)曲線和計算平均訓(xùn)練時間(目前僅支持這倆功能),執(zhí)行python tools/analysis_tools/analyze_logs.py -h命令,查看函數(shù)參數(shù):

(mmdet3d) xxx@xxx:~/det3d/mmdetection3d$ python tools/analysis_tools/analyze_logs.py -h
usage: analyze_logs.py [-h] {plot_curve,cal_train_time} ...
Analyze Json Log

positional arguments:
  {plot_curve,cal_train_time}
                        task parser
    plot_curve          parser for plotting curves
    cal_train_time      parser for computing the average time per training
                        iteration

optional arguments:
  -h, --help            show this help message and exit

可以看到有兩個必選參數(shù):plot_curve, cal_train_time,二者選其一即可,這里以plot_curve為例,繪制損失函數(shù)曲線圖,執(zhí)行如下命令:

(mmdet3d) xxx@xxx:~/det3d/mmdetection3d$ python tools/analysis_tools/analyze_logs.py plot_curve work_dirs/hv_pointpillars_secfpn_6x8_160e_kitti-3d-3class/20221002_160858.log.json --keys loss_cls loss_bbox --out losses.pdf 
plot curve of work_dirs/hv_pointpillars_secfpn_6x8_160e_kitti-3d-3class/20221002_160858.log.json, metric is loss_cls
plot curve of work_dirs/hv_pointpillars_secfpn_6x8_160e_kitti-3d-3class/20221002_160858.log.json, metric is loss_bbox
save curve to: losses.pdf

命令執(zhí)行結(jié)束,會在/mmdetection3d目錄下生成losses.pdf文件,繪制曲線如下所示:
kitti立體匹配數(shù)據(jù)集如何測試,3D目標(biāo)檢測,目標(biāo)檢測,計算機(jī)視覺,3D目標(biāo)檢測
注意??! 原本生成的曲線圖并不是這樣子,我自己根據(jù)個人喜好修改了analyze_logs.py中繪圖部分的代碼,感興趣的小伙伴可以參考一下(直接復(fù)制粘貼即可):

# Copyright (c) OpenMMLab. All rights reserved.
import argparse
import json
from collections import defaultdict

import numpy as np
import seaborn as sns
from matplotlib import pyplot as plt

# 定義plt字體大小
plt.rcParams.update({'font.size': 8})

def cal_train_time(log_dicts, args):
    for i, log_dict in enumerate(log_dicts):
        print(f'{"-" * 5}Analyze train time of {args.json_logs[i]}{"-" * 5}')
        all_times = []
        for epoch in log_dict.keys():
            if args.include_outliers:
                all_times.append(log_dict[epoch]['time'])
            else:
                all_times.append(log_dict[epoch]['time'][1:])
        all_times = np.array(all_times)
        epoch_ave_time = all_times.mean(-1)
        slowest_epoch = epoch_ave_time.argmax()
        fastest_epoch = epoch_ave_time.argmin()
        std_over_epoch = epoch_ave_time.std()
        print(f'slowest epoch {slowest_epoch + 1}, '
              f'average time is {epoch_ave_time[slowest_epoch]:.4f}')
        print(f'fastest epoch {fastest_epoch + 1}, '
              f'average time is {epoch_ave_time[fastest_epoch]:.4f}')
        print(f'time std over epochs is {std_over_epoch:.4f}')
        print(f'average iter time: {np.mean(all_times):.4f} s/iter')
        print()


def plot_curve(log_dicts, args):
    if args.backend is not None:
        plt.switch_backend(args.backend)
    sns.set_style(args.style)

    # 設(shè)置圖片標(biāo)題
    if args.title is None:
        title = args.json_logs[0]
    
    # 設(shè)置圖標(biāo)
    # if legend is None, use {filename}_{key} as legend
    legend = args.legend
    if legend is None:
        legend = []
        for json_log in args.json_logs:
            for metric in args.keys:
                # legend.append(f'{json_log}_{metric}')
                legend.append(f'{metric}')
    assert len(legend) == (len(args.json_logs) * len(args.keys))
    metrics = args.keys

    num_metrics = len(metrics)
    for i, log_dict in enumerate(log_dicts):
        epochs = list(log_dict.keys())
        for j, metric in enumerate(metrics):
            print(f'plot curve of {args.json_logs[i]}, metric is {metric}')
            if metric not in log_dict[epochs[args.interval - 1]]:
                raise KeyError(
                    f'{args.json_logs[i]} does not contain metric {metric}')

            if args.mode == 'eval':
                if min(epochs) == args.interval:
                    x0 = args.interval
                else:
                    # if current training is resumed from previous checkpoint
                    # we lost information in early epochs
                    # `xs` should start according to `min(epochs)`
                    if min(epochs) % args.interval == 0:
                        x0 = min(epochs)
                    else:
                        # find the first epoch that do eval
                        x0 = min(epochs) + args.interval - \
                            min(epochs) % args.interval
                xs = np.arange(x0, max(epochs) + 1, args.interval)
                ys = []
                for epoch in epochs[args.interval - 1::args.interval]:
                    ys += log_dict[epoch][metric]

                # if training is aborted before eval of the last epoch
                # `xs` and `ys` will have different length and cause an error
                # check if `ys[-1]` is empty here
                if not log_dict[epoch][metric]:
                    xs = xs[:-1]

                ax = plt.gca()
                ax.set_xticks(xs)
                plt.xlabel('epoch')
                plt.plot(xs, ys, label=legend[i * num_metrics + j], marker='o')
            else:
                xs = []
                ys = []
                num_iters_per_epoch = \
                    log_dict[epochs[args.interval-1]]['iter'][-1]
                for epoch in epochs[args.interval - 1::args.interval]:
                    iters = log_dict[epoch]['iter']
                    if log_dict[epoch]['mode'][-1] == 'val':
                        iters = iters[:-1]
                    xs.append(
                        np.array(iters) + (epoch - 1) * num_iters_per_epoch)
                    ys.append(np.array(log_dict[epoch][metric][:len(iters)]))
                xs = np.concatenate(xs)
                ys = np.concatenate(ys)
                plt.xlabel('iter')
                plt.plot(
                    xs, ys, label=legend[i * num_metrics + j], linewidth=0.5)
            plt.legend()
        plt.title(title)
    if args.out is None:
        plt.show()
    else:
        print(f'save curve to: {args.out}')
        plt.savefig(args.out)
        plt.cla()


def add_plot_parser(subparsers):
    parser_plt = subparsers.add_parser(
        'plot_curve', help='parser for plotting curves')
    parser_plt.add_argument(
        'json_logs',
        type=str,
        nargs='+',
        help='path of train log in json format')
    parser_plt.add_argument(
        '--keys',
        type=str,
        nargs='+',
        default=['mAP_0.25'],
        help='the metric that you want to plot')
    parser_plt.add_argument('--title', type=str, help='title of figure')
    parser_plt.add_argument(
        '--legend',
        type=str,
        nargs='+',
        default=None,
        help='legend of each plot')
    parser_plt.add_argument(
        '--backend', type=str, default=None, help='backend of plt')
    parser_plt.add_argument(
        '--style', type=str, default='dark', help='style of plt')
    parser_plt.add_argument('--out', type=str, default=None)
    parser_plt.add_argument('--mode', type=str, default='train')
    parser_plt.add_argument('--interval', type=int, default=1)


def add_time_parser(subparsers):
    parser_time = subparsers.add_parser(
        'cal_train_time',
        help='parser for computing the average time per training iteration')
    parser_time.add_argument(
        'json_logs',
        type=str,
        nargs='+',
        help='path of train log in json format')
    parser_time.add_argument(
        '--include-outliers',
        action='store_true',
        help='include the first value of every epoch when computing '
        'the average time')


def parse_args():
    parser = argparse.ArgumentParser(description='Analyze Json Log')
    # currently only support plot curve and calculate average train time
    # 目前僅支持繪制曲線和計算平均訓(xùn)練時間
    subparsers = parser.add_subparsers(dest='task', help='task parser')
    add_plot_parser(subparsers)
    add_time_parser(subparsers)
    args = parser.parse_args()
    return args


def load_json_logs(json_logs):
    # load and convert json_logs to log_dict, key is epoch, value is a sub dict
    # keys of sub dict is different metrics, e.g. memory, bbox_mAP
    # value of sub dict is a list of corresponding values of all iterations
    log_dicts = [dict() for _ in json_logs]
    for json_log, log_dict in zip(json_logs, log_dicts):
        with open(json_log, 'r') as log_file:
            for line in log_file:
                log = json.loads(line.strip())
                # skip lines without `epoch` field
                if 'epoch' not in log:
                    continue
                epoch = log.pop('epoch')
                if epoch not in log_dict:
                    log_dict[epoch] = defaultdict(list)
                for k, v in log.items():
                    log_dict[epoch][k].append(v)
    return log_dicts


def main():
    args = parse_args()

    json_logs = args.json_logs
    for json_log in json_logs:
        assert json_log.endswith('.json')

    log_dicts = load_json_logs(json_logs)

    eval(args.task)(log_dicts, args)


if __name__ == '__main__':
    main()

?

參考資料

KITTI數(shù)據(jù)集下載及解析

【深度估計】KITTI數(shù)據(jù)集介紹與使用說明

MMDETECTION3D’S DOCUMENTATION

MMdetection3d環(huán)境搭建、使用MMdetection3d做3D目標(biāo)檢測訓(xùn)練自己的數(shù)據(jù)集、測試、可視化,以及常見的錯誤

社區(qū)開放麥#8 | 邁向真實(shí)世界的感知:3D 目標(biāo)檢測文章來源地址http://www.zghlxwxcb.cn/news/detail-777364.html

到了這里,關(guān)于【MMDetection3D】環(huán)境搭建,使用PointPillers訓(xùn)練&測試&可視化KITTI數(shù)據(jù)集的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 零基礎(chǔ)熟悉mmdetection3d數(shù)據(jù)提取、模型搭建過程

    零基礎(chǔ)熟悉mmdetection3d數(shù)據(jù)提取、模型搭建過程

    本圖文從介紹配置文件開始,逐步構(gòu)建一個新的配置文件,并依次構(gòu)建相關(guān)模型,最終使用一條點(diǎn)云數(shù)據(jù)簡單走了一下處理流程 關(guān)于mmdetection3d的安裝,參考官方文檔安裝 — MMDetection3D 1.0.0rc4 文檔 1.1 mmdetection3d配置文件的組成 官方文檔:教程 1: 學(xué)習(xí)配置文件 — MMDetection3D 1.

    2024年02月05日
    瀏覽(27)
  • MMDetection3D使用學(xué)習(xí)(mmdet v1.1 rc)

    MMDetection3D使用學(xué)習(xí)(mmdet v1.1 rc)

    本文所觀看視頻教程的mmdet3d版本為v1.0.0 rc5,而我使用的是v1.1.0 rc3。v1.0.0 rc5的一些實(shí)現(xiàn)可以參考我的另一篇博客基于MMDet3D的pointpillars和centernet推理(mmdet3d v1.0 rc)或者官方文檔。本文會記錄學(xué)習(xí)中遇到的問題。視頻鏈接 支持點(diǎn)云、視覺、多模態(tài)檢測算法,支持室內(nèi)、室外場景

    2024年02月07日
    瀏覽(16)
  • MMDetection3D簡單學(xué)習(xí)

    我們通常把模型的各個組成成分分成 6 種類型: 編碼器(encoder):包括 voxel encoder 和 middle encoder 等進(jìn)入 backbone 前所使用的基于體素的方法,如? HardVFE ?和? PointPillarsScatter 。 骨干網(wǎng)絡(luò)(backbone):通常采用 FCN 網(wǎng)絡(luò)來提取特征圖,如? ResNet ?和? SECOND 。 頸部網(wǎng)絡(luò)(neck):

    2024年02月13日
    瀏覽(22)
  • mmdetection3d nuScenes (持續(xù)更新)

    本文為博主原創(chuàng)文章,未經(jīng)博主允許不得轉(zhuǎn)載。 本文為專欄《python三維點(diǎn)云從基礎(chǔ)到深度學(xué)習(xí)》系列文章,地址為“https://blog.csdn.net/suiyingy/article/details/124017716”。 ????????Mmdetection3d集成了大量3D深度學(xué)習(xí)算法,其中很大一部分可以在智能駕駛nuScenes數(shù)據(jù)集上運(yùn)行。在算法

    2023年04月15日
    瀏覽(19)
  • 【MMDetection3D】MVXNet踩坑筆記

    【MMDetection3D】MVXNet踩坑筆記

    原文 代碼 MVXNet(CVPR2019) 最近許多關(guān)于3D target detection的工作都集中在設(shè)計能夠使用點(diǎn)云數(shù)據(jù)的神經(jīng)網(wǎng)絡(luò)架構(gòu)上。雖然這些方法表現(xiàn)出令人鼓舞的性能,但它們通?;趩我荒B(tài),無法利用其他模態(tài)(如攝像頭和激光雷達(dá))的信息。盡管一些方法融合了來自不同模式的數(shù)據(jù),這些方

    2024年01月18日
    瀏覽(44)
  • 新版mmdetection3d將3D bbox繪制到圖像

    新版mmdetection3d將3D bbox繪制到圖像

    使用 python mmdet3d/utils/collect_env.py 收集環(huán)境信息 以前寫過mmdetection3d中的可視化,但mmdetection3d更新后代碼已經(jīng)不適用了,正好我把我的工作全轉(zhuǎn)移到新版mmdetection3d上來了,因此重新寫了一下推理結(jié)果可視化。整體思路還是構(gòu)建模型、構(gòu)建數(shù)據(jù)、推理、繪制,下面分步講解 我用

    2024年04月15日
    瀏覽(25)
  • mmdetection3d系列--(1)安裝步驟(無坑版)

    mmdetection3d系列--(1)安裝步驟(無坑版)

    ? 最近在看一些基于點(diǎn)云3d目標(biāo)檢測的文章,需要復(fù)現(xiàn)甚至修改一些算法,就找到了mmlab開源的mmdetection3d目標(biāo)檢測框架,方便后續(xù)學(xué)習(xí)。 ??? 在安裝的時候遇到一點(diǎn)坑,比如環(huán)境問題,安裝完能跑demo但是不能跑訓(xùn)練測試問題等。在解決問題后還是完成了安裝。在這里記錄一

    2024年02月02日
    瀏覽(15)
  • MMDetection3D庫中的一些模塊介紹

    MMDetection3D庫中的一些模塊介紹

    本文目前僅包含2個體素編碼器、2個中間編碼器、1個主干網(wǎng)絡(luò)、1個頸部網(wǎng)絡(luò)和1個檢測頭。如果有機(jī)會,會繼續(xù)補(bǔ)充更多模型。 若發(fā)現(xiàn)內(nèi)容有誤,歡迎指出。 ??MMDetection3D的點(diǎn)云數(shù)據(jù)一般會經(jīng)歷如下步驟/模塊: ??下面分別介紹每個部分的一些典型模型。 ??在介紹體素

    2023年04月17日
    瀏覽(16)
  • 點(diǎn)云檢測框投影到圖像上(mmdetection3d)

    點(diǎn)云檢測框投影到圖像上(mmdetection3d)

    原模型檢測時候只有點(diǎn)云的檢測框,本文主要是將demo文件中的pcd_demo.py中的代碼,將點(diǎn)云檢測出的3d框投影到圖像上面顯示。? ?

    2024年02月13日
    瀏覽(15)
  • mmdetection3d可視化多模態(tài)模型推理結(jié)果

    mmdetection3d可視化多模態(tài)模型推理結(jié)果

    參考文獻(xiàn): 帶你玩轉(zhuǎn) 3D 檢測和分割 (三):有趣的可視化 - 知乎 (zhihu.com) Welcome to MMDetection3D’s documentation! — MMDetection3D 1.0.0rc4 文檔 讓我們看一下ChatGPT的回答[手動狗頭]: mmdetection3D是基于PyTorch框架的3D目標(biāo)檢測工具包,它是mmdetection的3D擴(kuò)展版本。它提供了一個靈活且高效的

    2024年02月16日
    瀏覽(20)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包