一. Openpcdet的安装以及使用
* Openpcdet详细内容请看以下链接:
GitHub - open-mmlab/OpenPCDet: OpenPCDet Toolbox for LiDAR-based 3D Object Detection.
1.首先gitclone原文代码
2. 这里我建议自己按照作者github上的docs/install文件夹下指示一步步安装,(之前根据csdn上教程一直有报错),然后下载spconv,以及cumm, github链接如下:
GitHub - traveller59/spconv: Spatial Sparse Convolution Library
GitHub - FindDefinition/cumm: CUda Matrix Multiply library.
3. 打开spconv中的readme,并且严格按照readme步骤安装,一般需要编译一段时间。
4. 打开cumm中readme,严格按照上面指示安装。
5. 安装完成之后按照测试数据跑通检验一下。
二. Openpcdet训练自己的数据集
* 本人移植其他的数据集,由于我有自己的image数据,已经按照kitti数据集的格式转换为velodyne, calib, label, image四个文件,并且实现了评估,以及最终的检测结果,所以可能和其他博主不一样。
* 如果你只有velodyne,label,或者数据集格式还不知道如何转换,文件建议参考以下这几个博主的链接:
Training using our own dataset · Issue #771 · open-mmlab/OpenPCDet · GitHub
OpenPCDet 训练自己的数据集详细教程!_JulyLi2019的博客-优快云博客_openpcdet 数据集
3D目标检测(4):OpenPCDet训练篇--自定义数据集 - 知乎
Openpcdet-(2)自数据集训练数据集训练_花花花哇_的博客-优快云博客
win10 OpenPCDet 训练KITTI以及自己的数据集_树和猫的博客-优快云博客_openpcdet训练
这里首先总结以下主要涉及到以下三个文件的修改
* pcdet/datasets/custom/custom_dataset.py
* tools/cfgs/custom_models/pointpillar.yaml (也可以是其他模型)
* tools/cfgs/dataset_configs/custom_dataset.yaml
* demo.py
1.pcdet/datasets/custom/custom_dataset.py
其实custom_dataset.py只需要大家去模仿kitti_dataset.py去删改就可以了,而且大部分内容不需要用户修改,这里我修改了:
1)get_lidar函数
* 获取激光雷达数据,其他的get_image也类似
2) __getitem__函数
* 这个函数最重要,是获取数据字典并更新的关键
* 如果有些字典不需要可以删改,如calib,image等
3)get_infos函数
* 生成字典信息infos
infos={'image':xxx,
'calib': xxx,
'annos': xxx}
annos = {'name': xxx,
'truncated': xxx,
'alpha':xxx,
.............}
其中annos就是解析你的label文件生成的字典, 如类别名,是否被遮挡,bbox的角度
同理有些字典信息不需要可以增删
3) create_custom_infos函数
这个函数主要用来生成你的数据字典,一般以.pkl后缀,如果你不需要评估,可以将其中的评估部分删除,原理也很简单。
4) main函数中的类别信息
修改后的代码如下:
import copy
import pickle
import os
from skimage import io
import numpy as np
from ..kitti import kitti_utils
from ...ops.roiaware_pool3d import roiaware_pool3d_utils
from ...utils import box_utils, common_utils, calibration_kitti, object3d_custom
from ..dataset import DatasetTemplate
class CustomDataset(DatasetTemplate):
def __init__(self, dataset_cfg, class_names, training=True, root_path=None, logger=None, ext='.bin'):
"""
Args:
root_path:
dataset_cfg:
class_names:
training:
logger:
"""
super().__init__(
dataset_cfg=dataset_cfg, class_names=class_names, training=training, root_path=root_path, logger=logger
)
self.split = self.dataset_cfg.DATA_SPLIT[self.mode]
self.root_split_path = self.root_path / ('training' if self.split != 'test' else 'testing')
split_dir = os.path.join(self.root_path, 'ImageSets', (self.split + '.txt')) # custom/ImagSets/xxx.txt
self.sample_id_list = [x.strip() for x in open(split_dir).readlines()] if os.path.exists(split_dir) else None # xxx.txt内的内容
self.custom_infos = []
self.include_data(self.mode) # train/val
self.map_class_to_kitti = self.dataset_cfg.MAP_CLASS_TO_KITTI
self.ext = ext
def include_data(self, mode):
self.logger.info('Loading Custom dataset.')
custom_infos = []
for info_path in self.dataset_cfg.INFO_PATH[mode]:
info_path = self.root_path / info_path
if not info_path.exists():
continue
with open(info_path, 'rb') as f:
infos = pickle.load(f)
def get_label(self, idx):
label_file = self.root_split_path / 'label_2' / ('%s.txt' % idx)
assert label_file.exists()
return object3d_custom.get_objects_from_label(label_file)
def get_lidar(self, idx, getitem=True):
if getitem == True:
lidar_file = self.root_split_path + '/velodyne/' + ('%s.bin' % idx)
else:
lidar_file = self.root_split_path / 'velodyne' / ('%s.bin' % idx)
return np.fromfile(str(lidar_file), dtype=np.float32).reshape(-1, 4)
def get_image(self, idx):
"""
Loads image for a sample
Args:
idx: int, Sample index
Returns:
image: (H, W, 3), RGB Image
"""
img_file = self.root_split_path / 'image_2' / ('%s.png' % idx)

本文介绍了如何从源代码安装OpenPCDet,包括spconv和cumm的编译,以及如何使用和训练自己的数据集,重点讲解了custom_dataset.py的修改和模型配置。通过实例展示了数据处理、模型设置和检测结果的展示。
最低0.47元/天 解锁文章
383

被折叠的 条评论
为什么被折叠?



