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

Don't download model weights and load imagenet weights if using models for inference #144

Open
pjbull opened this issue Oct 21, 2021 · 3 comments
Labels
bug Something isn't working v2

Comments

@pjbull
Copy link
Member

pjbull commented Oct 21, 2021

We currently use load_from_checkpoint in our ModelManager to initialize models when doing inference. This can cause the models to download the pretrained imagenet weights from the internet even thought we don't need those. To address this, we need a parameter that we pass in to the __init__ of the model to indicate we are doing inference/loading from a checkpoint, and then we need to pass this paramter to load_from_checkpoint in the ModelManager.

We should check across all of our models for this behavior, but this is how it works for the time_distributed model:

  • Here is where we need to pass a parameter indicating that we're doing inference:

    if labels is None:
    # predict; load from checkpoint uses associated hparams
    logger.info("Loading from checkpoint.")
    return model_class.load_from_checkpoint(checkpoint_path=checkpoint)

  • Here is where we need to use that param to skip intializing from timm:

    if finetune_from is None:
    efficientnet = timm.create_model("efficientnetv2_rw_m", pretrained=True)
    efficientnet.classifier = nn.Identity()
    else:
    efficientnet = self.load_from_checkpoint(finetune_from).base.module

@pjbull pjbull added bug Something isn't working v2 labels Oct 21, 2021
@ejm714
Copy link
Collaborator

ejm714 commented Jun 7, 2022

This also arises if we are training a model that has labels which are a subset of the zamba labels, which means we "resume training" instead of replacing the head. This stems from the fact that finetune_from is still None in this case; we should instead do model_class(finetune_from={official_ckpt}) rather than load from checkpoint

elif is_subset:
logger.info(
"Provided species fully overlap with Zamba species. Resuming training from latest checkpoint."
)
# update in case we want to resume with different scheduler
if scheduler_config != "default":
hparams.update(scheduler_config.dict())
model = model_class.load_from_checkpoint(checkpoint_path=checkpoint, **hparams)

In addition: we may want super().load_from_checkpoint instead here to avoid re-passing through the init with the timm weight download:

efficientnet = self.load_from_checkpoint(finetune_from).base.module

@papapizzachess
Copy link

papapizzachess commented Nov 23, 2023

The code has changed a lot. Has this bug been resolved? I'm trying to work on this if it's not resolved.

@ejm714
Copy link
Collaborator

ejm714 commented Nov 27, 2023

@papapizzachess yes this bug still exists and the code sections in the issue description are still correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working v2
Projects
None yet
Development

No branches or pull requests

3 participants