open3d使用gpu加速icp

部署运行你感兴趣的模型镜像
import time
import open3d as o3d
print(o3d.__DEVICE_API__)
if o3d.__DEVICE_API__ == 'cuda':
    import open3d.cuda.pybind.t.pipelines.registration as treg
else:
    import open3d.cpu.pybind.t.pipelines.registration as treg

def draw_registration_result(source, target, transformation):
    source_temp = source.clone()
    target_temp = target.clone()

    source_temp.transform(transformation)

    # This is patched version for tutorial rendering.
    # Use `draw` function for you application.
    o3d.visualization.draw_geometries(
        [source_temp.to_legacy(),
         target_temp.to_legacy()],
        zoom=0.4459,
        front=[0.9288, -0.2951, -0.2242],
        lookat=[1.6784, 2.0612, 1.4451],
        up=[-0.3402, -0.9189, -0.1996])


# Input point-clouds
# demo_icp_pcds = o3d.data.DemoICPPointClouds()
source = o3d.t.io.read_point_cloud("cloud_bin_0.pcd")
target = o3d.t.io.read_point_cloud("cloud_bin_1.pcd")

voxel_sizes = o3d.utility.DoubleVector([0.1, 0.05, 0.025])

# List of Convergence-Criteria for Multi-Scale ICP:
criteria_list = [
    treg.ICPConvergenceCriteria(relative_fitness=0.0001, relative_rmse=0.0001, max_iteration=20),
    treg.ICPConvergenceCriteria(0.00001, 0.00001, 15),
    treg.ICPConvergenceCriteria(0.000001, 0.000001, 10)
]

# `max_correspondence_distances` for Multi-Scale ICP (o3d.utility.DoubleVector):
max_correspondence_distances = o3d.utility.DoubleVector([0.3, 0.14, 0.07])

# Initial alignment or source to target transform.
init_source_to_target = o3d.core.Tensor.eye(4, o3d.core.Dtype.Float32)

# Select the `Estimation Method`, and `Robust Kernel` (for outlier-rejection).
estimation = treg.TransformationEstimationPointToPlane()

# Save iteration wise `fitness`, `inlier_rmse`, etc. to analyse and tune result.
callback_after_iteration = lambda loss_log_map : print("Iteration Index: {}, Scale Index: {}, Scale Iteration Index: {}, Fitness: {}, Inlier RMSE: {},".format(
    loss_log_map["iteration_index"].item(), 
    loss_log_map["scale_index"].item(), 
    loss_log_map["scale_iteration_index"].item(), 
    loss_log_map["fitness"].item(), 
    loss_log_map["inlier_rmse"].item()))

# Setting Verbosity to Debug, helps in fine-tuning the performance.
# o3d.utility.set_verbosity_level(o3d.utility.VerbosityLevel.Debug)

s = time.time()

registration_ms_icp = treg.multi_scale_icp(source, target, voxel_sizes,
                                           criteria_list,
                                           max_correspondence_distances,
                                           init_source_to_target, estimation,
                                           callback_after_iteration)

ms_icp_time = time.time() - s
print("Time taken by Multi-Scale ICP CPU: ", ms_icp_time)
print("Inlier Fitness: ", registration_ms_icp.fitness)
print("Inlier RMSE: ", registration_ms_icp.inlier_rmse)

draw_registration_result(source, target, registration_ms_icp.transformation)



# The algorithm runs on the same device as the source and target point-cloud.
source_cuda = source.cuda(0)
target_cuda = target.cuda(0)
s = time.time()

registration_ms_icp = treg.multi_scale_icp(source_cuda, target_cuda,
                                           voxel_sizes, criteria_list,
                                           max_correspondence_distances,
                                           init_source_to_target, estimation)

ms_icp_time = time.time() - s
print("Time taken by Multi-Scale ICP CUDA: ", ms_icp_time)
print("Inlier Fitness: ", registration_ms_icp.fitness)
print("Inlier RMSE: ", registration_ms_icp.inlier_rmse)

draw_registration_result(source.cpu(), target.cpu(), registration_ms_icp.transformation)

运行结果:

