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

Remove fallback by error with pretrained weights #320

Merged
merged 2 commits into from
Dec 11, 2024
Merged
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
18 changes: 7 additions & 11 deletions terratorch/models/backbones/prithvi_vit.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ def checkpoint_filter_wrapper_fn(state_dict, model):
model_args = prithvi_cfgs[variant].copy()
model_args.update(kwargs)

# When the pretrained configuration is not available in HF, we shift to pretrained=False
try:
model = build_model_with_cfg(
prithvi_model_class,
Expand All @@ -230,16 +229,13 @@ def checkpoint_filter_wrapper_fn(state_dict, model):
pretrained_strict=True,
**model_args,
)
except RuntimeError:
logger.warning(f"No pretrained configuration was found for the model {variant}. Using random initialization.")
model = build_model_with_cfg(
prithvi_model_class,
variant,
False,
pretrained_filter_fn=checkpoint_filter_wrapper_fn,
pretrained_strict=True,
**model_args,
)
except RuntimeError as e:
if pretrained:
logger.error(f"Failed to initialize the pre-trained model {variant} via timm, "
f"consider running the code with pretrained=False.")
else:
logger.error(f"Failed to initialize the model {variant} via timm.")
raise e

if encoder_only:
default_out_indices = list(range(len(model.blocks)))
Expand Down
Loading