- Notifications
You must be signed in to change notification settings - Fork0
A high-performance implementation of 3D RANSAC (Random Sample Consensus) algorithm using PyTorch and CUDA.
License
harrydobbs/torch_ransac3d
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation

A high-performance implementation of 3D RANSAC algorithm using PyTorch and CUDA.
Explore the docs »
View Demo ·Report Bug ·Request Feature
Requirements: torch, numpy
Install with PyPI:
pip install torch-ransac3d
- High-performance RANSAC implementation using PyTorch and CUDA
- Supports fitting of multiple geometric primitives:
- Lines
- Planes
- Spheres
- Circles
- Cylinders
- Cuboids
- Points
- Batch processing capability for improved efficiency
- Support for both PyTorch tensors and NumPy arrays as input
- Clean dataclass return types for all fitting functions
importtorchimportnumpyasnpfromtorch_ransac3d.lineimportline_fit# Using PyTorch tensorpoints_torch=torch.rand(1000,3)result=line_fit(pts=points_torch,thresh=0.01,max_iterations=1000,iterations_per_batch=100,epsilon=1e-8,device=torch.device("cuda"iftorch.cuda.is_available()else"cpu"))print(f"Direction:{result.direction}")print(f"Point:{result.point}")print(f"Number of inliers:{len(result.inliers)}")# Using NumPy arraypoints_numpy=np.random.rand(1000,3)result=line_fit(pts=points_numpy,thresh=0.01,max_iterations=1000,iterations_per_batch=100,epsilon=1e-8,device=torch.device("cuda"iftorch.cuda.is_available()else"cpu"))
fromtorch_ransac3d.planeimportplane_fit# Works with both PyTorch tensors and NumPy arrayspoints=torch.rand(1000,3)# or np.random.rand(1000, 3)result=plane_fit(pts=points,thresh=0.05,max_iterations=1000,iterations_per_batch=100,epsilon=1e-8,device=torch.device("cuda"iftorch.cuda.is_available()else"cpu"))print(f"Plane equation:{result.equation}")# [a, b, c, d] for ax + by + cz + d = 0print(f"Number of inliers:{len(result.inliers)}")
fromtorch_ransac3d.sphereimportsphere_fit# Works with both PyTorch tensors and NumPy arrayspoints=torch.rand(1000,3)# or np.random.rand(1000, 3)result=sphere_fit(pts=points,thresh=0.05,max_iterations=1000,iterations_per_batch=100,epsilon=1e-8,device=torch.device("cuda"iftorch.cuda.is_available()else"cpu"))print(f"Center:{result.center}")print(f"Radius:{result.radius}")print(f"Number of inliers:{len(result.inliers)}")
pts
: Input point cloud (torch.Tensor or numpy.ndarray of shape (N, 3))thresh
: Distance threshold for considering a point as an inliermax_iterations
: Maximum number of RANSAC iterationsiterations_per_batch
: Number of iterations to process in parallelepsilon
: Small value to avoid division by zerodevice
: Torch device to run computations on (CPU or CUDA)
All fitting functions support both PyTorch tensors and NumPy arrays as input. The library automatically converts NumPy arrays to PyTorch tensors internally, allowing for seamless integration with various data formats.
All fitting functions support batch processing to improve performance. Theiterations_per_batch
parameter determines how many RANSAC iterations are processed in parallel, leading to significant speedups on GPU hardware.
This project is based on the work done athttps://github.com/leomariga/pyRANSAC-3D/
@software{Dobbs_torch_ransac3d, author = {Dobbs, Harry}, title = {torch\_ransac3d: A high-performance implementation of 3D RANSAC algorithm using PyTorch and CUDA}, year = {2024}, publisher = {GitHub}, journal = {GitHub repository}, url = {https://github.com/harrydobbs/torch_ransac3d},}
Maintainer: Harry DobbsEmail:harrydobbs87@gmail.com
About
A high-performance implementation of 3D RANSAC (Random Sample Consensus) algorithm using PyTorch and CUDA.