Config restructure (#283)

* starting docs for pipelines

* working on an example

* clearing output

* starting to implement config changes and add documentation

* wip: removed cicular imports; porting basic config into python; todo: get python setups workin

* circular imports again

* wip: pausing at dataloader sort of working

* break for today

* running vanilla

* wip need to get all the config docs working

* laptop about to die

* instant ngp working

* added all configs for all methods; not tested yet: [mipnerf360, nerfw, semantic_nerf]

* unpacking later

* done with pylinting

* mostly done. just need to do docs and one test

* added import order to docs

* fixing near/far plane and other config things

* making loggers also instantiable via configs

* docs

* lint

* making --help work with dcargs

* moving configs back into flat

* convert list to tuples; fixed post init function with mutable params

* lint

* made run_eval and benchmarking scripts compatible with new config/dcargs

* lint

* added option to load configs from presaved config

Co-authored-by: evonneng <evonne_ng@berkeley.edu>
This commit is contained in:
Ethan Weberandevonneng authored and GitHub committed 2022-08-26 17:25:10 -07:00
1 parent e0856e3afc
commit 7e9a56fac4
46 files changed
+987 -916

No files matched your search

+13 -14
View File
@@ -16,18 +16,22 @@
NeRF-W (NeRF in the wild) implementation.
"""
from __future__ import annotations
import torch
from torchmetrics import PeakSignalNoiseRatio
from torchmetrics.functional import structural_similarity_index_measure
from torchmetrics.image.lpip import LearnedPerceptualImagePatchSimilarity
from nerfactory.cameras.rays import RayBundle
from nerfactory.configs import base as cfg
from nerfactory.fields.modules.encoding import NeRFEncoding
from nerfactory.fields.modules.field_heads import FieldHeadNames
from nerfactory.fields.nerf_field import NeRFField
from nerfactory.fields.nerfw_field import VanillaNerfWField
from nerfactory.models.base import Model
from nerfactory.models.modules.ray_sampler import PDFSampler, UniformSampler
from nerfactory.models.modules.scene_colliders import AABBBoxCollider
from nerfactory.optimizers.loss import MSELoss
from nerfactory.renderers.renderers import (
AccumulationRenderer,
@@ -43,11 +47,7 @@ class NerfWModel(Model):
def __init__(
self,
near_plane=2.0,
far_plane=6.0,
num_coarse_samples=64,
num_importance_samples=64,
uncertainty_min=0.03,
config: cfg.NerfWModelConfig,
**kwargs,
) -> None:
"""A NeRF-W model.
@@ -59,17 +59,12 @@ class NerfWModel(Model):
This avoids calling torch.log() on a zero value, which would be undefined.
Defaults to 0.03.
"""
self.near_plane = near_plane
self.far_plane = far_plane
self.num_coarse_samples = num_coarse_samples
self.num_importance_samples = num_importance_samples
self.uncertainty_min = uncertainty_min
self.field_coarse = None
self.field_fine = None
self.num_images = 10000 # TODO(ethan): fix this
self.appearance_embedding_dim = 48
self.transient_embedding_dim = 16
super().__init__(**kwargs)
super().__init__(config=config, **kwargs)
def populate_fields(self):
"""Set the fields."""
@@ -92,8 +87,8 @@ class NerfWModel(Model):
def populate_misc_modules(self):
# samplers
self.sampler_uniform = UniformSampler(num_samples=self.num_coarse_samples)
self.sampler_pdf = PDFSampler(num_samples=self.num_importance_samples)
self.sampler_uniform = UniformSampler(num_samples=self.config.num_coarse_samples)
self.sampler_pdf = PDFSampler(num_samples=self.config.num_importance_samples)
# renderers
self.renderer_rgb = RGBRenderer(background_color=colors.BLACK)
@@ -109,6 +104,10 @@ class NerfWModel(Model):
self.ssim = structural_similarity_index_measure
self.lpips = LearnedPerceptualImagePatchSimilarity()
# colliders
if self.config.enable_collider:
self.collider = AABBBoxCollider(scene_bounds=self.scene_bounds)
def get_param_groups(self):
param_groups = {}
if self.field_coarse is None or self.field_fine is None:
@@ -176,7 +175,7 @@ class NerfWModel(Model):
# uncertainty
uncertainty = self.renderer_uncertainty(field_outputs_fine[FieldHeadNames.UNCERTAINTY], weights_fine_transient)
uncertainty += self.uncertainty_min
uncertainty += self.config.uncertainty_min
outputs = {
"rgb_coarse": rgb_coarse, # (num_rays, 3)