Spconv1.0安装与CLOCs复现

1.Spconv1.0安装

anaconda3中安装的虚拟环境为Pytorch1.1 cuda=10.0 python=3.6。

其中电脑上安装的cuda版本应与pytorch上安装的cuda版本一致。

下面的有些依赖是CLOCs中的。

conda install pytorch==1.1.0 torchvision==0.3.0 cudatoolkit=10.0 -c pytorch
# 配置second运行环境-----
pip install cmake==3.14.3
conda install scikit-image scipy numba pillow matplotlib shapely
pip install fire tensorboardX protobuf opencv-python pccm
#--------
sudo apt-get install libboost-all-dev
git clone https://github.com/traveller59/spconv
cd spconv
git reset --hard 8da6f967fb9a054d8870c3515b1b44eca2103634
cd third_party/
rm pybind11/
git clone https://github.com/pybind/pybind11.git
cd pybind11/
git reset --hard 085a2943
cd ../../ #进入到spconv目录下
python setup.py bdist_wheel
python -m pip install dist/*.whl  
#安装成功

如果上述的git reset --hard 085a2943不可行的话,就不要执行git clone https://github.com/pybind/pybind11.git这一步,进入下面的链接
https://github.com/traveller59/spconv/tree/8da6f967fb9a054d8870c3515b1b44eca2103634,进入到third_party里面的pybind11进行下载。

2.CLOCs复现

git clone https://github.com/pangsu0613/CLOCs.git
mkdir CLOCs/d2_detection_data
mkdir CLOCs/model_dir

2.1构建KITTI数据集

└── KITTI_DATASET_ROOT
       ├── training    <-- 7481 train data
       |   ├── image_2 <-- for visualization
       |   ├── calib
       |   ├── label_2
       |   ├── velodyne
       |   └── velodyne_reduced <-- empty directory
       └── testing     <-- 7518 test data
       |   ├── image_2 <-- for visualization
       |   ├── calib
       |   ├── velodyne
       |   └── velodyne_reduced <-- empty directory
       └── kitti_dbinfos_train.pkl
       ├── kitti_infos_train.pkl
       ├── kitti_infos_test.pkl
       ├── kitti_infos_val.pkl
       └── kitti_infos_trainval.pkl

上面的test数据集没有安装,因此需要进入到second/create_data.py中注释掉跟test有关的代码。KITTI_DATASET_ROOT需要自建立

2.2初始化数据索引

# 进入到second文件夹下
python create_data.py create_kitti_info_file --data_path=../KITTI_DATASET_ROOT
python create_data.py create_reduced_point_cloud --data_path=../KITTI_DATASET_ROOT
python create_data.py create_groundtruth_database --data_path=../KITTI_DATASET_ROOT

如果在运行上述代码时出现No module named 'second’的相关字样,可以在second.core的上面一行引入路径

import sys
sys.path.append('这里面放入绝对路径,second的上一级目录,这里应该是CLOCs')

3.2导入模型

将作者提供的三维检测模型second_model.zip导入到model_dir中,将二维检测目标结果cascade_rcnn_sigmoid_data导入到d2_detection_data中,源文件下载地址CLOCs_related_files - Google 云端硬盘

3.3运行文件路径修改

修改训练配置文件CLOCs/second/configs/car.fhd.config,cyclist和pedestrian同理。

train_input_reader: {
  ...
  database_sampler {
    database_info_path: "/dir/to/your/kitti_dbinfos_train.pkl"
    ...
  }
  kitti_info_path: "/dir/to/your/kitti_infos_train.pkl"
  kitti_root_path: "/dir/to/your/KITTI_DATASET_ROOT"
}
...
train_config: {
  ...
  detection_2d_path: "/dir/to/2d_detection/data"
}
...
eval_input_reader: {
  ...
  kitti_info_path: "/dir/to/your/kitti_infos_val.pkl"
  kitti_root_path: "/dir/to/your/KITTI_DATASET_ROOT"
}

3.4 CLOCs训练

python ./pytorch/train.py train --config_path=./configs/car.fhd.config --model_dir=../model_dir

训练时出现no module named 'torchplus’的问题,处理方法同上面的second。

3.5CLOCs算法评估

python ./pytorch/train.py evaluate --config_path=./configs/car.fhd.config --model_dir=../model_dir --measure_time=True --batch_size=1

使用的是作者给的预训练模型,将CLOCs_SecCas_pretrained.zip解压到model_dir中,再将second_model.zip解压到model_dir中进行评估训练,这里我注释了train.py中的两行代码,这两行是输出2D检测结果,我只需要3D结果,故不影响。

result = get_coco_eval_result(gt_annos, dt_annos, class_names)
print(result)

最终的评估结果如下,(自己训练的结果删了,所以拿作者的结果贴出来了):
在这里插入图片描述


### CLOCs融合算法概述 CLOCs(Coherent Local Outlier Factor with Camera-LiDAR Fusion)是一种先进的多模态传感器融合技术,在物体检测方面表现出显著优势[^1]。该方法通过结合相机图像和LiDAR点云数据来提高目标识别精度。 #### 实现原理 核心在于利用局部异常因子(LOF),并将其扩展到跨模态特征空间中,从而增强不同传感器之间的互补性和一致性: - **预处理阶段**:对输入的RGB图像和三维点云分别进行初步处理,提取有用的几何结构信息。 - **特征学习模块**:采用深度神经网络架构自动挖掘两者的共同表示形式;对于视觉信号而言,可以选用卷积神经网络(CNN),而对于激光雷达则可能更适合基于体素网格的方法或其他专门设计用于处理稀疏3D数据集的技术。 - **联合建模机制**:构建一个能够同时接受来自两个域的数据作为输入的学习框架,并在此基础上定义损失函数以指导模型训练过程中的参数优化方向。 - **决策层集成策略**:最后一步是在预测层面将两种感知源的结果结合起来做出最终判断。 ```python import torch from torchvision import models, transforms from pointnet2_ops.pointnet2_utils import furthest_point_sample as fps class CLOCsModel(torch.nn.Module): def __init__(self): super().__init__() self.image_encoder = models.resnet50(pretrained=True) self.lidar_processor = PointNet() # 假设PointNet是一个已经定义好的类 def forward(self, images, lidar_points): img_features = self.image_encoder(images) sampled_indices = fps(lidar_points, ratio=0.5) # 下采样lidar points sparse_lidar = lidar_points[:, sampled_indices] lidar_features = self.lidar_processor(sparse_lidar) fused_representation = torch.cat([img_features, lidar_features], dim=-1) return fused_representation ``` 此代码片段展示了如何创建一个多模态编码器来进行早期融合操作。实际应用中还需要考虑更多细节如同步问题、坐标转换以及具体的下游任务需求等。
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值