Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve evaluate_from_recipe usability #558

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/super_gradients/training/sg_trainer/sg_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,17 +270,22 @@ def evaluate_from_recipe(cls, cfg: DictConfig) -> None:
name=cfg.val_dataloader, dataset_params=cfg.dataset_params.val_dataset_params, dataloader_params=cfg.dataset_params.val_dataloader_params
)

checkpoints_dir = Path(get_checkpoints_dir_path(experiment_name=cfg.experiment_name, ckpt_root_dir=cfg.ckpt_root_dir))
checkpoint_path = str(checkpoints_dir / cfg.training_hyperparams.ckpt_name)
logger.info(f"Evaluating checkpoint: {checkpoint_path}")
if cfg.checkpoint_params.checkpoint_path is None:
logger.info(
"checkpoint_params.checkpoint_path was not provided, " "so the recipe will be evaluated using checkpoints_dir/training_hyperparams.ckpt_name"
)
checkpoints_dir = Path(get_checkpoints_dir_path(experiment_name=cfg.experiment_name, ckpt_root_dir=cfg.ckpt_root_dir))
cfg.checkpoint_params.checkpoint_path = str(checkpoints_dir / cfg.training_hyperparams.ckpt_name)

logger.info(f"Evaluating checkpoint: {cfg.checkpoint_params.checkpoint_path}")

# BUILD NETWORK
model = models.get(
model_name=cfg.architecture,
num_classes=cfg.arch_params.num_classes,
arch_params=cfg.arch_params,
pretrained_weights=cfg.checkpoint_params.pretrained_weights,
checkpoint_path=checkpoint_path,
checkpoint_path=cfg.checkpoint_params.checkpoint_path,
load_backbone=cfg.checkpoint_params.load_backbone,
)

Expand Down
2 changes: 1 addition & 1 deletion src/super_gradients/training/utils/checkpoint_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def copy_ckpt_to_local_folder(

def read_ckpt_state_dict(ckpt_path: str, device="cpu"):
if not os.path.exists(ckpt_path):
raise ValueError("Incorrect Checkpoint path")
raise FileNotFoundError(f"Incorrect Checkpoint path: {ckpt_path} (This should be an absolute path)")

if device == "cuda":
state_dict = torch.load(ckpt_path)
Expand Down