mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-02 05:48:57 +08:00
fixed up benchmarking test script more versatile
This commit is contained in:
1 parent
39db2e8a27
commit
6a70eaa40a
3 files changed
+37
-15
No files matched your search
@@ -111,3 +111,9 @@ ipython --pdb scripts/run_train.py
|
|||||||
```
|
```
|
||||||
./scripts/benchmarking/launch_train_blender.sh <gpu0> <gpu1> ... <gpu7>
|
./scripts/benchmarking/launch_train_blender.sh <gpu0> <gpu1> ... <gpu7>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
For testing specific methods, see scripts/benchmarking/run_benchmark.py.
|
||||||
|
Modify the `BENCH` variable to specify which jobs ("ckpt_dir") and methods ("method") you want benchmarked. Then run
|
||||||
|
```
|
||||||
|
python scripts/benchmarking/run_benchmark.py
|
||||||
|
```
|
||||||
@@ -6,6 +6,7 @@ for dataset in ${DATASETS[@]}; do
|
|||||||
export CUDA_VISIBLE_DEVICES=${!GPU_IDX}
|
export CUDA_VISIBLE_DEVICES=${!GPU_IDX}
|
||||||
python scripts/run_train.py \
|
python scripts/run_train.py \
|
||||||
data.dataset.data_directory=data/blender/${dataset} \
|
data.dataset.data_directory=data/blender/${dataset} \
|
||||||
|
data.dataset.downscale_factor=1 \
|
||||||
experiment_name=blender_${dataset} \
|
experiment_name=blender_${dataset} \
|
||||||
graph.model_dir=mattport_models/ \
|
graph.model_dir=mattport_models/ \
|
||||||
graph.steps_per_save=25000 \
|
graph.steps_per_save=25000 \
|
||||||
|
|||||||
@@ -2,27 +2,35 @@
|
|||||||
run_benchmark.py
|
run_benchmark.py
|
||||||
"""
|
"""
|
||||||
import json
|
import json
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
|
from datetime import date
|
||||||
|
|
||||||
import torch
|
import torch
|
||||||
from hydra import compose, initialize
|
from hydra import compose, initialize
|
||||||
|
from hydra.core.global_hydra import GlobalHydra
|
||||||
from omegaconf import DictConfig
|
from omegaconf import DictConfig
|
||||||
|
from tqdm import tqdm
|
||||||
|
|
||||||
from mattport.nerf.trainer import Trainer
|
from mattport.nerf.trainer import Trainer
|
||||||
|
|
||||||
BENCH = {
|
BENCH = {
|
||||||
"mic": "outputs/blender_mic/vanilla_nerf/2022-05-11_192109/",
|
"method": "vanilla_nerf",
|
||||||
"ficus": "outputs/blender_ficus/vanilla_nerf/2022-05-11_192109/",
|
"hydra_base_dir": "outputs/",
|
||||||
"chair": "outputs/blender_chair/vanilla_nerf/2022-05-11_192109/",
|
"ckpt_dir": {
|
||||||
"hotdog": "outputs/blender_hotdog/vanilla_nerf/2022-05-11_192109/",
|
"mic": "2022-05-11_192109",
|
||||||
"materials": "outputs/blender_materials/vanilla_nerf/2022-05-11_192109/",
|
"ficus": "2022-05-11_192109",
|
||||||
"drums": "outputs/blender_drums/vanilla_nerf/2022-05-11_192109/",
|
"chair": "2022-05-11_192109",
|
||||||
"ship": "outputs/blender_ship/vanilla_nerf/2022-05-11_192109/",
|
"hotdog": "2022-05-11_192109",
|
||||||
"lego": "outputs/blender_lego/vanilla_nerf/2022-05-11_192109/",
|
"materials": "2022-05-11_192109",
|
||||||
|
"drums": "2022-05-11_192109",
|
||||||
|
"ship": "2022-05-11_192109",
|
||||||
|
"lego": "2022-05-11_192109",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def load_best_ckpt(hydra_dir: str, config: DictConfig):
|
def load_best_ckpt(hydra_dir: str, config: DictConfig) -> str:
|
||||||
"""helper function to update config with latest checkpoint in specified hydra_dir"""
|
"""helper function to update config with latest checkpoint in specified hydra_dir"""
|
||||||
model_dir = os.path.join(hydra_dir, config.graph.model_dir)
|
model_dir = os.path.join(hydra_dir, config.graph.model_dir)
|
||||||
latest_ckpt = os.listdir(model_dir)
|
latest_ckpt = os.listdir(model_dir)
|
||||||
@@ -32,15 +40,19 @@ def load_best_ckpt(hydra_dir: str, config: DictConfig):
|
|||||||
config.graph.resume_train.load_dir = model_dir
|
config.graph.resume_train.load_dir = model_dir
|
||||||
config.graph.resume_train.load_step = int(step)
|
config.graph.resume_train.load_step = int(step)
|
||||||
config.logging.writer.TensorboardWriter.save_dir = "/tmp/"
|
config.logging.writer.TensorboardWriter.save_dir = "/tmp/"
|
||||||
|
return os.path.join(model_dir, latest_ckpt)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Main function."""
|
"""Main function."""
|
||||||
benchmarks = {}
|
benchmarks = {}
|
||||||
for dataset, hydra_dir in BENCH.items():
|
hydra_base_dir = BENCH["hydra_base_dir"]
|
||||||
|
method = BENCH["method"]
|
||||||
|
for dataset, ckpt_dir in tqdm(BENCH["ckpt_dir"].items()):
|
||||||
|
hydra_dir = f"{hydra_base_dir}/blender_{dataset}/{method}/{ckpt_dir}/"
|
||||||
initialize(config_path=os.path.join("../../", hydra_dir, ".hydra/"))
|
initialize(config_path=os.path.join("../../", hydra_dir, ".hydra/"))
|
||||||
config = compose("config.yaml")
|
config = compose("config.yaml")
|
||||||
load_best_ckpt(hydra_dir, config)
|
ckpt = load_best_ckpt(hydra_dir, config)
|
||||||
trainer = Trainer(config, local_rank=0, world_size=1)
|
trainer = Trainer(config, local_rank=0, world_size=1)
|
||||||
trainer.setup(test_mode=True)
|
trainer.setup(test_mode=True)
|
||||||
avg_psnr = 0
|
avg_psnr = 0
|
||||||
@@ -48,12 +60,15 @@ def main():
|
|||||||
with torch.no_grad():
|
with torch.no_grad():
|
||||||
psnr = trainer.test_image(image_idx=image_idx, step=step)
|
psnr = trainer.test_image(image_idx=image_idx, step=step)
|
||||||
avg_psnr = (step * avg_psnr + psnr) / (step + 1)
|
avg_psnr = (step * avg_psnr + psnr) / (step + 1)
|
||||||
benchmarks[dataset] = avg_psnr
|
benchmarks[dataset] = (avg_psnr, ckpt)
|
||||||
|
GlobalHydra.instance().clear()
|
||||||
|
|
||||||
benchmark_info = {"bench": BENCH, "results": benchmarks}
|
benchmark_info = {"bench": BENCH, "results": benchmarks}
|
||||||
# TODO(more sophisticated saving to output directory)
|
timestamp = date.today().strftime("%b-%d-%Y")
|
||||||
with open("/tmp/benchmark.json", "w", encoding="utf8") as f:
|
json_file = os.path.join(BENCH["hydra_base_dir"], f"{timestamp}.json")
|
||||||
json.dump(benchmark_info, f)
|
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__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in new issue
Block a user