Skip to main content

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 inlier
  • max_iterations: Maximum number of RANSAC iterations
  • iterations_per_batch: Number of iterations to process in parallel
  • epsilon: Small value to avoid division by zero
  • device: 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

torch_ransac3d-2.0.0.tar.gz (31.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

torch_ransac3d-2.0.0-py3-none-any.whl (37.5 kB view details)

Uploaded Python 3

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

Hashes for torch_ransac3d-2.0.0.tar.gz
Algorithm Hash digest
SHA256 4148e8c17e85ef4926eb4c614eb625d85ef6c31404bb8b14e536e0785a224843
MD5 76bf2bcddb640fd10c904d20c50bf371
BLAKE2b-256 1c161683837975ec6226490e89ed5d08aaf03024a138bebd3c289e1b9d787f5c

See more details on using hashes here.

Provenance

The following attestation bundles were made for torch_ransac3d-2.0.0.tar.gz:

Publisher: publish.yml on harrydobbs/torch_ransac3d

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for torch_ransac3d-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 14bdc62a737f6d13b73799c7989721ec72f6a18c7f1e1ed00b229d49882f7aac
MD5 38c002d01e86dda4d489f7d029fa5cbc
BLAKE2b-256 891b099669967d45025343d424e72816e2187e2d6459477abf13001c116de1d6

See more details on using hashes here.

Provenance

The following attestation bundles were made for torch_ransac3d-2.0.0-py3-none-any.whl:

Publisher: publish.yml on harrydobbs/torch_ransac3d

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page