mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-02 05:48:57 +08:00
refactor moving setup functions to associated classes; cleanup eval and benchmark scripts (#48)
* refactor code to move graph/dataset setup to respective files * consolidated eval and benchmark script * moved setup optimizers to its own thing
This commit is contained in:
1 parent
ee60d5b9b5
commit
f67dca6f5b
10 files changed
+269
-217
No files matched your search
@@ -16,7 +16,7 @@
|
||||
Optimizers class.
|
||||
"""
|
||||
|
||||
from typing import Dict, List
|
||||
from typing import Any, Dict, List
|
||||
|
||||
import numpy as np
|
||||
from hydra.utils import instantiate
|
||||
@@ -27,6 +27,19 @@ from torch.optim.lr_scheduler import LambdaLR
|
||||
from pyrad.utils import writer
|
||||
|
||||
|
||||
def setup_optimizers(config: DictConfig, param_groups: Dict[str, List[Parameter]]) -> "Optimizers":
|
||||
"""Helper to set up the optimizers
|
||||
|
||||
Args:
|
||||
config (DictConfig): _description_
|
||||
param_groups (Dict[str, List[Parameter]]): _description_
|
||||
|
||||
Returns:
|
||||
Optimizers: _description_
|
||||
"""
|
||||
return Optimizers(config, param_groups)
|
||||
|
||||
|
||||
class ExponentialDecaySchedule(LambdaLR):
|
||||
"""Exponential learning rate decay function.
|
||||
See https://github.com/google-research/google-research/blob/
|
||||
@@ -108,3 +121,8 @@ class Optimizers:
|
||||
# TODO(ethan): clean this up. why is there indexing into a list?
|
||||
lr = scheduler.get_last_lr()[0]
|
||||
writer.put_scalar(name=f"learning_rate/{param_group_name}", scalar=lr, step=step)
|
||||
|
||||
def load_optimizers(self, loaded_state: Dict[str, Any]) -> None:
|
||||
"""Helper to load the optimizer state from previous checkpoint"""
|
||||
for k, v in loaded_state["optimizers"].items():
|
||||
self.optimizers[k].load_state_dict(v)
|
||||
Reference in new issue
Block a user