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

+24 -28
View File
@@ -15,24 +15,23 @@
"""
Generic Writer class
"""
from __future__ import annotations
import enum
import os
import sys
import logging
from abc import abstractmethod
from pathlib import Path
from time import time
from typing import Dict
from typing import Dict, Optional
import imageio
import numpy as np
import torch
import wandb
from omegaconf import ListConfig
from torch.utils.tensorboard import SummaryWriter
from torchtyping import TensorType
from nerfactory.utils.config import LoggingConfig
from nerfactory.configs import base as cfg
from nerfactory.utils.decorators import check_main_thread, decorate_all
from nerfactory.utils.misc import human_format
@@ -138,16 +137,13 @@ def write_out_storage():
@check_main_thread
def setup_event_writers(config: LoggingConfig, max_iter: int) -> None:
def setup_event_writers(config: cfg.LoggingConfig, max_iter: int) -> None:
"""Initialization of all event writers specified in config"""
for writer_type in config.writer:
writer_class = getattr(sys.modules[__name__], writer_type)
writer_config = config.writer[writer_type]
if writer_type == "LocalWriter":
curr_writer = writer_class(writer_config.log_dir, writer_config.stats_to_track, writer_config.max_log_size)
else:
curr_writer = writer_class(writer_config.log_dir)
EVENT_WRITERS.append(curr_writer)
for writer_type_config in config.writer:
if writer_type_config.enable:
curr_writer = writer_type_config.setup()
EVENT_WRITERS.append(curr_writer)
logging.info("logging info to: %s", writer_type_config.log_dir)
## configure all the global buffer basic information
GLOBAL_BUFFER["max_iter"] = max_iter
@@ -159,7 +155,7 @@ def setup_event_writers(config: LoggingConfig, max_iter: int) -> None:
class Writer:
"""Writer class"""
def __init__(self, log_dir: str):
def __init__(self, log_dir: Optional[Path]):
self.log_dir = log_dir
@abstractmethod
@@ -228,9 +224,9 @@ class TimeWriter:
class WandbWriter(Writer):
"""WandDB Writer Class"""
def __init__(self, log_dir: str):
super().__init__(log_dir)
wandb.init(dir=log_dir)
def __init__(self, config: cfg.WandbWriterConfig):
super().__init__(config.log_dir)
wandb.init(dir=config.log_dir)
def write_image(self, name: str, image: TensorType["H", "W", "C"], step: int) -> None:
"""_summary_
@@ -256,9 +252,9 @@ class WandbWriter(Writer):
class TensorboardWriter(Writer):
"""Tensorboard Writer Class"""
def __init__(self, log_dir: str):
super().__init__(log_dir)
self.tb_writer = SummaryWriter(log_dir=self.log_dir)
def __init__(self, config: cfg.TensorboardWriterConfig):
super().__init__(config.log_dir)
self.tb_writer = SummaryWriter(log_dir=config.log_dir)
def write_image(self, name: str, image: TensorType["H", "W", "C"], step: int) -> None:
"""_summary_
@@ -313,23 +309,23 @@ def _format_time(seconds):
class LocalWriter(Writer):
"""Local Writer Class"""
def __init__(self, log_dir: str, stats_to_track: ListConfig, max_log_size: int = 0):
def __init__(self, config: cfg.LocalWriterConfig):
"""
Args:
stats_to_track (ListConfig): the names of stats that should be logged.
max_log size (int): max number of lines that will be logged to teminal.
"""
super().__init__(log_dir)
self.stats_to_track = [EventName[name].value for name in stats_to_track]
self.max_log_size = max_log_size
super().__init__(config.log_dir)
self.stats_to_track = [name.value for name in config.stats_to_track]
self.max_log_size = config.max_log_size
self.keys = set()
self.past_mssgs = ["", ""]
self.has_printed = False
def write_image(self, name: str, image: TensorType["H", "W", "C"], step: int) -> None:
if name in self.stats_to_track:
if name in self.stats_to_track and self.log_dir:
image = to8b(image)
image_path = os.path.join(self.log_dir, f"{name}.jpg")
image_path = self.log_dir / f"{name}.jpg"
imageio.imwrite(image_path, np.uint8(image.cpu().numpy() * 255.0))
def write_scalar(self, name: str, scalar: float, step: int) -> None: