mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-03 22:38:48 +08:00
load from checkpoint
This commit is contained in:
1 parent
310b177406
commit
cf856d0915
1 file changed
+12
@@ -83,6 +83,8 @@ class TrainerConfig(ExperimentConfig):
|
|||||||
"""Optionally specify model step to load from; if none, will find most recent model in load_dir."""
|
"""Optionally specify model step to load from; if none, will find most recent model in load_dir."""
|
||||||
load_config: Optional[Path] = None
|
load_config: Optional[Path] = None
|
||||||
"""Path to config YAML file."""
|
"""Path to config YAML file."""
|
||||||
|
load_checkpoint: Optional[Path] = None
|
||||||
|
"""Path to checkpoint file."""
|
||||||
log_gradients: bool = False
|
log_gradients: bool = False
|
||||||
"""Optionally log gradients during training"""
|
"""Optionally log gradients during training"""
|
||||||
|
|
||||||
@@ -345,6 +347,7 @@ class Trainer:
|
|||||||
def _load_checkpoint(self) -> None:
|
def _load_checkpoint(self) -> None:
|
||||||
"""Helper function to load pipeline and optimizer from prespecified checkpoint"""
|
"""Helper function to load pipeline and optimizer from prespecified checkpoint"""
|
||||||
load_dir: Path = self.config.load_dir
|
load_dir: Path = self.config.load_dir
|
||||||
|
load_checkpoint: Path = self.config.load_checkpoint
|
||||||
if load_dir is not None:
|
if load_dir is not None:
|
||||||
load_step = self.config.load_step
|
load_step = self.config.load_step
|
||||||
if load_step is None:
|
if load_step is None:
|
||||||
@@ -360,6 +363,15 @@ class Trainer:
|
|||||||
self.optimizers.load_optimizers(loaded_state["optimizers"])
|
self.optimizers.load_optimizers(loaded_state["optimizers"])
|
||||||
self.grad_scaler.load_state_dict(loaded_state["scalers"])
|
self.grad_scaler.load_state_dict(loaded_state["scalers"])
|
||||||
CONSOLE.print(f"Done loading Nerfstudio checkpoint from {load_path}")
|
CONSOLE.print(f"Done loading Nerfstudio checkpoint from {load_path}")
|
||||||
|
elif load_checkpoint is not None:
|
||||||
|
assert load_checkpoint.exists(), f"Checkpoint {load_checkpoint} does not exist"
|
||||||
|
loaded_state = torch.load(load_checkpoint, map_location="cpu")
|
||||||
|
self._start_step = loaded_state["step"] + 1
|
||||||
|
# load the checkpoints for pipeline, optimizers, and gradient scalar
|
||||||
|
self.pipeline.load_pipeline(loaded_state["pipeline"], loaded_state["step"])
|
||||||
|
self.optimizers.load_optimizers(loaded_state["optimizers"])
|
||||||
|
self.grad_scaler.load_state_dict(loaded_state["scalers"])
|
||||||
|
CONSOLE.print(f"Done loading Nerfstudio checkpoint from {load_checkpoint}")
|
||||||
else:
|
else:
|
||||||
CONSOLE.print("No Nerfstudio checkpoint to load, so training from scratch.")
|
CONSOLE.print("No Nerfstudio checkpoint to load, so training from scratch.")
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user