A high-performance implementation of 3D RANSAC (Random Sample Consensus) algorithm using PyTorch and CUDA.
Project description
A high-performance implementation of 3D RANSAC algorithm using PyTorch and CUDA.
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
Installation
Requirements: torch, numpy
Install with PyPI :
pip install torch-ransac3d
Features
- 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
Example Usage
Line Fitting
import torch
import numpy as np
from torch_ransac3d.line import line_fit
# Using PyTorch tensor
points_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" if torch.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 array
points_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" if torch.cuda.is_available() else "cpu")
)
Plane Fitting
from torch_ransac3d.plane import plane_fit
# Works with both PyTorch tensors and NumPy arrays
points = 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" if torch.cuda.is_available() else "cpu")
)
print(f"Plane equation: {result.equation}") # [a, b, c, d] for ax + by + cz + d = 0
print(f"Number of inliers: {len(result.inliers)}")
Sphere Fitting
from torch_ransac3d.sphere import sphere_fit
# Works with both PyTorch tensors and NumPy arrays
points = 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" if torch.cuda.is_available() else "cpu")
)
print(f"Center: {result.center}")
print(f"Radius: {result.radius}")
print(f"Number of inliers: {len(result.inliers)}")
Parameters
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)
Input Flexibility
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.
Batch Processing
All fitting functions support batch processing to improve performance. The iterations_per_batch parameter determines how many RANSAC iterations are processed in parallel, leading to significant speedups on GPU hardware.
Credit
This project is based on the work done at https://github.com/leomariga/pyRANSAC-3D/
Citation
@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},
}
Contact
Maintainer: Harry Dobbs Email: harrydobbs87@gmail.com
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file torch_ransac3d-2.0.0.tar.gz.
File metadata
- Download URL: torch_ransac3d-2.0.0.tar.gz
- Upload date:
- Size: 31.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4148e8c17e85ef4926eb4c614eb625d85ef6c31404bb8b14e536e0785a224843
|
|
| MD5 |
76bf2bcddb640fd10c904d20c50bf371
|
|
| BLAKE2b-256 |
1c161683837975ec6226490e89ed5d08aaf03024a138bebd3c289e1b9d787f5c
|
Provenance
The following attestation bundles were made for torch_ransac3d-2.0.0.tar.gz:
Publisher:
publish.yml on harrydobbs/torch_ransac3d
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torch_ransac3d-2.0.0.tar.gz -
Subject digest:
4148e8c17e85ef4926eb4c614eb625d85ef6c31404bb8b14e536e0785a224843 - Sigstore transparency entry: 167787351
- Sigstore integration time:
-
Permalink:
harrydobbs/torch_ransac3d@ddc3cd263133051c1fce5d81a10b12ca68890d5b -
Branch / Tag:
refs/tags/v2.0.0 - Owner: https://github.com/harrydobbs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ddc3cd263133051c1fce5d81a10b12ca68890d5b -
Trigger Event:
release
-
Statement type:
File details
Details for the file torch_ransac3d-2.0.0-py3-none-any.whl.
File metadata
- Download URL: torch_ransac3d-2.0.0-py3-none-any.whl
- Upload date:
- Size: 37.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
14bdc62a737f6d13b73799c7989721ec72f6a18c7f1e1ed00b229d49882f7aac
|
|
| MD5 |
38c002d01e86dda4d489f7d029fa5cbc
|
|
| BLAKE2b-256 |
891b099669967d45025343d424e72816e2187e2d6459477abf13001c116de1d6
|
Provenance
The following attestation bundles were made for torch_ransac3d-2.0.0-py3-none-any.whl:
Publisher:
publish.yml on harrydobbs/torch_ransac3d
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torch_ransac3d-2.0.0-py3-none-any.whl -
Subject digest:
14bdc62a737f6d13b73799c7989721ec72f6a18c7f1e1ed00b229d49882f7aac - Sigstore transparency entry: 167787352
- Sigstore integration time:
-
Permalink:
harrydobbs/torch_ransac3d@ddc3cd263133051c1fce5d81a10b12ca68890d5b -
Branch / Tag:
refs/tags/v2.0.0 - Owner: https://github.com/harrydobbs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ddc3cd263133051c1fce5d81a10b12ca68890d5b -
Trigger Event:
release
-
Statement type: