【问题标题】:PCL kd-tree implementation extremely slowPCL kd-tree 实现极其缓慢
【发布时间】:2014-10-16 16:23:15
【问题描述】:

我正在使用基于点云库 (PCL) 的 C++ 实现 kd-tree 最近邻 (NN) 搜索。该数据集包含大约 220 万个点。我正在为每个其他点搜索 NN 点。搜索半径设置为 2.0。要完全计算,大约需要 12 个小时!我正在使用具有 4GB RAM 的 Windows 64 位机器。 kd-tree 搜索很常见吗?我想知道是否有任何其他用于 3D 点云数据的 c++ 库,它更快。我听说过 ANN C++ 库和 CGAL,但不确定它们有多快。

【问题讨论】:

  • 我会给+1,因为这个问题很困难。但是,请考虑下次测试自己并询问时间结果。
  • 您提到您的搜索半径设置为 2.0。您的数据是如何分布的(例如,它在 XYZ 方向上覆盖什么范围)?如果很多点落入搜索半径内,搜索会变得非常缓慢。
  • 使用 2.0 的搜索半径,大约点数约为 7-80。但是数据不是均匀分布的。 NN 数从 10 到 150 不等。我也认为问题不在于维度,而在于数据的分布。
  • 你要对答案说点什么吗?

标签: nearest-neighbor point-cloud-library cgal kdtree


【解决方案1】:

简而言之:

只有自己进行时间测量才能确定。

您应该确保 NN 库是否比蛮力更快,您的数据可能就是这种情况。

正如评论中提到的安德拉斯,搜索半径也起着重要作用。如果很多点落入搜索半径内,搜索会变得非常缓慢。

完整答案:

3 个维度并不多。由于您拥有的点数而出现问题。

ANN 代表近似最近邻搜索。在涉及 NNS(最近邻搜索)时,接受准确度和速度之间的权衡是很常见的。

这意味着您执行搜索的速度更快,但您可能找不到确切的 NN,而是找到一个接近的(例如,不是最近的点,而是第二近的点,依此类推)。更快的速度意味着更低的准确性,反之亦然。

CGAL还有一个参数epsilon,代表精度(ε=0表示完全精度)。 CGAL 是为了达到 3 个维度,所以你可以试一试。

我可以测试自己并发布答案。但是,这不是 100% 安全的,因为您所拥有的点可能有一些关系。如果要利用点(可能)彼此之间的关系,这对库的性能非常重要。

另一个需要考虑的因素,安装的容易程度。

CGAL 很难安装。当我这样做时,我遵循these 的步骤。 ANN 易于安装。 我还建议你看看 BOOST Geometry,它可能会派上用场。

FLANN 也是该领域的佼佼者,但我不建议这样做,因为它旨在处理更大尺寸的数据集(例如 128)。

....

好吧,我承认,我现在对自己很好奇,我要进行一些测试!

....

ANN

(我没有发布代码,因此答案不会变得太大。文档中有示例,您当然可以询问是否需要!)。 输出:

// 克莱因瓶

samaras@samaras-A15:~/Inria/nn_libs/ANN/ann_1.1.2/code$ g++ main.cpp -O3 -I ../include/ -L../lib -lANN -std=c++0x -o myExe
samaras@samaras-A15:~/Inria/nn_libs/ANN/ann_1.1.2/code$ ./myExe
N = 1000000
D = 3
ε = 0 // full accuracy
Misses: 0
creation of the tree took 1.06638 seconds.
Brute force for min: 0.009985598 seconds.
NN for 0.0           0.000078551 seconds.
Speedup of ANN for NN = 8.721533780

对于ε = 0.1,我得到了:

Misses: 1000
creation of the tree took 0.727613 seconds.
Brute force for min: 0.006351318 seconds.
NN for 0.0           0.000004260 seconds.
Speedup of ANN for NN = 8.678169573

//对于一个shpere

ε = 0
Misses: 0
creation of the tree took 1.28098 seconds.
Brute force for min: 0.006382912 seconds.
NN for 0.0           0.000022341 seconds.
Speedup of ANN for NN = 4.897436311

ε = 0.1
Misses: 1000
creation of the tree took 1.25572 seconds.
Brute force for min: 0.006482465 seconds.
NN for 0.0           0.000004379 seconds.
Speedup of ANN for NN = 5.144413371

注意加速的差异!这与数据集的性质有关,如上所述(点之间的关系)。

CGAL:

// 克莱因瓶

samaras@samaras-A15:~/code/NN$ ./myExe
ε = 0
SplitingRule = Sliding_midpoint, N = 1000000, D = 3
creation of the tree took 0.02478 seconds.
Tree statistics:
Number of items stored: 1000000
Number of nodes: 471492
 Tree depth: 34
0x80591e4
Brute force for min: 0.007979495 seconds.
NN for 0.0           0.008085704 seconds.
Speedup of cgal for NN = 0.983849423

ε = 0.1
SplitingRule = Sliding_midpoint, N = 1000000, D = 3
creation of the tree took 0.02628 seconds.
Tree statistics:
Number of items stored: 1000000
Number of nodes: 471492
 Tree depth: 34
0x80591e4
Brute force for min: 0.007852951 seconds.
NN for 0.0           0.007856228 seconds.
Speedup of cgal for NN = 0.996250305

// 球体

samaras@samaras-A15:~/code/NN$ ./myExe
ε = 0
SplitingRule = Sliding_midpoint, N = 1000000, D = 3
creation of the tree took 0.025502 seconds.
Tree statistics:
Number of items stored: 1000000
Number of nodes: 465002
 Tree depth: 32
0x80591e4
Brute force for min: 0.007946504 seconds.
NN for 0.0           0.007981456 seconds.
Speedup of cgal for NN = 0.992449817


samaras@samaras-A15:~/code/NN$ ./myExe
ε = 0.1
SplitingRule = Sliding_midpoint, N = 1000000, D = 3
creation of the tree took 0.025106 seconds.
Tree statistics:
Number of items stored: 1000000
Number of nodes: 465002
 Tree depth: 32
0x80591e4
Brute force for min: 0.008115519 seconds.
NN for 0.0           0.008117261 seconds.
Speedup of cgal for NN = 0.996702679

在我的测试中,ANN 比 CGAL 更清晰,可能你的也一样!


附注:

您实际上要求每个点的 NN。但是,图书馆不知道这一点,也没有考虑到之前为每个点所做的​​工作,这是一个遗憾。但是,我不知道有任何图书馆这样做。

【讨论】:

  • PCL 在内部使用 FLANN。你也用 FLANN 做过基准测试吗?我对 PCL 的 FLANN 包装器非常熟悉,根据我的经验,在低维数据的情况下它通常不会比 ANN 慢(甚至更快)。
  • 不,我没有运行 FLANN @anderas,因为 OP 没有提到它,主要是因为 FLANN 用于更高的维度,而 OP 的数据集位于 3 个维度。
  • 我不明白你的结果,他们是否真的表明 CGAL 的树比暴力搜索慢?这是不可能的,一定是有问题。
  • @AleksanderFular 当维度很高时,已知 CGAL 在最近邻中表现不佳。
  • @gsamaras 我不知道,反正你的测试是在 D=3 上进行的吗?这就是我从您的回复中得到的信息
猜你喜欢
  • 2014-01-27
  • 2011-07-05
  • 1970-01-01
  • 1970-01-01
  • 2011-11-18
  • 1970-01-01
  • 1970-01-01
  • 2019-04-27
  • 2011-03-22
相关资源
最近更新 更多