MIT-SPARK / TEASER-plusplus

A fast and robust point cloud registration library
MIT License
1.81k stars 344 forks source link

[BUG] Seg Fault when testing on my own dataset #132

Closed gitouni closed 2 years ago

gitouni commented 2 years ago

Describe the bug Seg Fault Error when testing for more than 30 samples.

Have you run the unit tests?

Installed Dependencies Ubuntu 20.04. I have install all dependecies of teaserpp for python and examples can be run without error.

To Reproduce I use FPFH to build correspondence and TEASER++ for global registration. However, it will raise seg fault after almost 30 instances. Whatever the max coorespondence is (range from 500 to 5000), the seg fault will alwayas happen. My own dataset is ModelNet40, part of my code is as follows: TEASER++ Estimator

import teaserpp_python
import numpy as np
import open3d as o3d
from . import utils
import os
class TEASER:
    def __init__(self,voxel:float,cbar2=1,noise_bound=0.01,estimate_scaling=False,
                 gnc_factor=1.4,rotation_max_iteration=100,
                 rotation_cost_threshold=1e-12,
                 ):
        os.environ['OMP_NUM_THREADS']= '12'
        self.solver_params = teaserpp_python.RobustRegistrationSolver.Params()
        self.solver_params.cbar2 = cbar2
        self.solver_params.noise_bound = noise_bound
        self.solver_params.estimate_scaling = estimate_scaling
        self.solver_params.rotation_estimation_algorithm = (
            teaserpp_python.RobustRegistrationSolver.ROTATION_ESTIMATION_ALGORITHM.GNC_TLS
        )
        self.solver_params.rotation_gnc_factor = gnc_factor
        self.solver_params.rotation_max_iterations = rotation_max_iteration
        self.solver_params.rotation_cost_threshold = rotation_cost_threshold
        self.voxel = voxel
    def registrate(self, src:np.ndarray,dst:np.ndarray)->np.ndarray:
        src_pcd = o3d.geometry.PointCloud()
        dst_pcd = o3d.geometry.PointCloud()
        src_pcd.points = o3d.utility.Vector3dVector(src)  # src: N1,3
        dst_pcd.points = o3d.utility.Vector3dVector(dst)  # dst: N2,3
        src_pcd.voxel_down_sample(voxel_size=self.voxel)
        dst_pcd.voxel_down_sample(voxel_size=self.voxel)
        src_fpfh = utils.extract_fpfh(src_pcd,voxel_size=self.voxel)
        dst_fpfh = utils.extract_fpfh(dst_pcd,voxel_size=self.voxel)
        src_coor_index, dst_coor_index = utils.find_correspondences(src_fpfh,dst_fpfh,mutual_filter=True)
        src_coor, dst_coor = src[src_coor_index,:], dst[dst_coor_index,:]
        # src, dst (3,N)
        solver = teaserpp_python.RobustRegistrationSolver(self.solver_params)
        solver.solve(src_coor.T,dst_coor.T)  # (3,N1), (3,N2)
        solution = solver.getSolution()
        est_g = np.eye(4)
        est_g[:3,3] = solution.translation
        est_g[:3,:3] = solution.rotation
        return est_g

dataset testing

model = TEASER(**args)
for i, data in enumerate(testloader):
    p0, p1, igt = data
    est_g = model.registrate(p0,p1)

The error is

INFO - 2022-05-25 11:30:55,557 - test_teaserpp - test, 25/5995, 0.014207
段错误 (核心已转储)

I have checked my CPU memory does not overflow (1.4GB/32GB).

gitouni commented 2 years ago

see https://github.com/MIT-SPARK/TEASER-plusplus/issues/54#issuecomment-1070777676 first. Setting OMP_NUM_THREADS through os.environ does not work. However, setting OMP_NUM_THREADS through bash can fix this problem.

OMP_NUM_THREADS=12 python xxx.py

Maybe the reason is PMC module is complied in cpp and bind to python, so that os.environ cannot pass this parameter to inner cpp solver.