vision: Pretrained efficientnet_b0_rwrightman-3dd342df state_dict fails sha256 check
🐛 Describe the bug
Originally reported in the forum.
I am able to reproduce the issue using torchvision==0.16.0.dev20230709+cu121
:
model = models.efficientnet_b0(pretrained=True)
/home/pbialecki/miniforge3/envs/nightly_pip_cu121/lib/python3.10/site-packages/torchvision/models/_utils.py:208: UserWarning: The parameter 'pretrained' is deprecated since 0.13 and may be removed in the future, please use 'weights' instead.
warnings.warn(
/home/pbialecki/miniforge3/envs/nightly_pip_cu121/lib/python3.10/site-packages/torchvision/models/_utils.py:223: UserWarning: Arguments other than a weight enum or `None` for 'weights' are deprecated since 0.13 and may be removed in the future. The current behavior is equivalent to passing `weights=EfficientNet_B0_Weights.IMAGENET1K_V1`. You can also use `weights=EfficientNet_B0_Weights.DEFAULT` to get the most up-to-date weights.
warnings.warn(msg)
Downloading: "https://download.pytorch.org/models/efficientnet_b0_rwightman-3dd342df.pth" to /home/pbialecki/.cache/torch/hub/checkpoints/efficientnet_b0_rwightman-3dd342df.pth
100%|██████████| 20.5M/20.5M [00:00<00:00, 52.8MB/s]
Traceback (most recent call last):
Cell In[75], line 1
model = models.efficientnet_b0(pretrained=True)
File ~/miniforge3/envs/nightly_pip_cu121/lib/python3.10/site-packages/torchvision/models/_utils.py:142 in wrapper
return fn(*args, **kwargs)
File ~/miniforge3/envs/nightly_pip_cu121/lib/python3.10/site-packages/torchvision/models/_utils.py:228 in inner_wrapper
return builder(*args, **kwargs)
File ~/miniforge3/envs/nightly_pip_cu121/lib/python3.10/site-packages/torchvision/models/efficientnet.py:770 in efficientnet_b0
return _efficientnet(
File ~/miniforge3/envs/nightly_pip_cu121/lib/python3.10/site-packages/torchvision/models/efficientnet.py:360 in _efficientnet
model.load_state_dict(weights.get_state_dict(progress=progress, check_hash=True))
File ~/miniforge3/envs/nightly_pip_cu121/lib/python3.10/site-packages/torchvision/models/_api.py:90 in get_state_dict
return load_state_dict_from_url(self.url, *args, **kwargs)
File ~/miniforge3/envs/nightly_pip_cu121/lib/python3.10/site-packages/torch/hub.py:757 in load_state_dict_from_url
download_url_to_file(url, cached_file, hash_prefix, progress=progress)
File ~/miniforge3/envs/nightly_pip_cu121/lib/python3.10/site-packages/torch/hub.py:653 in download_url_to_file
raise RuntimeError('invalid hash value (expected "{}", got "{}")'
RuntimeError: invalid hash value (expected "3dd342df", got "7f5810bc96def8f7552d5b7e68d53c4786f81167d28291b21c0d90e1fca14934")
Downloading the state_dict
manually also confirms the sha256
checksum:
wget https://download.pytorch.org/models/efficientnet_b0_rwightman-3dd342df.pth
sha256sum efficientnet_b0_rwightman-3dd342df.pth
7f5810bc96def8f7552d5b7e68d53c4786f81167d28291b21c0d90e1fca14934 efficientnet_b0_rwightman-3dd342df.pth
which does not match the one stored in the file name.
Versions
torchvision==0.16.0.dev20230709+cu121
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 17 (10 by maintainers)
EDIT: This is fixed in torchvision 0.17, just install “torchvision>0.16” and this should be fixed. If you’re stuck with 0.16, do as described below
Original comment:
Overriding
torchvision.models._api.WeightsEnum.get_state_dict()
should do the trick, LMK if it doesn’t workFor anyone who might still be stuck with the same error. The major issue is from
torchvision==0.16.0
. An easy workaround is to install higher versions or nightly. Tested and worked ontorchvision
v0.16.1
,v0.16.2
,v0.17.0
.I can still reproduce this issue with
torchvision==0.17.0.dev20231009
.@NicolasHug, running your script from #7898 I get:
@ptrblck bingo 😃 So it was like that for a while, but it was not checked before… Running the script to validate published checksums right now…
@dimakpa please see https://github.com/pytorch/vision/issues/7744#issuecomment-1757321451 until the fix is available in the next bugfix release (planned for mid Nov)
Thanks for the report @ar0ck . I’m confused as to how I missed those in the past, but I can reproduce…
We’ll fix those in the next [bugfix] release
Is it because https://github.com/pytorch/vision/pull/7219 landed between these commits?