1、训练代码部署运行
1.1 部署
新建虚拟环境:
conda create --name cpgnet-new python=3.7
安装依赖:
CUDA==11.3
Pytorch==1.12.1
PyYAML@5.4.1
scipy@1.3.1
nuscenes
pytz
rospkg
pyquaternion
opencv-python
scikit-learn
matplotlib
tqdm
cachetools
编译安装c++代码:
python3 setup.py install
1.2 运行
准备工作:
config_cpgnet_sgd_bili_sample_ohem_fp16.py中pretrain_epoch根据实际情况修改,如下所示,没有预训练模型,所以设为0:
class pretrain:
pretrain_epoch = 0
cpgnet.py中下图所示代码解注释:
下图所示代码注释:
执行以下指令开始训练:
python train.py --config config/config_cpgnet_sgd_bili_sample_ohem_fp16.py
2、python运行测试
single_infernece.py文件中修改配置文件路径、模型路径及拼接点云话题:
config_path = 'config/config_cpgnet_sgd_bili_sample_ohem_fp16.py'
model_path = 'experiments/config_cpgnet_sgd_bili_sample_ohem_fp16/checkpoint/47-model.pth'
sub_lidar_topic = "/merge_pointcloud"
single_infernece.py中解注释:
# np_p = get_xyz_points(msg_cloud, True)
# resample
# 不验证trt模型时解注释
# choice = np.random.choice(np_p.shape[0], 30000, replace=True)
# np_p = np_p[choice]
single_infernece.py中注释:
test_data_path='/home/mdj/data/sm_stone_label_data/bin/002457.bin'
np_p = np.fromfile(test_data_path, dtype=np.float32).reshape(-1,4)[:, :4]
# 验证trt模型使用
np_p = np_p[:30000]
执行以下指令开始运行测试:
roscore
cd ~/data/jidong/carmo_02/stone/
rosbag play front_lidar_pinglu_stone.bag
cd ~/catkin_ws/pointcloud_merge
source install/setup.bash
roslaunch launch/carmo.launch
python single_infernece.py
3、onnx代码运行
cpgnet.py中下图所示代码注释:
下图所示代码解注释:
export_onnx.py文件中修改配置文件路径、模型路径:
config_path = 'config/config_cpgnet_sgd_bili_sample_ohem_fp16.py'
model_path = 'experiments/config_cpgnet_sgd_bili_sample_ohem_fp16/checkpoint/47-model.pth'
执行以下指令开始导出onnx:
pytthon export_onnx.py
4、TensorRT代码部署运行
4.1 部署
安装依赖:
TensorRT-8.6.0.12
编译:
cd ~/catkin_ws/CPGNet/c++_inference/
catkin_make install
4.2 运行
cd ~/data/jidong/carmo_02/stone/
rosbag play front_lidar_pinglu_stone.bag
cd ~/catkin_ws/CPGNet/c++_inference/
source install/setup.bash
roslaunch launch/carmo.launch