mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-26 10:59:53 +08:00
compound model (wip) (#427)
* compound model now uses compound field, passing num_images in the config, working on passing image indices through ngp sampler * renaming cuda func, adding torch compound support * removing unused imports * getting num images from dataloader instead of config * fixing pylint and adding todo * undoing base config change * adding cone angle and near plane to compound model config
This commit is contained in:
1 parent
2495cfe1ee
commit
84024a4e73
10 files changed
+170
-31
No files matched your search
@@ -51,11 +51,13 @@ class Model(nn.Module):
|
||||
self,
|
||||
config: cfg.ModelConfig,
|
||||
scene_bounds: SceneBounds,
|
||||
num_train_data: int,
|
||||
**kwargs,
|
||||
) -> None:
|
||||
super().__init__()
|
||||
self.config = config
|
||||
self.scene_bounds = scene_bounds
|
||||
self.num_train_data = num_train_data
|
||||
self.density_field = None
|
||||
self.kwargs = kwargs
|
||||
self.collider = None
|
||||
|
||||
@@ -39,7 +39,7 @@ from torchmetrics.image.lpip import LearnedPerceptualImagePatchSimilarity
|
||||
import nerfactory.cuda as nerfactory_cuda
|
||||
from nerfactory.cameras.rays import RayBundle
|
||||
from nerfactory.configs import base as cfg
|
||||
from nerfactory.fields.instant_ngp_field import field_implementation_to_class
|
||||
from nerfactory.fields.compound_field import field_implementation_to_class
|
||||
from nerfactory.fields.modules.field_heads import FieldHeadNames
|
||||
from nerfactory.models.base import Model
|
||||
from nerfactory.models.modules.ray_sampler import NGPSpacedSampler
|
||||
@@ -84,7 +84,9 @@ class CompoundModel(Model):
|
||||
"""Set the fields and modules."""
|
||||
super().populate_modules()
|
||||
# torch or tiny-cuda-nn version
|
||||
self.field = field_implementation_to_class[self.config.field_implementation](self.scene_bounds.aabb)
|
||||
self.field = field_implementation_to_class[self.config.field_implementation](
|
||||
self.scene_bounds.aabb, self.num_train_data
|
||||
)
|
||||
|
||||
# samplers
|
||||
self.sampler = NGPSpacedSampler(num_samples=self.config.num_samples, density_field=self.density_field)
|
||||
@@ -163,14 +165,14 @@ class CompoundModel(Model):
|
||||
return loss_dict
|
||||
|
||||
def log_test_image_outputs(self, image_idx, step, batch, outputs):
|
||||
image = batch["image"]
|
||||
device = self.device
|
||||
image = batch["image"].to(device)
|
||||
rgb = outputs["rgb"]
|
||||
acc = visualization.apply_colormap(outputs["accumulation"])
|
||||
depth = visualization.apply_depth_colormap(
|
||||
outputs["depth"],
|
||||
accumulation=outputs["accumulation"],
|
||||
)
|
||||
|
||||
combined_rgb = torch.cat([image, rgb], dim=1)
|
||||
combined_acc = torch.cat([acc], dim=1)
|
||||
combined_depth = torch.cat([depth], dim=1)
|
||||
|
||||
@@ -430,10 +430,17 @@ class NGPSpacedSampler(Sampler):
|
||||
starts = starts[:total_samples]
|
||||
ends = ends[:total_samples]
|
||||
|
||||
# return samples
|
||||
assert ray_bundle.camera_indices is not None
|
||||
indices = torch.zeros_like(origins[:, :1], dtype=torch.long)
|
||||
|
||||
ray_bundle.camera_indices = ray_bundle.camera_indices.to(torch.long).to(packed_info.device)
|
||||
|
||||
indices = nerfactory_cuda.get_camera_indices(packed_info, ray_bundle.camera_indices, indices)
|
||||
|
||||
zeros = torch.zeros_like(origins[:, :1])
|
||||
ray_samples = RaySamples(
|
||||
frustums=Frustums(origins=origins, directions=dirs, starts=starts, ends=ends, pixel_area=zeros),
|
||||
camera_indices=indices,
|
||||
)
|
||||
return ray_samples, packed_info, t_min, t_max
|
||||
|
||||
|
||||
Reference in new issue
Block a user