graphdeco-inria / reduced-3dgs

The code for the paper "Reducing the Memory Footprint of 3D Gaussian Splatting"
Other
96 stars 6 forks source link

Reducing the Memory Footprint of 3D Gaussian Splatting

Panagiotis Papantonakis Georgios Kopanas, Bernhard Kerbl, Alexandre Lanvin, George Drettakis
| Webpage | Full Paper | Datasets (TODO) | Video | Other GRAPHDECO Publications | FUNGRAPH project page |
Teaser image

This repository contains the code of the paper "Reducing the Memory Footprint of 3D Gaussian Splatting", which can be found here. We also provide the configurations to train the models mentioned in the paper, as well as the evaluation script that produces the results.

Abstract: 3D Gaussian splatting provides excellent visual quality for novel view synthesis, with fast training and real-time rendering; unfortunately, the memory requirements of this method for storing and transmission are unreasonably high. We first analyze the reasons for this, identifying three main areas where storage can be reduced: the number of 3D Gaussian primitives used to represent a scene, the number of coefficients for the spherical harmonics used to represent directional radiance, and the precision required to store Gaussian primitive attributes. We present a solution to each of these issues. First, we propose an efficient, resolution-aware primitive pruning approach, reducing the primitive count by half. Second, we introduce an adaptive adjustment method to choose the number of coefficients used to represent directional radiance for each Gaussian primitive, and finally a codebook-based quantization method, together with a half-float representation for further memory reduction. Taken together, these three components result in a ×27 reduction in overall size on disk on the standard datasets we tested, along with a ×1.7 speedup in rendering speed. We demonstrate our method on standard datasets and show how our solution results in significantly reduced download times when using the method on a mobile device

BibTeX

