mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-20 14:45:38 +08:00
added limit to how many models to save (#546)
This commit is contained in:
1 parent
399e5cac6d
commit
800be33cf3
2 files changed
+7
No files matched your search
@@ -146,6 +146,8 @@ class TrainerConfig(PrintableConfig):
|
|||||||
"""whether or not to use mixed precision for training"""
|
"""whether or not to use mixed precision for training"""
|
||||||
relative_model_dir: Path = Path("nerfactory_models/")
|
relative_model_dir: Path = Path("nerfactory_models/")
|
||||||
"""relative path to save all checkpoints"""
|
"""relative path to save all checkpoints"""
|
||||||
|
num_ckpt_to_save: int = 1
|
||||||
|
"""number of latest checkpoints that we want to save. Default 1 saves only the latest model"""
|
||||||
# optional parameters if we want to resume training
|
# optional parameters if we want to resume training
|
||||||
load_dir: Optional[Path] = None
|
load_dir: Optional[Path] = None
|
||||||
"""optionally specify a pre-trained model directory to load from"""
|
"""optionally specify a pre-trained model directory to load from"""
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ class Trainer:
|
|||||||
# directory to save checkpoints
|
# directory to save checkpoints
|
||||||
self.checkpoint_dir = config.get_checkpoint_dir()
|
self.checkpoint_dir = config.get_checkpoint_dir()
|
||||||
logging.info("Saving checkpoints to: %s", self.checkpoint_dir)
|
logging.info("Saving checkpoints to: %s", self.checkpoint_dir)
|
||||||
|
self.prev_ckpt_paths = []
|
||||||
# set up viewer if enabled
|
# set up viewer if enabled
|
||||||
viewer_log_path = self.base_dir / config.viewer.relative_log_filename
|
viewer_log_path = self.base_dir / config.viewer.relative_log_filename
|
||||||
self.viewer_state, banner_messages = viewer_utils.setup_viewer(config.viewer, log_filename=viewer_log_path)
|
self.viewer_state, banner_messages = viewer_utils.setup_viewer(config.viewer, log_filename=viewer_log_path)
|
||||||
@@ -291,6 +292,10 @@ class Trainer:
|
|||||||
},
|
},
|
||||||
ckpt_path,
|
ckpt_path,
|
||||||
)
|
)
|
||||||
|
self.prev_ckpt_paths.append(ckpt_path)
|
||||||
|
if len(self.prev_ckpt_paths) > self.config.trainer.num_ckpt_to_save:
|
||||||
|
self.prev_ckpt_paths[0].unlink(missing_ok=True)
|
||||||
|
self.prev_ckpt_paths.pop(0)
|
||||||
|
|
||||||
@profiler.time_function
|
@profiler.time_function
|
||||||
def train_iteration(self, step: int) -> Tuple[torch.Tensor, Dict[str, torch.Tensor], Dict[str, torch.Tensor]]:
|
def train_iteration(self, step: int) -> Tuple[torch.Tensor, Dict[str, torch.Tensor], Dict[str, torch.Tensor]]:
|
||||||
|
|||||||
Reference in new issue
Block a user