ba-cuda
GPU-accelerated Bundle Adjustment using PyTorch with Analytical Jacobians.
Features
- SE3 Lie Group: Right perturbation convention for camera pose representation
- Analytical Jacobians: Fast and accurate gradient computation
- Batched Operations: Efficient GPU parallelization
- Levenberg-Marquardt Optimizer: Robust non-linear optimization
- Huber Loss: Robust to outliers
Installation
1. Install PyTorch (Required - Manual Installation)
⚠️ Important: PyTorch must be installed manually according to your CUDA version.
-
Check your CUDA version:
nvcc --version -
Install PyTorch from the official website:
For example, with CUDA 12.1:
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
For CUDA 11.8:
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
2. Install ba-cuda
pip install ba-cuda
Or from source:
git clone https://github.com/hunminkim98/BA_on_CUDA_130_Win.git
cd BA_on_CUDA_130_Win
pip install -e .
Quick Start
import torch
from ba_cuda import LevenbergMarquardtOptimizer
# Prepare your data
observations = torch.tensor(...) # (N_obs, 2) - 2D observations
points_3d = torch.tensor(...) # (N_obs, 3) - 3D points
camera_indices = torch.tensor(...) # (N_obs,) - camera index per observation
intrinsics = torch.tensor(...) # (N_cams, 3, 3)
distortions = torch.tensor(...) # (N_cams, 5)
initial_poses = torch.tensor(...) # (N_cams, 3, 4) - [R|t]
# Run optimization
optimizer = LevenbergMarquardtOptimizer()
optimized_poses, rmse = optimizer.optimize(
observations=observations,
points_3d=points_3d,
camera_indices=camera_indices,
intrinsics=intrinsics,
distortions=distortions,
initial_poses=initial_poses,
ref_cam_idx=0
)
print(f"Final RMSE: {rmse:.4f}")
API Reference
LevenbergMarquardtOptimizer
optimizer = LevenbergMarquardtOptimizer(
max_iterations=50, # Maximum LM iterations
abs_tolerance=1e-6, # Absolute convergence tolerance
rel_tolerance=1e-6, # Relative convergence tolerance
initial_damping=1e-3, # Initial LM damping factor
huber_delta=1.0, # Huber loss delta
device=None, # torch.device (auto-detects CUDA if available)
dtype=torch.float64 # Precision
)
Input Tensor Formats
| Tensor | Shape | Description |
|---|---|---|
observations |
(N_obs, 2) | 2D keypoint observations (u, v) |
points_3d |
(N_obs, 3) | 3D points in reference camera frame |
camera_indices |
(N_obs,) | Camera index for each observation |
intrinsics |
(N_cams, 3, 3) | Camera intrinsic matrices K |
distortions |
(N_cams, 5) | Distortion coefficients [k1, k2, p1, p2, k3] |
initial_poses |
(N_cams, 3, 4) | Initial camera poses [R |
Requirements
- Python >= 3.10
- PyTorch >= 2.0.0 (with CUDA support recommended)
- NumPy >= 1.20.0
License
MIT License
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ba_cuda-0.1.0.tar.gz
(11.2 kB
view details)
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
ba_cuda-0.1.0-py3-none-any.whl
(10.1 kB
view details)
File details
Details for the file ba_cuda-0.1.0.tar.gz.
File metadata
- Download URL: ba_cuda-0.1.0.tar.gz
- Upload date:
- Size: 11.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
550d8941b88a82228a4444851c927e2e5fc1eed56fc6fa15e7593773aefb5c80
|
|
| MD5 |
985a8e23ab70386d9ca5d89e8adc61ea
|
|
| BLAKE2b-256 |
0bf0f18e3ebdb0a2f4713677ef013c49fb07a451dcec3cadcb3976e95f1bced7
|
File details
Details for the file ba_cuda-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ba_cuda-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e531d584bf2aec61bdf251d5e908d0fa9ec2a7319a5b41a4693bc4066f715366
|
|
| MD5 |
c0215b3b4c73a15c994011f4240114af
|
|
| BLAKE2b-256 |
97bccc834cee5eb3d5b50ea607ae92ca8733e1a687b974271e409c294d6db258
|