@Article{papantonakisReduced3DGS,
      author       = {Papantonakis, Panagiotis and Kopanas, Georgios and Kerbl, Bernhard and Lanvin, Alexandre and Drettakis, George},
      title        = {Reducing the Memory Footprint of 3D Gaussian Splatting},
      journal      = {Proceedings of the ACM on Computer Graphics and Interactive Techniques},
      number       = {1},
      volume       = {7},
      month        = {May},
      year         = {2024},
      url          = {https://repo-sam.inria.fr/fungraph/reduced_3dgs/}
}

Funding and Acknowledgments

This research was funded by the ERC Advanced grant FUNGRAPH No 788065. The authors are grateful to Adobe for generous donations, the OPAL infrastructure from Université Côte d’Azur and for the HPC resources from GENCI–IDRIS (Grant 2022-AD011013409).

Cloning the Repository

The repository contains submodules, thus please check it out with

# SSH
git clone git@github.com:graphdeco-inria/reduced-3dgs.git --recursive

or

# HTTPS
git clone https://github.com/graphdeco-inria/reduced-3dgs --recursive

Overview

The codebase consists an extension to the original 3DGS project that you can find here. This project builts on top of the previous one, so almost all of the functionality of the original code exists to this one, with one major exception. In this project the point cloud .ply format is altered in a way that it is no longer compatible to the old one. There is included a detailed explanation of the differences later on this README and also there is provided a script that converts the point clouds from the old to the new format.

This README contains the instructions on how to setup and run the code, taken directly from the orinal project, modified accordingly to the needs of this project, wherever it is necessary.

PLY Format

The use of the train.py will result in a point cloud that is stored in a .ply format. Before the layout of this file was one row per primitive, that contained a series of parameters, namely

The normal parameters were a burden, as they were not used anywhere in the algorithm.

In this project, apart from removing these 3, unused normal parameters, we introduce these 3 changes:

Multiple Point Clouds

With our SH culling technique we end up with sets of primitives that have a different number of SH coefficients. So, we group primitives based on the SH bands they use and store only the coefficients that are used. The SH coefficients are placed in the same place as before (after the DC colour and before opacity). The point clouds are stored one after the other, with an increasing number of SH band. That is, if we have a converged model with N_i = number of primitives that have i SH bands (i being 0, 1, ..., max_sh_degree), the first N_0 rows of the .ply file will contain no SH coefficients, the next N_1 rows will contain 9, the next N_2 rows will contain 9 + 15 = 24 and the final N_3 rows will contain 9 + 15 + 21 = 45.

We provide a script that converts the previous .ply files to this new format, by creating a file that has 0 primitives in all SH bands except the final one.

To run the optimizer, simply use

python update_old_ply_format.py -p <path of the ply file to convert> -n <name of the new, converted ply file>
Command Line Arguments for update_old_ply_format.py #### --path / -p Path of the ply file to convert #### --model_path / -m #### --name / -n Name of the newly created point cloud #### --max_sh_order Max order of SH bands. 0 if just DC colour, 1 if 3 coefficients per channel etc.


Codebook

The codebook quantization induces some additional changes. First of all, since we are using 256 entries for each quantized parameter, we store only an 8-bit unsigned int for each one of them. Secondly, we add the codebook entries at the bottom of the .ply file as rows containing 1 entry of each codebook (256 rows in total). The codebooks are ordered as follows:

So, the nth row will contain the nth entry of the above codebooks, in the given order.

Half-float Quantization

If the half-float quantization has been employed, the codebook entries as well as the position parameters are stored in half precision. That means that 16 bits are used instead of 32, and subsequently, float16 are stored instead of float32. However, as the .ply format does not allow for float16 typed numbers, the parameters are pointer casted to int16 and stored as such.

Optimizer

The optimizer uses PyTorch and CUDA extensions in a Python environment to produce trained models.

Hardware Requirements

Software Requirements

Setup

Local Setup

Our default, provided install method is based on Conda package and environment management:

SET DISTUTILS_USE_SDK=1 # Windows only
conda env create --file environment.yml
conda activate gaussian_splatting

Please note that this process assumes that you have CUDA SDK 11 installed, not 12. For modifications, see below.

Tip: Downloading packages and creating a new environment with Conda can require a significant amount of disk space. By default, Conda will use the main system hard drive. You can avoid this by specifying a different package download location and an environment on a different drive:

conda config --add pkgs_dirs <Drive>/<pkg_path>
conda env create --file environment.yml --prefix <Drive>/<env_path>/gaussian_splatting
conda activate <Drive>/<env_path>/gaussian_splatting

Modifications

If you can afford the disk space, we recommend using our environment files for setting up a training environment identical to ours. If you want to make modifications, please note that major version changes might affect the results of our method. However, our (limited) experiments suggest that the codebase works just fine inside a more up-to-date environment (Python 3.8, PyTorch 2.0.0, CUDA 12). Make sure to create an environment where PyTorch and its CUDA runtime version match and the installed CUDA SDK has no major version difference with PyTorch's CUDA version.

Known Issues

Some users experience problems building the submodules on Windows (cl.exe: File not found or similar). Please consider the workaround for this problem from the FAQ.

Running

To run the optimizer, simply use

python train.py -s <path to COLMAP or NeRF Synthetic dataset>
Command Line Arguments for train.py #### --source_path / -s Path to the source directory containing a COLMAP or Synthetic NeRF data set. #### --model_path / -m Path where the trained model should be stored (```output/``` by default). #### --images / -i Alternative subdirectory for COLMAP images (```images``` by default). #### --eval Add this flag to use a MipNeRF360-style training/test split for evaluation. #### --resolution / -r Specifies resolution of the loaded images before training. If provided ```1, 2, 4``` or ```8```, uses original, 1/2, 1/4 or 1/8 resolution, respectively. For all other values, rescales the width to the given number while maintaining image aspect. **If not set and input image width exceeds 1.6K pixels, inputs are automatically rescaled to this target.** #### --data_device Specifies where to put the source image data, ```cuda``` by default, recommended to use ```cpu``` if training on large/high-resolution dataset, will reduce VRAM consumption, but slightly slow down training. Thanks to [HrsPythonix](https://github.com/HrsPythonix). #### --white_background / -w Add this flag to use white background instead of black (default), e.g., for evaluation of NeRF Synthetic dataset. #### --sh_degree Order of spherical harmonics to be used (no larger than 3). ```3``` by default. #### --convert_SHs_python Flag to make pipeline compute forward and backward of SHs with PyTorch instead of ours. #### --convert_cov3D_python Flag to make pipeline compute forward and backward of the 3D covariance with PyTorch instead of ours. #### --debug Enables debug mode if you experience erros. If the rasterizer fails, a ```dump``` file is created that you may forward to us in an issue so we can take a look. #### --debug_from Debugging is **slow**. You may specify an iteration (starting from 0) after which the above debugging becomes active. #### --iterations Number of total iterations to train for, ```30_000``` by default. #### --ip IP to start GUI server on, ```127.0.0.1``` by default. #### --port Port to use for GUI server, ```6009``` by default. #### --test_iterations Space-separated iterations at which the training script computes L1 and PSNR over test set, ```7000 30000``` by default. #### --save_iterations Space-separated iterations at which the training script saves the Gaussian model, ```7000 30000 ``` by default. #### --checkpoint_iterations Space-separated iterations at which to store a checkpoint for continuing later, saved in the model directory. #### --start_checkpoint Path to a saved checkpoint to continue training from. #### --quiet Flag to omit any text written to standard out pipe. #### --feature_lr Spherical harmonics features learning rate, ```0.0025``` by default. #### --opacity_lr Opacity learning rate, ```0.05``` by default. #### --scaling_lr Scaling learning rate, ```0.005``` by default. #### --rotation_lr Rotation learning rate, ```0.001``` by default. #### --position_lr_max_steps Number of steps (from 0) where position learning rate goes from ```initial``` to ```final```. ```30_000``` by default. #### --position_lr_init Initial 3D position learning rate, ```0.00016``` by default. #### --position_lr_final Final 3D position learning rate, ```0.0000016``` by default. #### --position_lr_delay_mult Position learning rate multiplier (cf. Plenoxels), ```0.01``` by default. #### --densify_from_iter Iteration where densification starts, ```500``` by default. #### --densify_until_iter Iteration where densification stops, ```15_000``` by default. #### --densify_grad_threshold Limit that decides if points should be densified based on 2D position gradient, ```0.0002``` by default. #### --densification_interval How frequently to densify, ```100``` (every 100 iterations) by default. #### --opacity_reset_interval How frequently to reset opacity, ```3_000``` by default. #### --lambda_dssim Influence of SSIM on total loss from 0 to 1, ```0.2``` by default. #### --percent_dense Percentage of scene extent (0--1) a point must exceed to be forcibly densified, ```0.01``` by default. #### --lambda_alpha_regul Factor that controls the alpha regularization #### --lambda_sh_sparsity Factor that controls the spherical harmonics regularization #### --mercy_points Enables the additional culling scheme #### --mercy_type Determines the culling scheme used #### --lambda_mercy Factors that controls how many standard deviations from the mean should be filetered for culling #### --box_size Factor that determines the size of the spherical region around each point to calculate the redundancy score #### --mercy_minimum Value of redundancy score under which culling stops #### --prune_dead_points Enables the removal of points that are no longer splatted due to low opacity #### --store_grads Prevents the zero-out of gradients for densified points in densification iterations #### --mercy_interval How many densification cycles pass before culling is performed #### --cdist_threshold Threshold for the colour distance for SH culling #### --std_threshold Threshold on the standard deviation for the SH culling #### --variable_sh_bands Uses the variable SH bands variant rasterizer. USED ONLY FOR INFERENCE


Note that similar to MipNeRF360, we target images at resolutions in the 1-1.6K pixel range. For convenience, arbitrary-size inputs can be passed and will be automatically resized if their width exceeds 1600 pixels. We recommend to keep this behavior, but you may force training to use your higher-resolution images by setting -r 1.

The MipNeRF360 scenes are hosted by the paper authors here. You can find our SfM data sets for Tanks&Temples and Deep Blending here. If you do not provide an output model directory (-m), trained models are written to folders with randomized unique names inside the output directory. At this point, the trained models may be viewed with the real-time viewer (see further below).

Evaluation

By default, the trained models use all available images in the dataset. To train them while withholding a test set for evaluation, use the --eval flag. This way, you can render training/test sets and produce error metrics as follows:

python train.py -s <path to COLMAP or NeRF Synthetic dataset> --eval # Train with train/test split
python render.py -m <path to trained model> # Generate renderings
python metrics.py -m <path to trained model> # Compute error metrics on renderings
Command Line Arguments for render.py #### --model_path / -m Path to the trained model directory you want to create renderings for. #### --skip_train Flag to skip rendering the training set. #### --skip_test Flag to skip rendering the test set. #### --skip_measure_fps Flag to skip calculating fps #### --quiet Flag to omit any text written to standard out pipe. #### --models Types of models to test. Choices between "baseline" and "quantised_half" **The below parameters will be read automatically from the model path, based on what was used for training. However, you may override them by providing them explicitly on the command line.** #### --source_path / -s Path to the source directory containing a COLMAP or Synthetic NeRF data set. #### --images / -i Alternative subdirectory for COLMAP images (```images``` by default). #### --eval Add this flag to use a MipNeRF360-style training/test split for evaluation. #### --resolution / -r Changes the resolution of the loaded images before training. If provided ```1, 2, 4``` or ```8```, uses original, 1/2, 1/4 or 1/8 resolution, respectively. For all other values, rescales the width to the given number while maintaining image aspect. ```1``` by default. #### --white_background / -w Add this flag to use white background instead of black (default), e.g., for evaluation of NeRF Synthetic dataset. #### --convert_SHs_python Flag to make pipeline render with computed SHs from PyTorch instead of ours. #### --convert_cov3D_python Flag to make pipeline render with computed 3D covariance from PyTorch instead of ours.
Command Line Arguments for metrics.py #### --model_paths / -m Space-separated list of model paths for which metrics should be computed.


We further provide the full_eval.py script. This script specifies the routine used in our evaluation and demonstrates the use of some additional parameters, e.g., --images (-i) to define alternative image directories within COLMAP data sets. If you have downloaded and extracted all the training data, you can run it like this:

python full_eval.py -m360 <mipnerf360 folder> -tat <tanks and temples folder> -db <deep blending folder>

In the current version, this process takes about 7h on our reference machine containing an A6000. If you want to do the full evaluation on our pre-trained models, you can specify their download location and skip training.

python full_eval.py -o <directory with pretrained model> --skip_training -m360 <mipnerf360 folder> -tat <tanks and temples folder> -db <deep blending folder>
Command Line Arguments for full_eval.py #### --skip_training Flag to skip training stage. #### --skip_rendering Flag to skip rendering stage. #### --skip_metrics Flag to skip metrics calculation stage. ### --skip_measure_fps Argument passed to render.py to skip FPS measurement #### --output_path Directory to put renderings and results in, ```./eval``` by default, set to pre-trained model location if evaluating them. #### --mipnerf360 / -m360 Path to MipNeRF360 source datasets, required if training or rendering. #### --tanksandtemples / -tat Path to Tanks&Temples source datasets, required if training or rendering. #### --deepblending / -db Path to Deep Blending source datasets, required if training or rendering. ### --experiments / -e Names of experiments that the script will use. Defaults to "full_final" ### --scenes / -s, Names of the scenes that the script will use.


Interactive Viewers

We provide two interactive viewers for our method: remote and real-time. Our viewing solutions are based on the SIBR framework, developed by the GRAPHDECO group for several novel-view synthesis projects.

Hardware Requirements

Software Requirements

Installation from Source

If you cloned with submodules (e.g., using --recursive), the source code for the viewers is found in SIBR_viewers. The network viewer runs within the SIBR framework for Image-based Rendering applications.

Windows

CMake should take care of your dependencies.

cd SIBR_viewers
cmake -Bbuild .
cmake --build build --target install --config RelWithDebInfo

You may specify a different configuration, e.g. Debug if you need more control during development.

Ubuntu 22.04

You will need to install a few dependencies before running the project setup.

# Dependencies
sudo apt install -y libglew-dev libassimp-dev libboost-all-dev libgtk-3-dev libopencv-dev libglfw3-dev libavdevice-dev libavcodec-dev libeigen3-dev libxxf86vm-dev libembree-dev
# Project setup
cd SIBR_viewers
cmake -Bbuild . -DCMAKE_BUILD_TYPE=Release # add -G Ninja to build faster
cmake --build build -j24 --target install

Ubuntu 20.04

Backwards compatibility with Focal Fossa is not fully tested, but building SIBR with CMake should still work after invoking

git checkout fossa_compatibility

Navigation in SIBR Viewers

The SIBR interface provides several methods of navigating the scene. By default, you will be started with an FPS navigator, which you can control with W, A, S, D, Q, E for camera translation and I, K, J, L, U, O for rotation. Alternatively, you may want to use a Trackball-style navigator (select from the floating menu). You can also snap to a camera from the data set with the Snap to button or find the closest camera with Snap to closest. The floating menues also allow you to change the navigation speed. You can use the Scaling Modifier to control the size of the displayed Gaussians, or show the initial point cloud.

Running the Network Viewer

https://github.com/graphdeco-inria/gaussian-splatting/assets/40643808/90a2e4d3-cf2e-4633-b35f-bfe284e28ff7

After extracting or installing the viewers, you may run the compiled SIBR_remoteGaussian_app[_config] app in <SIBR install dir>/bin, e.g.:

./<SIBR install dir>/bin/SIBR_remoteGaussian_app

The network viewer allows you to connect to a running training process on the same or a different machine. If you are training on the same machine and OS, no command line parameters should be required: the optimizer communicates the location of the training data to the network viewer. By default, optimizer and network viewer will try to establish a connection on localhost on port 6009. You can change this behavior by providing matching --ip and --port parameters to both the optimizer and the network viewer. If for some reason the path used by the optimizer to find the training data is not reachable by the network viewer (e.g., due to them running on different (virtual) machines), you may specify an override location to the viewer by using -s <source path>.

Primary Command Line Arguments for Network Viewer #### --path / -s Argument to override model's path to source dataset. #### --ip IP to use for connection to a running training script. #### --port Port to use for connection to a running training script. #### --rendering-size Takes two space separated numbers to define the resolution at which network rendering occurs, ```1200``` width by default. Note that to enforce an aspect that differs from the input images, you need ```--force-aspect-ratio``` too. #### --load_images Flag to load source dataset images to be displayed in the top view for each camera.


Running the Real-Time Viewer

https://github.com/graphdeco-inria/gaussian-splatting/assets/40643808/0940547f-1d82-4c2f-a616-44eabbf0f816

After extracting or installing the viewers, you may run the compiled SIBR_gaussianViewer_app[_config] app in <SIBR install dir>/bin, e.g.:

./<SIBR install dir>/bin/SIBR_gaussianViewer_app -m <path to trained model>

It should suffice to provide the -m parameter pointing to a trained model directory. Alternatively, you can specify an override location for training input data using -s. To use a specific resolution other than the auto-chosen one, specify --rendering-size <width> <height>. Combine it with --force-aspect-ratio if you want the exact resolution and don't mind image distortion.

To unlock the full frame rate, please disable V-Sync on your machine and also in the application (Menu → Display). In a multi-GPU system (e.g., laptop) your OpenGL/Display GPU should be the same as your CUDA GPU (e.g., by setting the application's GPU preference on Windows, see below) for maximum performance.

Teaser image

In addition to the initial point cloud and the splats, you also have the option to visualize the Gaussians by rendering them as ellipsoids from the floating menu. SIBR has many other functionalities, please see the documentation for more details on the viewer, navigation options etc. There is also a Top View (available from the menu) that shows the placement of the input cameras and the original SfM point cloud; please note that Top View slows rendering when enabled. The real-time viewer also uses slightly more aggressive, fast culling, which can be toggled in the floating menu. If you ever encounter an issue that can be solved by turning fast culling off, please let us know.

Primary Command Line Arguments for Real-Time Viewer #### --model-path / -m Path to trained model. #### --iteration Specifies which of state to load if multiple are available. Defaults to latest available iteration. #### --path / -s Argument to override model's path to source dataset. #### --rendering-size Takes two space separated numbers to define the resolution at which real-time rendering occurs, ```1200``` width by default. Note that to enforce an aspect that differs from the input images, you need ```--force-aspect-ratio``` too. #### --load_images Flag to load source dataset images to be displayed in the top view for each camera. #### --device Index of CUDA device to use for rasterization if multiple are available, ```0``` by default. #### --no_interop Disables CUDA/GL interop forcibly. Use on systems that may not behave according to spec (e.g., WSL2 with MESA GL 4.5 software rendering).


Processing your own Scenes

Our COLMAP loaders expect the following dataset structure in the source path location:

<location>
|---images
|   |---<image 0>
|   |---<image 1>
|   |---...
|---sparse
    |---0
        |---cameras.bin
        |---images.bin
        |---points3D.bin

For rasterization, the camera models must be either a SIMPLE_PINHOLE or PINHOLE camera. We provide a converter script convert.py, to extract undistorted images and SfM information from input images. Optionally, you can use ImageMagick to resize the undistorted images. This rescaling is similar to MipNeRF360, i.e., it creates images with 1/2, 1/4 and 1/8 the original resolution in corresponding folders. To use them, please first install a recent version of COLMAP (ideally CUDA-powered) and ImageMagick. Put the images you want to use in a directory <location>/input.

<location>
|---input
    |---<image 0>
    |---<image 1>
    |---...

If you have COLMAP and ImageMagick on your system path, you can simply run

python convert.py -s <location> [--resize] #If not resizing, ImageMagick is not needed

Alternatively, you can use the optional parameters --colmap_executable and --magick_executable to point to the respective paths. Please note that on Windows, the executable should point to the COLMAP .bat file that takes care of setting the execution environment. Once done, <location> will contain the expected COLMAP data set structure with undistorted, resized input images, in addition to your original images and some temporary (distorted) data in the directory distorted.

If you have your own COLMAP dataset without undistortion (e.g., using OPENCV camera), you can try to just run the last part of the script: Put the images in input and the COLMAP info in a subdirectory distorted:

<location>
|---input
|   |---<image 0>
|   |---<image 1>
|   |---...
|---distorted
    |---database.db
    |---sparse
        |---0
            |---...

Then run

python convert.py -s <location> --skip_matching [--resize] #If not resizing, ImageMagick is not needed
Command Line Arguments for convert.py #### --no_gpu Flag to avoid using GPU in COLMAP. #### --skip_matching Flag to indicate that COLMAP info is available for images. #### --source_path / -s Location of the inputs. #### --camera Which camera model to use for the early matching steps, ```OPENCV``` by default. #### --resize Flag for creating resized versions of input images. #### --colmap_executable Path to the COLMAP executable (```.bat``` on Windows). #### --magick_executable Path to the ImageMagick executable.


OpenXR support

OpenXR is supported in the branch gaussian_code_release_openxr Within that branch, you can find documentation for VR support here.

FAQ

Default learning rate result Reduced learning rate result