mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-22 23:55:36 +08:00
Tiny-cuda-nn and fixed logic for instant-ngp (#102)
* correcting implementation for instant ngp * instant ngp with tcnn * black and pylint * merged master
This commit is contained in:
1 parent
8cc4c063df
commit
7d8beaaed4
17 files changed
+477
-43
No files matched your search
@@ -0,0 +1,42 @@
|
||||
"""
|
||||
Test the fields
|
||||
"""
|
||||
import torch
|
||||
|
||||
from mattport.nerf.field_modules.field_heads import FieldHeadNames
|
||||
from mattport.nerf.fields.instant_ngp_field import TCNNInstantNGPField
|
||||
from mattport.structures.rays import PointSamples
|
||||
|
||||
|
||||
def test_tcnn_instant_ngp_field():
|
||||
"""Test the tiny-cuda-nn field"""
|
||||
# pylint: disable=import-outside-toplevel
|
||||
# pylint: disable=unused-import
|
||||
try:
|
||||
import tinycudann as tcnn
|
||||
except ImportError as e:
|
||||
# tinycudann module doesn't exist
|
||||
print(e)
|
||||
return
|
||||
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
||||
aabb_scale = 1.0
|
||||
aabb = torch.tensor(
|
||||
[[-aabb_scale, -aabb_scale, -aabb_scale], [aabb_scale, aabb_scale, aabb_scale]], dtype=torch.float32
|
||||
).to(device)
|
||||
field = TCNNInstantNGPField(aabb)
|
||||
num_rays = 1024
|
||||
num_samples = 256
|
||||
positions = torch.rand((num_rays, num_samples, 3), dtype=torch.float32, device=device)
|
||||
directions = torch.rand_like(positions)
|
||||
point_samples = PointSamples(positions=positions, directions=directions)
|
||||
field_outputs = field.forward(point_samples)
|
||||
|
||||
positions_dtype = positions.dtype
|
||||
field_outputs_density_dtype = field_outputs[FieldHeadNames.DENSITY].dtype
|
||||
assert (
|
||||
positions_dtype == field_outputs_density_dtype
|
||||
), f"The input and output dtypes do not match: {positions_dtype} vs. {field_outputs_density_dtype}"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_tcnn_instant_ngp_field()
|
||||
Reference in new issue
Block a user