Skip to content

Commit

Permalink
add code
Browse files Browse the repository at this point in the history
  • Loading branch information
taoranyi committed Oct 16, 2023
1 parent c889693 commit 2e4fed3
Show file tree
Hide file tree
Showing 1,542 changed files with 129 additions and 267,799 deletions.
2 changes: 1 addition & 1 deletion GaussianDreamer.ipynb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"cells":[{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":599,"status":"ok","timestamp":1697455927064,"user":{"displayName":"Taoran Yi","userId":"07510823077200585758"},"user_tz":-480},"id":"olxFPUSKQPVZ","outputId":"e6c743e2-a0f5-4935-a22d-3246686f0d7b"},"outputs":[],"source":["!nvidia-smi"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":13738,"status":"ok","timestamp":1697455896350,"user":{"displayName":"Taoran Yi","userId":"07510823077200585758"},"user_tz":-480},"id":"McvSStODwmVw","outputId":"2dedea00-c7a6-4231-c65f-7d34ed64d903"},"outputs":[],"source":["!pip install torch torchvision --index-url https://download.pytorch.org/whl/cu118\n","!pip install ninja\n","!pip install -r requirements.txt"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":20448,"status":"ok","timestamp":1697456095928,"user":{"displayName":"Taoran Yi","userId":"07510823077200585758"},"user_tz":-480},"id":"AYQ-gj7CQOb_","outputId":"1c5a2ac4-d44a-413a-a581-9aacee147b3c"},"outputs":[],"source":["!git clone https://github.com/hustvl/GaussianDreamer.git\n","%cd GaussianDreamer\n","!pip install ./gaussiansplatting/submodules/diff-gaussian-rasterization\n","!pip install ./gaussiansplatting/submodules/simple-knn\n","!git clone https://github.com/openai/shap-e.git\n","!pip install -e ."]},{"cell_type":"code","execution_count":null,"metadata":{"id":"FTdmevtfRMr8"},"outputs":[],"source":["!python launch.py --config configs/gaussiandreamer-sd.yaml --train --gpu 0 system.prompt_processor.prompt=\"a fox\""]}],"metadata":{"colab":{"authorship_tag":"ABX9TyP+O8fnJmfV9hLdba4QgwEh","provenance":[]},"kernelspec":{"display_name":"Python 3","name":"python3"},"language_info":{"name":"python"}},"nbformat":4,"nbformat_minor":0}
{"cells":[{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":599,"status":"ok","timestamp":1697455927064,"user":{"displayName":"Taoran Yi","userId":"07510823077200585758"},"user_tz":-480},"id":"olxFPUSKQPVZ","outputId":"e6c743e2-a0f5-4935-a22d-3246686f0d7b"},"outputs":[],"source":["!nvidia-smi"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":13738,"status":"ok","timestamp":1697455896350,"user":{"displayName":"Taoran Yi","userId":"07510823077200585758"},"user_tz":-480},"id":"McvSStODwmVw","outputId":"2dedea00-c7a6-4231-c65f-7d34ed64d903"},"outputs":[],"source":["!pip install torch torchvision --index-url https://download.pytorch.org/whl/cu118\n","!pip install ninja"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":20448,"status":"ok","timestamp":1697456095928,"user":{"displayName":"Taoran Yi","userId":"07510823077200585758"},"user_tz":-480},"id":"AYQ-gj7CQOb_","outputId":"1c5a2ac4-d44a-413a-a581-9aacee147b3c"},"outputs":[],"source":["!git clone https://github.com/hustvl/GaussianDreamer.git\n","%cd GaussianDreamer\n","!pip install -r requirements.txt\n","!pip install ./gaussiansplatting/submodules/diff-gaussian-rasterization\n","!pip install ./gaussiansplatting/submodules/simple-knn\n","!git clone https://github.com/openai/shap-e.git\n","!pip install -e ."]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"FTdmevtfRMr8"},"outputs":[],"source":["!python launch.py --config configs/gaussiandreamer-sd.yaml --train --gpu 0 system.prompt_processor.prompt=\"a fox\""]}],"metadata":{"colab":{"authorship_tag":"ABX9TyP+O8fnJmfV9hLdba4QgwEh","provenance":[]},"kernelspec":{"display_name":"Python 3","name":"python3"},"language_info":{"name":"python"}},"nbformat":4,"nbformat_minor":0}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ In recent times, the generation of 3D assets from text prompts has shown impress

## 🏁 Get Started
**Installation**

Install [3D Gaussian Splatting](https://github.com/graphdeco-inria/gaussian-splatting) and [Shap-E](https://github.com/openai/shap-e#usage) as fellow:
```
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu118
Expand All @@ -36,6 +35,8 @@ pip install ./gaussiansplatting/submodules/simple-knn
git clone https://github.com/openai/shap-e.git
pip install -e .
```
Download [finetuned Shap-E](https://huggingface.co/datasets/tiange/Cap3D/tree/main/our_finetuned_models) by Cap3D, and put it in `./load`

**Quickstart**
```
python launch.py --config configs/gaussiandreamer-sd.yaml --train --gpu 0 system.prompt_processor.prompt="a fox"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ add_library(CudaRasterizer
cuda_rasterizer/rasterizer.h
)

set_target_properties(CudaRasterizer PROPERTIES CUDA_ARCHITECTURES "75;86")
set_target_properties(CudaRasterizer PROPERTIES CUDA_ARCHITECTURES "70;75;86")

target_include_directories(CudaRasterizer PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/cuda_rasterizer)
target_include_directories(CudaRasterizer PRIVATE third_party/glm ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
Gaussian-Splatting License
===========================

**Inria** and **the Max Planck Institut for Informatik (MPII)** hold all the ownership rights on the *Software* named **gaussian-splatting**.
The *Software* is in the process of being registered with the Agence pour la Protection des
Programmes (APP).

The *Software* is still being developed by the *Licensor*.

*Licensor*'s goal is to allow the research community to use, test and evaluate
the *Software*.

## 1. Definitions

*Licensee* means any person or entity that uses the *Software* and distributes
its *Work*.

*Licensor* means the owners of the *Software*, i.e Inria and MPII

*Software* means the original work of authorship made available under this
License ie gaussian-splatting.

*Work* means the *Software* and any additions to or derivative works of the
*Software* that are made available under this License.


## 2. Purpose
This license is intended to define the rights granted to the *Licensee* by
Licensors under the *Software*.

## 3. Rights granted

For the above reasons Licensors have decided to distribute the *Software*.
Licensors grant non-exclusive rights to use the *Software* for research purposes
to research users (both academic and industrial), free of charge, without right
to sublicense.. The *Software* may be used "non-commercially", i.e., for research
and/or evaluation purposes only.

Subject to the terms and conditions of this License, you are granted a
non-exclusive, royalty-free, license to reproduce, prepare derivative works of,
publicly display, publicly perform and distribute its *Work* and any resulting
derivative works in any form.

## 4. Limitations

**4.1 Redistribution.** You may reproduce or distribute the *Work* only if (a) you do
so under this License, (b) you include a complete copy of this License with
your distribution, and (c) you retain without modification any copyright,
patent, trademark, or attribution notices that are present in the *Work*.

**4.2 Derivative Works.** You may specify that additional or different terms apply
to the use, reproduction, and distribution of your derivative works of the *Work*
("Your Terms") only if (a) Your Terms provide that the use limitation in
Section 2 applies to your derivative works, and (b) you identify the specific
derivative works that are subject to Your Terms. Notwithstanding Your Terms,
this License (including the redistribution requirements in Section 3.1) will
continue to apply to the *Work* itself.

**4.3** Any other use without of prior consent of Licensors is prohibited. Research
users explicitly acknowledge having received from Licensors all information
allowing to appreciate the adequacy between of the *Software* and their needs and
to undertake all necessary precautions for its execution and use.

**4.4** The *Software* is provided both as a compiled library file and as source
code. In case of using the *Software* for a publication or other results obtained
through the use of the *Software*, users are strongly encouraged to cite the
corresponding publications as explained in the documentation of the *Software*.

## 5. Disclaimer

THE USER CANNOT USE, EXPLOIT OR DISTRIBUTE THE *SOFTWARE* FOR COMMERCIAL PURPOSES
WITHOUT PRIOR AND EXPLICIT CONSENT OF LICENSORS. YOU MUST CONTACT INRIA FOR ANY
UNAUTHORIZED USE: [email protected] . ANY SUCH ACTION WILL
CONSTITUTE A FORGERY. THIS *SOFTWARE* IS PROVIDED "AS IS" WITHOUT ANY WARRANTIES
OF ANY NATURE AND ANY EXPRESS OR IMPLIED WARRANTIES, WITH REGARDS TO COMMERCIAL
USE, PROFESSIONNAL USE, LEGAL OR NOT, OR OTHER, OR COMMERCIALISATION OR
ADAPTATION. UNLESS EXPLICITLY PROVIDED BY LAW, IN NO EVENT, SHALL INRIA OR THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES, LOSS OF USE, DATA, OR PROFITS OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING FROM, OUT OF OR
IN CONNECTION WITH THE *SOFTWARE* OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE*.
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Differential Gaussian Rasterization

Used as the rasterization engine for the paper "3D Gaussian Splatting for Real-Time Rendering of Radiance Fields". If you can make use of it in your own research, please be so kind to cite us.
This is a forked repository of the rasterization pipeline from the paper "3D Gaussian Splatting for Real-Time Rendering of Radiance Fields". I have made some extensions to it:

- main branch incorporates only the forward pass of depth, which is used for depth visualization.
- 4th-degree: add the 4th degree of SH
- depth: add both the forward and backward pass of depth, which is used for some tasks with depth supervision.
- latest: is the dev branch that contains acc and depth visualization, together with depth backward pass.

<section class="section" id="BibTeX">
<div class="container is-max-desktop content">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,13 @@ renderCUDA(
int W, int H,
const float2* __restrict__ points_xy_image,
const float* __restrict__ features,
const float* __restrict__ depths,
const float4* __restrict__ conic_opacity,
float* __restrict__ final_T,
uint32_t* __restrict__ n_contrib,
const float* __restrict__ bg_color,
float* __restrict__ out_color)
float* __restrict__ out_color,
float* __restrict__ out_depth)
{
// Identify current tile and associated min/max pixel range.
auto block = cg::this_thread_block();
Expand Down Expand Up @@ -301,6 +303,7 @@ renderCUDA(
uint32_t contributor = 0;
uint32_t last_contributor = 0;
float C[CHANNELS] = { 0 };
float D = { 0 };

// Iterate over batches until all done or range is complete
for (int i = 0; i < rounds; i++, toDo -= BLOCK_SIZE)
Expand Down Expand Up @@ -353,6 +356,7 @@ renderCUDA(
// Eq. (3) from 3D Gaussian splatting paper.
for (int ch = 0; ch < CHANNELS; ch++)
C[ch] += features[collected_id[j] * CHANNELS + ch] * alpha * T;
D += depths[collected_id[j]] * alpha * T;

T = test_T;

Expand All @@ -370,6 +374,7 @@ renderCUDA(
n_contrib[pix_id] = last_contributor;
for (int ch = 0; ch < CHANNELS; ch++)
out_color[ch * H * W + pix_id] = C[ch] + T * bg_color[ch];
out_depth[pix_id] = D;
}
}

Expand All @@ -380,23 +385,27 @@ void FORWARD::render(
int W, int H,
const float2* means2D,
const float* colors,
const float* depths,
const float4* conic_opacity,
float* final_T,
uint32_t* n_contrib,
const float* bg_color,
float* out_color)
float* out_color,
float* out_depth)
{
renderCUDA<NUM_CHANNELS> << <grid, block >> > (
ranges,
point_list,
W, H,
means2D,
colors,
depths,
conic_opacity,
final_T,
n_contrib,
bg_color,
out_color);
out_color,
out_depth);
}

void FORWARD::preprocess(int P, int D, int M,
Expand Down Expand Up @@ -452,4 +461,4 @@ void FORWARD::preprocess(int P, int D, int M,
tiles_touched,
prefiltered
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@ namespace FORWARD
int W, int H,
const float2* points_xy_image,
const float* features,
const float* depths,
const float4* conic_opacity,
float* final_T,
uint32_t* n_contrib,
const float* bg_color,
float* out_color);
float* out_color,
float* out_depth);
}


#endif
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ namespace CudaRasterizer
const float tan_fovx, float tan_fovy,
const bool prefiltered,
float* out_color,
float* out_depth,
int* radii = nullptr,
bool debug = false);

Expand Down Expand Up @@ -85,4 +86,4 @@ namespace CudaRasterizer
};
};

#endif
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ int CudaRasterizer::Rasterizer::forward(
const float tan_fovx, float tan_fovy,
const bool prefiltered,
float* out_color,
float* out_depth,
int* radii,
bool debug)
{
Expand Down Expand Up @@ -326,11 +327,13 @@ int CudaRasterizer::Rasterizer::forward(
width, height,
geomState.means2D,
feature_ptr,
geomState.depths,
geomState.conic_opacity,
imgState.accum_alpha,
imgState.n_contrib,
background,
out_color), debug)
out_color,
out_depth), debug)

return num_rendered;
}
Expand Down Expand Up @@ -431,4 +434,4 @@ void CudaRasterizer::Rasterizer::backward(
dL_dsh,
(glm::vec3*)dL_dscale,
(glm::vec4*)dL_drot), debug)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,22 @@ def forward(
if raster_settings.debug:
cpu_args = cpu_deep_copy_tuple(args) # Copy them before they can be corrupted
try:
num_rendered, color, radii, geomBuffer, binningBuffer, imgBuffer = _C.rasterize_gaussians(*args)
num_rendered, color, depth, radii, geomBuffer, binningBuffer, imgBuffer = _C.rasterize_gaussians(*args)
except Exception as ex:
torch.save(cpu_args, "snapshot_fw.dump")
print("\nAn error occured in forward. Please forward snapshot_fw.dump for debugging.")
raise ex
else:
num_rendered, color, radii, geomBuffer, binningBuffer, imgBuffer = _C.rasterize_gaussians(*args)
num_rendered, color, depth, radii, geomBuffer, binningBuffer, imgBuffer = _C.rasterize_gaussians(*args)

# Keep relevant tensors for backward
ctx.raster_settings = raster_settings
ctx.num_rendered = num_rendered
ctx.save_for_backward(colors_precomp, means3D, scales, rotations, cov3Ds_precomp, radii, sh, geomBuffer, binningBuffer, imgBuffer)
return color, radii
return color, radii, depth

@staticmethod
def backward(ctx, grad_out_color, _):
def backward(ctx, grad_out_color, grad_radii, grad_depth):

# Restore necessary values from context
num_rendered = ctx.num_rendered
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ std::function<char*(size_t N)> resizeFunctional(torch::Tensor& t) {
return lambda;
}

std::tuple<int, torch::Tensor, torch::Tensor, torch::Tensor, torch::Tensor, torch::Tensor>
std::tuple<int, torch::Tensor, torch::Tensor, torch::Tensor, torch::Tensor, torch::Tensor, torch::Tensor>
RasterizeGaussiansCUDA(
const torch::Tensor& background,
const torch::Tensor& means3D,
Expand Down Expand Up @@ -66,6 +66,7 @@ RasterizeGaussiansCUDA(
auto float_opts = means3D.options().dtype(torch::kFloat32);

torch::Tensor out_color = torch::full({NUM_CHANNELS, H, W}, 0.0, float_opts);
torch::Tensor out_depth = torch::full({1, H, W}, 0.0, float_opts);
torch::Tensor radii = torch::full({P}, 0, means3D.options().dtype(torch::kInt32));

torch::Device device(torch::kCUDA);
Expand Down Expand Up @@ -108,10 +109,11 @@ RasterizeGaussiansCUDA(
tan_fovy,
prefiltered,
out_color.contiguous().data<float>(),
out_depth.contiguous().data<float>(),
radii.contiguous().data<int>(),
debug);
}
return std::make_tuple(rendered, out_color, radii, geomBuffer, binningBuffer, imgBuffer);
return std::make_tuple(rendered, out_color, out_depth, radii, geomBuffer, binningBuffer, imgBuffer);
}

std::tuple<torch::Tensor, torch::Tensor, torch::Tensor, torch::Tensor, torch::Tensor, torch::Tensor, torch::Tensor, torch::Tensor>
Expand Down Expand Up @@ -214,4 +216,4 @@ torch::Tensor markVisible(
}

return present;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <tuple>
#include <string>

std::tuple<int, torch::Tensor, torch::Tensor, torch::Tensor, torch::Tensor, torch::Tensor>
std::tuple<int, torch::Tensor, torch::Tensor, torch::Tensor, torch::Tensor, torch::Tensor, torch::Tensor>
RasterizeGaussiansCUDA(
const torch::Tensor& background,
const torch::Tensor& means3D,
Expand Down Expand Up @@ -64,4 +64,4 @@ std::tuple<torch::Tensor, torch::Tensor, torch::Tensor, torch::Tensor, torch::Te
torch::Tensor markVisible(
torch::Tensor& means3D,
torch::Tensor& viewmatrix,
torch::Tensor& projmatrix);
torch::Tensor& projmatrix);
Loading

0 comments on commit 2e4fed3

Please sign in to comment.