Skip to main content

A CUDA-enhanced package for common NeRF model operations

Project description

nerfboost

nerfboost is a CUDA-accelerated Python package that enhances common operations required for Neural Radiance Fields (NeRF) models. It provides high-performance implementations of key functions such as positional encoding, stratified sampling, volume rendering, and more, to accelerate NeRF training and rendering.

Features

  • CUDA-accelerated functions for efficient neural rendering tasks.
  • Implements key operations for NeRF models like:
    • Positional encoding
    • Stratified, uniform, hierarchical, and inverse sampling
    • Volume rendering
    • MLP network processing
    • Rendering loss computation
    • Ray generation
  • Easy integration with PyTorch using custom CUDA kernels.

Prerequisites

Ensure PyTorch is installed.

You can install Torch using the following command:

pip install torch

Installation

You can install nerfboost using the following command:

pip install nerfboost

Usage

Initialization

import nerfboost

Positional encoding

The positional encoding transforms input coordinates into a higher-dimensional space, crucial for NeRF models.

x = torch.randn(10, 3)  # Input coordinates (e.g., 10 points in 3D space)
L = 10  # Number of encoding frequencies
encoded_positions = nerfboost.positional_encoding_cuda(x, L)

Stratified and Uniform Sampling

Stratified sampling generates sample points along a ray between near and far planes: Uniform sampling generates evenly spaced samples between near and far planes:

near = 0.1
far = 4.0
num_samples = 64
stratified_samples = nerfboost.stratified_sampling_cuda(near, far, num_samples)
unifrom_samples = nerfboost.uniform_sampling_cuda(near, far, num_samples)

Hierarchical Sampling

Refines samples based on coarse predictions:

coarse_samples = torch.randn(num_samples)  # Coarse samples from the network
weights = torch.randn(num_samples)  # Corresponding weights
num_fine_samples = 128
fine_samples = nerfboost.hierarchical_sampling_cuda(coarse_samples, weights, num_fine_samples)

Inverse Transform Sampling

Generates samples using inverse transform sampling based on the given probability distribution:

weights = torch.rand(64)  # Probability distribution
num_samples = 128
samples = nerfboost.inverse_transform_sampling_cuda(weights, num_samples)

Volume Rendering

Computes the final color and density for each ray based on input densities, colors, and distances:

densities = torch.rand(64)  # Density for each sample
colors = torch.rand(64, 3)  # RGB color for each sample
distances = torch.rand(64)  # Distance along the ray
final_colors = nerfboost.volume_rendering_cuda(densities, colors, distances)

MLP Network Processing

Processes sampled points through a multi-layer perceptron (MLP) network:

sampled_points = torch.randn(64, 3)  # Points sampled along the rays
directions = torch.randn(64, 3)  # Ray directions
weights = [torch.randn(3, 64), torch.randn(64, 64), torch.randn(64, 3)]  # MLP weights
output = nerfboost.mlp_network_cuda(sampled_points, directions, weights)

Rendering Loss (MSE)

Computes the mean squared error (MSE) between the rendered image and the ground truth image:

rendered_image = torch.rand(256, 256, 3)  # Rendered output
ground_truth_image = torch.rand(256, 256, 3)  # Ground truth image
loss = nerfboost.rendering_loss_cuda(rendered_image, ground_truth_image)

Ray Generation

Generates rays for rendering using the camera intrinsics and resolution:

camera_intrinsics = torch.rand(3, 3)  # Camera intrinsic matrix
H = 256  # Image height
W = 256  # Image width
origins, directions = nerfboost.generate_rays_cuda(camera_intrinsics, H, W)

License

This project is licensed under the MIT License.

Author

Akshay Pappu

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

nerfboost-0.0.4.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

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

nerfboost-0.0.4-cp311-cp311-win_amd64.whl (570.4 kB view details)

Uploaded CPython 3.11Windows x86-64

File details

Details for the file nerfboost-0.0.4.tar.gz.

File metadata

  • Download URL: nerfboost-0.0.4.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.5

File hashes

Hashes for nerfboost-0.0.4.tar.gz
Algorithm Hash digest
SHA256 0d651a3afa7e2b7be24364b72797b1e9c9f933e174aa81b7767f492c462e7aa2
MD5 6f2cf2f74111aa911daff32028cad296
BLAKE2b-256 f966f02cd4c690be79ee7c378b760508bb7a429beda0b7ea1e1ee478d114a036

See more details on using hashes here.

File details

Details for the file nerfboost-0.0.4-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: nerfboost-0.0.4-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 570.4 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.5

File hashes

Hashes for nerfboost-0.0.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 d90c7fb5f20ff91c61548107d2d3d26089d114b8728c5452db90228370a1b2fb
MD5 b9cc80e921838816c65e24ca0d3febc5
BLAKE2b-256 76a5bc980d80e7ea2e8c594926a6d671f43420f0334cc5f6a0bd81801d524cee

See more details on using hashes here.

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