Skip to main content



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

Metadata

Release files for torch-ransac3d 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for torch-ransac3d 2.0.0
File Size Uploaded
torch_ransac3d-2.0.0.tar.gz 31.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for torch-ransac3d 2.0.0
File Interpreter ABI Platform
torch_ransac3d-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 68.8 kB

Release files / torch_ransac3d-2.0.0.tar.gz

Download URL torch_ransac3d-2.0.0.tar.gz
Size 31.2 kB
Tags Source
SHA-256 checksum
How to use checksums
4148e8c17e85ef4926eb4c614eb625d85ef6c31404bb8b14e536e0785a224843
BLAKE2b-256 checksum
How to use checksums
1c161683837975ec6226490e89ed5d08aaf03024a138bebd3c289e1b9d787f5c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 1, 2025.

Transparency log

Release files / torch_ransac3d-2.0.0-py3-none-any.whl

Download URL torch_ransac3d-2.0.0-py3-none-any.whl
Size 37.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
14bdc62a737f6d13b73799c7989721ec72f6a18c7f1e1ed00b229d49882f7aac
BLAKE2b-256 checksum
How to use checksums
891b099669967d45025343d424e72816e2187e2d6459477abf13001c116de1d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 1, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files

1.0.36

2 release files

1.0.35

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page