mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-19 22:25:44 +08:00
dataloader logic, new folder structure, flatter configs (#26)
* renaming dataloader to data. adding some dataloader classes * restructuring configs * fixed instant ngp tcnn direction rescaling * working through test cases * black and lint and tests
This commit is contained in:
1 parent
24c1c77ef1
commit
457788d689
105 files changed
+8828
-682
No files matched your search
@@ -12,7 +12,7 @@ from hydra.core.global_hydra import GlobalHydra
|
||||
from omegaconf import DictConfig
|
||||
from tqdm import tqdm
|
||||
|
||||
from pyrad.nerf.trainer import Trainer
|
||||
from pyrad.engine.trainer import Trainer
|
||||
|
||||
BENCH = {
|
||||
"method": "vanilla_nerf",
|
||||
|
||||
@@ -7,7 +7,7 @@ Script to process different dataset types into our format.
|
||||
from hydra import compose, initialize
|
||||
import json
|
||||
|
||||
from pyrad.nerf.dataset.utils import get_dataset_inputs
|
||||
from pyrad.data.utils import get_dataset_inputs
|
||||
from pyrad.utils.io import get_absolute_path, make_dir, write_to_pkl
|
||||
from pyrad.utils.misc import get_hash_str_from_dict
|
||||
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
"""
|
||||
run_eval.py
|
||||
"""
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
from datetime import date
|
||||
|
||||
import torch
|
||||
from hydra import compose, initialize
|
||||
from hydra.core.global_hydra import GlobalHydra
|
||||
from omegaconf import DictConfig
|
||||
from tqdm import tqdm
|
||||
|
||||
from pyrad.engine.trainer import Trainer
|
||||
from pyrad.cameras.cameras import Camera
|
||||
|
||||
BENCH = {
|
||||
"method": "vanilla_nerf",
|
||||
"hydra_base_dir": "outputs/",
|
||||
"benchmark_date": "05-26-2022",
|
||||
"object_list": ["mic", "ficus", "chair", "hotdog", "materials", "drums", "ship", "lego"],
|
||||
}
|
||||
|
||||
|
||||
def load_best_ckpt(hydra_dir: str, config: DictConfig) -> str:
|
||||
"""helper function to update config with latest checkpoint in specified hydra_dir"""
|
||||
model_dir = os.path.join(hydra_dir, config.graph.model_dir)
|
||||
latest_ckpt = os.listdir(model_dir)
|
||||
latest_ckpt.sort()
|
||||
latest_ckpt = latest_ckpt[-1]
|
||||
step = os.path.splitext(latest_ckpt)[0].split("-")[-1]
|
||||
config.graph.resume_train.load_dir = model_dir
|
||||
config.graph.resume_train.load_step = int(step)
|
||||
config.logging.writer.TensorboardWriter.save_dir = "/tmp/"
|
||||
return os.path.join(model_dir, latest_ckpt)
|
||||
|
||||
|
||||
def main():
|
||||
"""Main function."""
|
||||
# benchmarks = {}
|
||||
# hydra_base_dir = BENCH["hydra_base_dir"]
|
||||
# method = BENCH["method"]
|
||||
# benchmark_date = BENCH["benchmark_date"]
|
||||
# for dataset in tqdm(BENCH["object_list"]):
|
||||
|
||||
# hydra_dir = f"{hydra_base_dir}/blender_{dataset}_{benchmark_date}/{method}/"
|
||||
# basename = os.listdir(hydra_dir)[0]
|
||||
# hydra_dir = f"{hydra_dir}/{basename}"
|
||||
# initialize(config_path=os.path.join("../../", hydra_dir, ".hydra/"))
|
||||
# config = compose("configs/flat.yaml")
|
||||
|
||||
with initialize(version_base=None, config_path="../configs"):
|
||||
config = compose(config_name="flat.yaml")
|
||||
trainer = Trainer(config, local_rank=0, world_size=1)
|
||||
trainer.setup(test_mode=False)
|
||||
|
||||
# create a camera trajectory
|
||||
print("Running eval.")
|
||||
# camera = Camera()
|
||||
# trainer.graph.eval()
|
||||
# camera_ray_bundle = camera.get_camera_ray_bundle(device=trainer.device)
|
||||
image_idx = 0
|
||||
camera_ray_bundle, batch = trainer.dataloader_eval.get_data_from_image_idx(image_idx)
|
||||
image_height, image_width = camera_ray_bundle.origins.shape[:2]
|
||||
print(image_height, image_width)
|
||||
outputs = trainer.graph.get_outputs_for_camera_ray_bundle(camera_ray_bundle)
|
||||
|
||||
# print(outputs)
|
||||
|
||||
# avg_psnr = 0
|
||||
# for step, image_idx in enumerate(config.data.val_image_indices):
|
||||
# with torch.no_grad():
|
||||
# psnr = trainer.test_image(image_idx=image_idx, step=step)
|
||||
# avg_psnr = (step * avg_psnr + psnr) / (step + 1)
|
||||
# benchmarks[dataset] = (avg_psnr, ckpt)
|
||||
# GlobalHydra.instance().clear()
|
||||
|
||||
# benchmark_info = {"bench": BENCH, "results": benchmarks}
|
||||
# timestamp = date.today().strftime("%b-%d-%Y")
|
||||
# json_file = os.path.join(BENCH["hydra_base_dir"], f"{timestamp}.json")
|
||||
# with open(json_file, "w", encoding="utf8") as f:
|
||||
# json.dump(benchmark_info, f, indent=2)
|
||||
# logging.info("saved benchmark results to %s", json_file)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -19,7 +19,7 @@ import torch.multiprocessing as mp
|
||||
from omegaconf import DictConfig
|
||||
import yaml
|
||||
|
||||
from pyrad.nerf.trainer import Trainer
|
||||
from pyrad.engine.trainer import Trainer
|
||||
from pyrad.utils import comms, profiler
|
||||
|
||||
logging.basicConfig(format="[%(filename)s:%(lineno)d] %(message)s", level=logging.DEBUG)
|
||||
@@ -102,7 +102,7 @@ def _distributed_worker(
|
||||
|
||||
assert num_gpus_per_machine <= torch.cuda.device_count()
|
||||
torch.cuda.set_device(local_rank)
|
||||
_set_random_seed(config.seed + global_rank)
|
||||
_set_random_seed(config.machine_config.seed + global_rank)
|
||||
comms.synchronize(world_size)
|
||||
|
||||
output = main_func(local_rank, world_size, config)
|
||||
@@ -151,11 +151,11 @@ def launch(
|
||||
world_size = num_machines * num_gpus_per_machine
|
||||
if world_size == 0:
|
||||
# Using only CPU and one process.
|
||||
_set_random_seed(config.seed)
|
||||
_set_random_seed(config.machine_config.seed)
|
||||
main_func(local_rank=0, world_size=0, config=config)
|
||||
elif world_size == 1:
|
||||
# Using one gpu and one process.
|
||||
_set_random_seed(config.seed)
|
||||
_set_random_seed(config.machine_config.seed)
|
||||
try:
|
||||
main_func(local_rank=0, world_size=1, config=config)
|
||||
except KeyboardInterrupt:
|
||||
|
||||
Reference in new issue
Block a user