PAConv: Position Adaptive Convolution with Dynamic Kernel Assembling on Point Clouds(PAConv 基于Paddle复现)

1.简介

论文介绍了位置自适应卷积(PAConv),一种用于三维点云处理的通用卷积运算。PAConv的关键是通过动态组合存储在权重库中的基本权重矩阵来构造卷积矩阵,其中这些权重矩阵的系数通过核心网从点位置自适应学习。通过这种方式,内核构建在数据驱动管理器中,使PAConv比二维卷积具有更大的灵活性,可以更好地处理不规则和无序的点云数据。此外,通过组合权重矩阵而不是从点位置预测核,降低了学习过程的复杂性。

此外,与现有的点云卷积运算不同,他们的网络架构通常是经过精心设计的,我们将我们的PAConv集成到基于经典MLP的点云处理网络中,而不需要改变网络配置。即使建立在简单的网络上,我们的方法仍然接近甚至超过最先进的模型,并显著提高了分类和分割任务的基线性能并且效率相当高。

2.复现精度

在modelnet40数据集上的测试效果如下表。

NetWorkepochsoptnum pointsbatch_sizedatasetaccvote acc
PAConv350SGD102432modelnet4093.40%93.48%

3.数据集

modelnet40数据集下载地址:

https://aistudio.baidu.com/aistudio/datasetdetail/161759

最优模型为项目目录下的best_model.pdparams文件。

4.环境依赖

PaddlePaddle == 2.3.1

5.论文解读

首先我们看一下网络结构:

在这里插入图片描述

网络代码如下,我们主要看一下前向运算forward方法中的代码:

class PAConv(nn.Layer):
    def __init__(self, args):
        Some layer init code...
    def forward(self, x, label=None, criterion=None):
        B, C, N = x.shape
        # 使用knn算法提取出每个点最近的20个点
        idx, _ = knn(x, k=self.k)  
        # 取出这些点并与原X值做减法,然后在第二个维度做拼接,
        # 得到 [b,6,n,k]形状的数据
        xyz = get_scorenet_input(x, idx=idx, k=self.k) 
        # 对1024个三维坐标进行特征提取,其中self.matrice1
        # 是自定义的可学习的参数。
        point1, center1 = feat_trans_dgcnn(point_input=x, kernel=self.matrice1, m=self.m1)  # b,n,m1,o1
        # 通过Scorenet得到新的特征
        score1 = self.scorenet1(xyz, calc_scores=self.calc_scores, bias_attr=0.5)
        # 组合Point, center ,和idx得到新的特征。
        point1 = assemble_dgcnn(scores=score1, points=point1, centers=center1, knn_idx=idx)  # b,o1,n
        point1 = F.relu(self.bn1(point1))
        # 以下的points都是重复上述过程。参数不同。
        point2, center2 = feat_trans_dgcnn(point_input=point1, kernel=self.matrice2, m=self.m2)
        score2 = self.scorenet2(xyz, calc_scores=self.calc_scores, bias_attr=0.5)
        point2 = assemble_dgcnn(scores=score2, points=point2, centers=center2, knn_idx=idx)
        point2 = F.relu(self.bn2(point2))

        point3, center3 = feat_trans_dgcnn(point_input=point2, kernel=self.matrice3, m=self.m3)
        score3 = self.scorenet3(xyz, calc_scores=self.calc_scores, bias_attr=0.5)
        point3 = assemble_dgcnn(scores=score3, points=point3, centers=center3, knn_idx=idx)
        point3 = F.relu(self.bn3(point3))

        point4, center4 = feat_trans_dgcnn(point_input=point3, kernel=self.matrice4, m=self.m4)
        score4 = self.scorenet4(xyz, calc_scores=self.calc_scores, bias_attr=0.5)
        point4 = assemble_dgcnn(scores=score4, points=point4, centers=center4, knn_idx=idx)
        point4 = F.relu(self.bn4(point4))
        ##################
        #融合多个Point特征
        point = paddle.concat((point1, point2, point3, point4), axis=1)
        point = F.relu(self.conv5(point))
        point11 = F.adaptive_max_pool1d(point, 1).reshape([B, -1])
        point22 = F.adaptive_avg_pool1d(point, 1).reshape([B, -1])
        point = paddle.concat((point11, point22), 1)
        # 经过多个线性层进行特征提取
        point = F.relu(self.bn11(self.linear1(point)))
        point = self.dp1(point)
        point = F.relu(self.bn22(self.linear2(point)))
        point = self.dp2(point)
        # 最终通过一个线性层得到分类结果
        point = self.linear3(point)

        if criterion is not None:
            return point, criterion(point, label)  # return output and loss
        else:
            return point     

6.快速开始

训练:

下载数据集解压后,将数据集放到项目的data目录下。

%cd /home/aistudio/PaddlePAConv
!ln -s /home/aistudio/data
!cd data && unzip data161759/modelnet40_ply_hdf5_2048.zip
!python -u main.py --config config/dgcnn_paconv_train.yaml --dataset_root data/modelnet40_ply_hdf5_2048 --seed 9999

config: 配置文件地址

dataset_root: 训练集路径

测试:

使用最优模型进行评估.

%cd /home/aistudio/PaddlePAConv
!python -u main.py --config config/dgcnn_paconv_test.yaml --dataset_root data/modelnet40_ply_hdf5_2048 --model_path best_model.pdparams

