Skip to content

Invalid hash code when using EfficientNet #696

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

Open
jdrp opened this issue Oct 23, 2023 · 3 comments
Open

Invalid hash code when using EfficientNet #696

jdrp opened this issue Oct 23, 2023 · 3 comments

Comments

@jdrp
Copy link

jdrp commented Oct 23, 2023

I am currently on step 3.2 of 06. PyTorch Transfer Learning. When I try to run this code on a Colab notebook:

weights = torchvision.models.EfficientNet_B0_Weights.DEFAULT # .DEFAULT = best available weights 
model = torchvision.models.efficientnet_b0(weights=weights).to(device)

I keep getting the following error:

RuntimeError: invalid hash value (expected "3dd342df", got "7f5810bc96def8f7552d5b7e68d53c4786f81167d28291b21c0d90e1fca14934")

Both the expected and got hash values stay the same if I run the code again.
My torch version is 2.1.0+cu118 and torchvision is 0.16.0+cu118

@mrdbourke
Copy link
Owner

Hi @jdrp ,

Looks like a few people are getting this issue with the latest version of torchvision.

You can find a solution here: #693 (reply in thread)

In short,

This should help fix it:

Overriding torchvision.models._api.WeightsEnum.get_state_dict() should do the trick, LMK if it doesn't work

from torchvision.models import efficientnet_b0, EfficientNet_B0_Weights
from torchvision.models._api import WeightsEnum
from torch.hub import load_state_dict_from_url

def get_state_dict(self, *args, **kwargs):
    kwargs.pop("check_hash")
    return load_state_dict_from_url(self.url, *args, **kwargs)
WeightsEnum.get_state_dict = get_state_dict

efficientnet_b0(weights=EfficientNet_B0_Weights.IMAGENET1K_V1)
efficientnet_b0(weights="DEFAULT")

Source: pytorch/vision#7744 (comment)

@jdrp
Copy link
Author

jdrp commented Oct 24, 2023

That worked, thanks for the quick help!

@Aconsumeeverything
Copy link

that worked thank you !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants