连接速腾16线激光雷达,录制rslidar_points的bag文件:
rosbag record /rslidar_packets -O bag
然后需要将bag文件转换成.bin文件,先转成pcd:
rosrun pcl_ros bag_to_pcd data.bag /rslidar_points ./pcd
pcd是创建的存放.pcd文件的位置
然后转成.bin文件
# -*- coding: utf-8 -*-
# @Time : 2022/7/25 11:30
# @Author : JulyLi
# @File : pcd2bin.py
import numpy as np
import os
import argparse
from pypcd import pypcd
import csv
from tqdm import tqdm
def main():
## Add parser
parser = argparse.ArgumentParser(description="Convert .pcd to .bin")
parser.add_argument(
"--pcd_path",
help=".pcd file path.",
type=str,
default="pcd4"
)
parser.add_argument(
"--bin_path",
help=".bin file path.",
type=str,
default="bin4"
)
parser.add_argument(
"--file_name",
help="File name.",
type=str,
default="file_name"
)
args = parser.parse_args()
## Find all pcd files
pcd_files = []
for (path, dir, files) in os.walk(args.pcd_path):
for filename in files:
# print(filename)
ext = os.path.splitext(filename)[-1]
if ext == '.pcd':
pcd_files.append(path + "/" + filename)
## Sort pcd files by file name
pcd_files.sort()
print("Finish to load point clouds!")
## Make bin_path directory
try:
if not (os.path.isdir(args.bin_path)):
os.makedirs(os.path.join(args.bin_path))
except OSError as e:
# if e.errno != errno.EEXIST:
# print("Failed to create directory!!!!!")
raise
## Generate csv meta file
csv_file_path = os.path.join(args.bin_path, "meta.csv")
csv_file = open(csv_file_path, "w")
meta_file = csv.writer(
csv_file, delimiter=",", quotechar="|", quoting=csv.QUOTE_MINIMAL
)
## Write csv meta file header
meta_file.writerow(
[
"pcd file name",
"bin file name",
]
)
print("Finish to generate csv meta file")
## Converting Process
print("Converting Start!")
seq = 0
for pcd_file in tqdm(pcd_files):
## Get pcd file
pc = pypcd.PointCloud.from_path(pcd_file)
## Generate bin file name
# bin_file_name = "{}_{:05d}.bin".format(args.file_name, seq)
bin_file_name = "{:05d}.bin".format(seq)
bin_file_path = os.path.join(args.bin_path, bin_file_name)
## Get data from pcd (x, y, z, intensity, ring, time)
np_x = (np.array(pc.pc_data['x'], dtype=np.float32)).astype(np.float32)
np_y = (np.array(pc.pc_data['y'], dtype=np.float32)).astype(np.float32)
np_z = (np.array(pc.pc_data['z'], dtype=np.float32)).astype(np.float32)
np_i = (np.array(pc.pc_data['intensity'], dtype=np.float32)).astype(np.float32) / 256
# np_r = (np.array(pc.pc_data['ring'], dtype=np.float32)).astype(np.float32)
# np_t = (np.array(pc.pc_data['time'], dtype=np.float32)).astype(np.float32)
## Stack all data
points_32 = np.transpose(np.vstack((np_x, np_y, np_z, np_i)))
## Save bin file
points_32.tofile(bin_file_path)
## Write csv meta file
meta_file.writerow(
[os.path.split(pcd_file)[-1], bin_file_name]
)
seq = seq + 1
if __name__ == "__main__":
main()
然后开始标定 采用labelCloud 开源三维点云工具标注自制点云数据集
1.以如下命令安装:
git clone https://github.com/ch-sa/labelCloud.git
2.建议在Conda环境下新建一个虚拟环境安装标注软件所需的依赖,因为系统自带的python3是3.6的,可能会存在一些问题,新建一个虚拟环境就非常清爽:
conda create -n label3.8 python=3.8 -y
3.进入创建的虚拟环境:
conda activate label3.8
4.在下载的标注软件labelCloud路径下启动配置的虚拟环境,安装相关依赖:
pip install -r requirements.txt
5.启动软件:
python labelCloud.py
生成对应的标签后,需要使用openpcdet进行标定。安装过程中会存在较多的版本安装问题,作者采用的方式如下:
首先创建一个虚拟环境:
conda create -n pcdetect python=3.8
conda activate pcdetect
这里如果用python3.7的话后面会有一个av2包的报错无法解决,因为av2只支持python3.8及以上,显示说没有与3.7适配的版本。
git clone https://ghproxy.com/https://github.com/open-mmlab/OpenPCDet.git
下载好openpcd的包以后,下载这个包:
git clone https://github.com/AbangLZU/EasyPointPillars
主要是参考其中requirments.txt的版本,然后这个是大佬写的简化版本,也是可以直接用的配置什么的都比较简单。我的是cuda10,所以将OpenPCDet其中的pytorch设置为1.4.0,torchvision设置为0.5.0。
后续:
cd OpenPCDet或者大佬的那个包 为最后还是用cd EasyPointPillars大佬修改过的版本了可能因为我的cuda10.0太低了用OpenPCDet时,spconv一直有问题
pip install -r requirements.txt
python setup.py develop
随后是安装spconv,确保torch的版本是1.4.0:
git clone https://github.com/AbangLZU/spconv.git --recursive
编译:
python setup.py bdist_wheel
安装:
cd dist/
pip install the_wheel_file_you_produced.whl然后训练模型,模型修改部分参考:
存在报错1.python相对包导入失败的是没有重新编译好
报错2:
RuntimeError:
normalize(Tensor input, float p=2., int dim=1, float eps=9.9999999999999998e-13, Tensor? out=None) -> (Tensor):
Expected a value of type 'float' for argument 'p' but instead found type 'int'.
:
File "/home/a/miniconda3/envs/pc3.8/lib/python3.8/site-packages/kornia/geometry/conversions.py", line 362
"Input must be a tensor of shape (*, 4). Got {}".format(
quaternion.shape))
return F.normalize(quaternion, p=2, dim=-1, eps=eps)
~~~~~~~~~~~ <--- HERE
'normalize_quaternion' is being compiled since it was called from 'quaternion_to_rotation_matrix'
File "/home/a/miniconda3/envs/pc3.8/lib/python3.8/site-packages/kornia/geometry/conversions.py", line 396
quaternion.shape))
# normalize the input quaternion
quaternion_norm: torch.Tensor = normalize_quaternion(quaternion)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE # unpack the normalized quaternion components
'quaternion_to_rotation_matrix' is being compiled since it was called from 'quat_to_mat'
File "/home/a/OpenPCDet/pcdet/datasets/argo2/argo2_utils/so3.py", line 19
(...,3,3) 3D rotation matrices.
"""
return C.quaternion_to_rotation_matrix(
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~... <--- HERE
quat_wxyz, order=C.QuaternionCoeffOrder.WXYZ
)
还以为是哪里没写好,其实是标签文件train.txt里面是六位的如000000,而为实际的bin文件是五位的,如00000.bin所以存在问题。
问题3:
ValueError: need at least one array to concatenate
因为我是3个标签,实际只用了一个,一开始以为是不能设置3个得设置一个,后来发现是因为有几个标签是空的,在train.txt里删除对应的空标签即可正常运行。
然后开始训练:
python tools/train.py --cfg_file tools/cfgs/custom_models/pointrcnn.yaml --batch_size=2 --epochs=300
出现报错:
File "/home/a/OpenPCDet/pcdet/utils/spconv_utils.py", line 4, in <module>
if float(spconv.__version__[2:]) >= 2.2:
AttributeError: module 'spconv' has no attribute '__version__'