Coder Social home page Coder Social logo

3d-object-detection's Introduction

强对抗人、车检测

简介

本项目采用PointPillars进行3D检测。PointPillars是目前工业界应用广泛的点云检测模型,其最主要的特点是检测速度和精度的平衡。PointPillars 在 VoxelNetSECOND 的基础上针对性能进行了优化,将点云转化为柱体(Pillars)表示,从而使得编码后的点云特征可以使用2D卷积神经网络进行检测任务。

使用教程

数据准备

  • 目前Paddle3D中提供的PointPillars模型支持在KITTI格式数据集上训练,本项目使用的数据集地址为:
cd datasets/zw_1102_0914

数据集的目录结构组织如下:

└── kitti_dataset_root
    |—— training
        |—— label_2
            |—— 000001.txt
            |—— ...
        |—— calib
            |—— 000001.txt
            |—— ...
        |—— velodyne
            |—— 000001.bin
            |—— ...
    |—— ImageSets
        |—— test.txt
        |—— train.txt
        |—— trainval.txt
        |—— val.txt

数据集包含生成的数据增强所需的真值库,结构如下:

└── kitti_train_gt_database
    |—— anno_info_train.pkl
    |—— Car
        |—— 1102-day1_000000_Car_1.bin
        |—— ...
    |—— Pedestrian
        |—— 1102-day1_000000_Pedestrian_0.bin
        |—— ...
  • 若需生成其他训练时数据增强所需的真值库,指令如下:
python tools/create_det_gt_database.py --dataset_name kitti --dataset_root /path/to/datasets --save_dir /path/to/datasets

--dataset_root指定KITTI数据集所在路径,--save_dir指定用于保存所生成的真值库的路径。

训练

位于Paddle3D/目录下,执行:

python -m paddle.distributed.launch --gpus 0 \
    tools/train.py \
    --config configs/pointpillars/pointpillars_zw_car.yml \
    --save_interval 100 \
    --keep_checkpoint_max 100 \
    --save_dir outputs/pointpillars_zw_pedestrian_1102_0914 \
    --do_eval \
    --num_workers 8

训练脚本支持设置如下参数:

参数名 用途 是否必选项 默认值
gpus 使用的GPU编号 -
config 配置文件 -
save_dir 模型和visualdl日志文件的保存根路径 output
num_workers 用于异步读取数据的进程数量, 大于等于1时开启子进程读取数据 2
save_interval 模型保存的间隔步数 1000
do_eval 是否在保存模型时进行评估
log_interval 打印日志的间隔步数 10
keep_checkpoint_max 最新模型保存个数 5
resume 是否从断点恢复训练
batch_size mini-batch大小(每张GPU) 在配置文件中指定
iters 训练轮数 在配置文件中指定
learning_rate 学习率 在配置文件中指定
seed Paddle的全局随机种子值 None

评估

位于Paddle3D/目录下,执行:

python tools/evaluate.py \
    --config configs/pointpillars/pointpillars_zw_car.yml \
    --model /path/to/model.pdparams \
    --num_workers 8

评估脚本支持设置如下参数:

参数名 用途 是否必选项 默认值
config 配置文件 -
model 待评估模型路径 -
num_workers 用于异步读取数据的进程数量, 大于等于1时开启子进程读取数据 2
batch_size mini-batch大小 在配置文件中指定

模型导出

运行以下命令,将训练时保存的动态图模型文件导出成推理引擎能够加载的静态图模型文件。

python tools/export.py \
    --config configs/pointpillars/pointpillars_zw_car.yml \
    --model /path/to/model.pdparams \
    --save_dir /path/to/output

模型导出脚本支持设置如下参数:

参数名 用途 是否必选项 默认值
config 配置文件 -
model 待导出模型参数model.pdparams路径 -
save_dir 保存导出模型的路径,save_dir下将会生成三个文件:pointpillars.pdiparams pointpillars.pdiparams.infopointpillars.pdmodel deploy

模型部署

Python 部署

注意:目前PointPillars的仅支持使用GPU进行推理。

运行命令参数说明如下:

参数名 用途 是否必选项 默认值
mdoel_file 导出模型的结构文件pointpillars.pdmodel所在路径 -
params_file 导出模型的参数文件pointpillars.pdiparams所在路径 -
lidar_file 待预测的点云所在路径 -
point_cloud_range 模型中将点云划分为柱体(pillars)时选取的点云范围,格式为X_min Y_min Z_min X_max Y_Max Z_max -
voxel_size 模型中将点云划分为柱体(pillars)时每个柱体的尺寸,格式为X_size Y_size Z_size -
max_points_in_voxel 模型中将点云划分为柱体(pillars)时每个柱体包含点数量上限 -
max_voxel_num 模型中将点云划分为柱体(pillars)时保留的柱体数量上限 -
num_point_dim 点云文件中每个点的维度大小。例如,若每个点的信息是x, y, z, intensity,则num_point_dim填写为4 4
use_trt 是否使用TensorRT进行加速 0
trt_precision 当use_trt设置为1时,模型精度可设置0或1,0表示fp32, 1表示fp16 0
trt_use_static 当trt_use_static设置为1时,在首次运行程序的时候会将TensorRT的优化信息进行序列化到磁盘上,下次运行时直接加载优化的序列化信息而不需要重新生成 0
trt_static_dir 当trt_use_static设置为1时,保存优化信息的路径 -
collect_shape_info 是否收集模型动态shape信息。默认0。只需首次运行,后续直接加载生成的shape信息文件即可进行TensorRT加速推理 0
dynamic_shape_file 保存模型动态shape信息的文件路径 -

运行以下命令,执行预测:

python infer.py \
  --model_file /path/to/pointpillars.pdmodel \
  --params_file /path/to/pointpillars.pdiparams \
  --lidar_file /path/to/lidar.bin \
  --point_cloud_range 0 -39.68 -5 69.12 39.68 5 \
  --voxel_size .16 .16 10 \
  --max_points_in_voxel 32 \
  --max_voxel_num 40000

推理结果可视化

运行以下命令,执行可视化:

python tools/pcd_vis_single_frame_demo.py   \
   --model_file outputs/pointpillars_zw_car_1102/best_model/pointpillars.pdmodel   \
   --params_file outputs/pointpillars_zw_car_1102/best_model/pointpillars.pdiparams   \
   --lidar_file datasets/zw-1102-618-all/zw-1102-618-train-merge/lidar_bin_xyzi   \
   --image_dir datasets/zw-1102-618-all/zw-1102-618-train-merge/camera/front  \
   --calib_file datasets/zw-1102-618-all/zw-1102-618-train-merge/KITTI_format/training/calib/1102-day1_000000.txt   \
   --point_cloud_range 0 -39.68 -5 69.12 39.68 5   \
   --voxel_size .16 .16 10   \
   --max_points_in_voxel 32   \
   --max_voxel_num 40000

3d-object-detection's People

Contributors

gygwg avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.