WARNING:root:Open3D CPU Python bindings were not found and Open3D is built with CUDA support. Open3D will not work on systems without CUDA devices.
cuda
Iteration Index: 0, Scale Index: 0, Scale Iteration Index: 0, Fitness: 0.6401799100449775, Inlier RMSE: 0.1435171877300303,
Iteration Index: 1, Scale Index: 0, Scale Iteration Index: 1, Fitness: 0.6784107946026986, Inlier RMSE: 0.13904681767650018, 
Iteration Index: 2, Scale Index: 0, Scale Iteration Index: 2, Fitness: 0.7068965517241379, Inlier RMSE: 0.13527219516165337, 
Iteration Index: 3, Scale Index: 0, Scale Iteration Index: 3, Fitness: 0.7383808095952024, Inlier RMSE: 0.13258198107889027, 
Iteration Index: 4, Scale Index: 0, Scale Iteration Index: 4, Fitness: 0.7638680659670165, Inlier RMSE: 0.1290726638117883,  
Iteration Index: 5, Scale Index: 0, Scale Iteration Index: 5, Fitness: 0.7848575712143928, Inlier RMSE: 0.12406552414009266, 
Iteration Index: 6, Scale Index: 0, Scale Iteration Index: 6, Fitness: 0.7946026986506747, Inlier RMSE: 0.11809130423869939, 
Iteration Index: 7, Scale Index: 0, Scale Iteration Index: 7, Fitness: 0.800599700149925, Inlier RMSE: 0.11378514535184624,  
Iteration Index: 8, Scale Index: 0, Scale Iteration Index: 8, Fitness: 0.7991004497751124, Inlier RMSE: 0.10894468258670095, 
Iteration Index: 9, Scale Index: 0, Scale Iteration Index: 9, Fitness: 0.7946026986506747, Inlier RMSE: 0.10418402377255993, 
Iteration Index: 10, Scale Index: 0, Scale Iteration Index: 10, Fitness: 0.787856071964018, Inlier RMSE: 0.09966809154918733,
Iteration Index: 11, Scale Index: 0, Scale Iteration Index: 11, Fitness: 0.7871064467766117, Inlier RMSE: 0.098674366357213,
Iteration Index: 12, Scale Index: 0, Scale Iteration Index: 12, Fitness: 0.7856071964017991, Inlier RMSE: 0.09772411987341977,
Iteration Index: 13, Scale Index: 0, Scale Iteration Index: 13, Fitness: 0.782608695652174, Inlier RMSE: 0.09591778394692035,
Iteration Index: 14, Scale Index: 0, Scale Iteration Index: 14, Fitness: 0.7811094452773614, Inlier RMSE: 0.09490764102588534,
Iteration Index: 15, Scale Index: 0, Scale Iteration Index: 15, Fitness: 0.7788605697151424, Inlier RMSE: 0.09349837448979069,
Iteration Index: 16, Scale Index: 0, Scale Iteration Index: 16, Fitness: 0.7743628185907047, Inlier RMSE: 0.09078584586480609,
Iteration Index: 17, Scale Index: 0, Scale Iteration Index: 17, Fitness: 0.7743628185907047, Inlier RMSE: 0.09075243429214983,
Iteration Index: 18, Scale Index: 0, Scale Iteration Index: 18, Fitness: 0.7736131934032984, Inlier RMSE: 0.09046248298063476,
Iteration Index: 19, Scale Index: 0, Scale Iteration Index: 19, Fitness: 0.7728635682158921, Inlier RMSE: 0.09017857365170984,
Iteration Index: 20, Scale Index: 1, Scale Iteration Index: 0, Fitness: 0.732347427619246, Inlier RMSE: 0.05556660941093014,
Iteration Index: 21, Scale Index: 1, Scale Iteration Index: 1, Fitness: 0.7252655696729848, Inlier RMSE: 0.045692598499078335,
Iteration Index: 22, Scale Index: 1, Scale Iteration Index: 2, Fitness: 0.7192251614247032, Inlier RMSE: 0.040759157802817116,
Iteration Index: 23, Scale Index: 1, Scale Iteration Index: 3, Fitness: 0.7175588419079358, Inlier RMSE: 0.03914417161120339,
Iteration Index: 24, Scale Index: 1, Scale Iteration Index: 4, Fitness: 0.7156842324515726, Inlier RMSE: 0.03826442346071981,
Iteration Index: 25, Scale Index: 1, Scale Iteration Index: 5, Fitness: 0.714642782753593, Inlier RMSE: 0.03777364694465274,
Iteration Index: 26, Scale Index: 1, Scale Iteration Index: 6, Fitness: 0.7131847531764216, Inlier RMSE: 0.03727315439898996,
Iteration Index: 27, Scale Index: 1, Scale Iteration Index: 7, Fitness: 0.7123515934180379, Inlier RMSE: 0.036992713854137736,
Iteration Index: 28, Scale Index: 1, Scale Iteration Index: 8, Fitness: 0.7123515934180379, Inlier RMSE: 0.037000121110260006,
Iteration Index: 29, Scale Index: 1, Scale Iteration Index: 9, Fitness: 0.711935013538846, Inlier RMSE: 0.03685469133653814,
Iteration Index: 30, Scale Index: 1, Scale Iteration Index: 10, Fitness: 0.711935013538846, Inlier RMSE: 0.036844882207075595,
Iteration Index: 31, Scale Index: 1, Scale Iteration Index: 11, Fitness: 0.712143303478442, Inlier RMSE: 0.0369191476901881,
Iteration Index: 32, Scale Index: 1, Scale Iteration Index: 12, Fitness: 0.712143303478442, Inlier RMSE: 0.036916446586517986,
Iteration Index: 33, Scale Index: 1, Scale Iteration Index: 13, Fitness: 0.712143303478442, Inlier RMSE: 0.0369131823317825,
Iteration Index: 34, Scale Index: 1, Scale Iteration Index: 14, Fitness: 0.711935013538846, Inlier RMSE: 0.036845330886925876,
Iteration Index: 35, Scale Index: 2, Scale Iteration Index: 0, Fitness: 0.6778512116590408, Inlier RMSE: 0.019811331031561873,
Iteration Index: 36, Scale Index: 2, Scale Iteration Index: 1, Fitness: 0.676608484437666, Inlier RMSE: 0.01824183982323284,
Iteration Index: 37, Scale Index: 2, Scale Iteration Index: 2, Fitness: 0.6762130712308648, Inlier RMSE: 0.017820459796440848,
Iteration Index: 38, Scale Index: 2, Scale Iteration Index: 3, Fitness: 0.6758741456250353, Inlier RMSE: 0.01765704556601279,
Iteration Index: 39, Scale Index: 2, Scale Iteration Index: 4, Fitness: 0.6758741456250353, Inlier RMSE: 0.017636787162782268,
Iteration Index: 40, Scale Index: 2, Scale Iteration Index: 5, Fitness: 0.6758176580240637, Inlier RMSE: 0.017622013414364635,
Iteration Index: 41, Scale Index: 2, Scale Iteration Index: 6, Fitness: 0.6756481952211489, Inlier RMSE: 0.01759052848056601,
Iteration Index: 42, Scale Index: 2, Scale Iteration Index: 7, Fitness: 0.6757046828221206, Inlier RMSE: 0.017601956425768395,
Iteration Index: 43, Scale Index: 2, Scale Iteration Index: 8, Fitness: 0.6756481952211489, Inlier RMSE: 0.01759245305854123,
Iteration Index: 44, Scale Index: 2, Scale Iteration Index: 9, Fitness: 0.6756481952211489, Inlier RMSE: 0.01759431171659403,
Time taken by Multi-Scale ICP CPU:  0.11198186874389648
Inlier Fitness:  0.6756481952211489
Inlier RMSE:  0.01759505999620161
Time taken by Multi-Scale ICP CUDA:  0.06492376327514648
Inlier Fitness:  0.6755917076201774
Inlier RMSE:  0.01758385560954595

在这里插入图片描述
带有gpu支持的open3d下载链接:open3d-0.15.2-cp38-cp38-win-amd64.whl

您可能感兴趣的与本文相关的镜像

PyTorch 2.8

PyTorch 2.8

PyTorch
Cuda

PyTorch 是一个开源的 Python 机器学习库,基于 Torch 库,底层由 C++ 实现,应用于人工智能领域,如计算机视觉和自然语言处理

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

给算法爸爸上香

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值