config: 配置文件路径

dataset_root: 训练集路径

model_path: 预训练模型路径

测试结果

Loading pretrained model from best_model.pdparams
There are 85/85 variables loaded into PAConv.
Test :: test acc: 0.933955, test avg acc: 0.895698

投票测试使用以下命令:

%cd /home/aistudio/PaddlePAConv
!python -u eval_voting.py --config config/dgcnn_paconv_test.yaml --dataset_root data/modelnet40_ply_hdf5_2048 --model_path best_model.pdparams

测试结果

Voting 297, test acc: 92.990276,
Voting 298, test acc: 93.233387,
Voting 299, test acc: 93.273906,
Final voting test acc: 93.476499,

单张图片预测

输入的点云形状如下图:

%cd /home/aistudio/PaddlePAConv
!python predict.py --config config/dgcnn_paconv_test.yaml --input_file example/plane.h5 --model_path best_model.pdparams

参数说明:

config: 配置文件路径

input_file: 输入文件

model_path: 训练好的模型

Compiling user custom op, it will cost a few seconds.....
W0805 16:47:21.422516  5542 gpu_resources.cc:61] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 10.1
W0805 16:47:21.426019  5542 gpu_resources.cc:91] device: 0, cuDNN Version: 7.6.
Loading pretrained model from best_model.pdparams
There are 85/85 variables loaded into PAConv.
The input points is class airplane

模型导出

模型导出可执行以下命令:

%cd /home/aistudio/PaddlePAConv
!python export_model.py --model_path best_model.pdparams --save_dir ./output/

参数说明:

model_path: 模型路径

save_dir: 输出图片保存路径

Inference推理

可使用以下命令进行模型推理。infer命令运行如下:

%cd /home/aistudio/PaddlePAConv
!python infer.py --use_gpu=False --enable_mkldnn=False --cpu_threads=1 --model_file=output/model.pdmodel --batch_size=1 --input_file=example/plane.h5 --enable_benchmark=False --precision=fp32 --params_file=output/model.pdiparams

参数说明:

use_gpu:是否使用GPU

enable_mkldnn:是否使用mkldnn

cpu_threads: cpu线程数

model_file: 模型路径

batch_size: 批次大小

input_file: 输入文件路径

enable_benchmark: 是否开启benchmark

precision: 运算精度

params_file: 模型权重文件,由export_model.py脚本导出。

TIPC基础链条测试

该部分依赖auto_log,需要进行安装,安装方式如下:

auto_log的详细介绍参考https://github.com/LDOUBLEV/AutoLog

%cd /home/aistudio/
!git clone https://gitee.com/Double_V/AutoLog
%cd /home/aistudio/AutoLog/
!pip3 install -r requirements.txt
!python3 setup.py bdist_wheel
!pip3 install ./dist/auto_log-1.2.0-py3-none-any.whl

运行测试:

%cd /home/aistudio/PaddlePAConv
!bash test_tipc/prepare.sh test_tipc/configs/paconv/train_infer_python.txt 'lite_train_lite_infer'

!bash test_tipc/test_train_inference_python.sh test_tipc/configs/paconv/train_infer_python.txt 'lite_train_lite_infer'

测试结果如截图所示:

在这里插入图片描述

7.代码结构与详细说明

PaddlePAConv
├── README.md #用户指南
├── assign_score_gpu #自定义算子,运行时会自动编译加载
│   ├── __init__.py
│   ├── assign_score_withk_cuda.cc
│   ├── assign_score_withk_kernel.cu
│   └── setup.py
├── config #配置文件
│   ├── dgcnn_paconv_test.yaml # 训练脚本
│   └── dgcnn_paconv_train.yaml #测试脚本
├── data
│   └── modelnet40_ply_hdf5_2048 #数据集
├── eval_voting.py # 评估脚本 (投票)
├── example # 样例图片文件夹
├── export_model.py # 模型导出脚本
├── infer.py # 推理脚本
├── main.py # 主程序,包含训练和测试
├── model
│   ├── DGCNN_PAConv.py # 模型网络
│   ├── __init__.py
│   └── param_init.py
├── test.log # 测试日志
├── test_tipc # TIPC测试目录
│   ├── README.md
│   ├── common_func.sh
│   ├── configs
│   ├── data
│   ├── docs
│   ├── output
│   ├── prepare.sh
│   └── test_train_inference_python.sh
├── train.log # 训练日志
├── util # 工具类
│   ├── PAConv_util.py
│   ├── __init__.py
│   ├── data_util.py
│   └── util.py
└── vis.py # 点云可视化脚本

8.模型信息

信息描述
模型名称PAConv
框架版本PaddlePaddle==2.3.1
应用场景点云分类

9.心得体会

之前复现的论文对自定算子不熟悉,所以也看到自定义算子就很头疼。现在paddle的最新版本,自定义算子有了很大的更新,自定义算子的功能得到了进一步的完善,尤其是可以动态的自动编译算子非常的方便。通过本篇论文的复现进一步熟悉了编写自定义算子的方法,拓宽了论文复现的思路。最后感谢AI Studio提供算力的支持!

此文章为搬运
原项目链接

Logo

学大模型,用大模型上飞桨星河社区!每天8点V100G算力免费领!免费领取ERNIE 4.0 100w Token >>>

更多推荐