'PytorchStreamReader failed reading zip archive: failed finding central directory

I am trying to learn pytorch from a book, but it seems not a straight line for me. I coped the code below and pasted in my jupyter notebook for running but it gave me an error I am not able to interpret at my level!

from torchvision import models
model = models.alexnet(pretrained=True)

# set the device
device = 'cuda' if torch.cuda.is_available() else 'cpu'
print(f'Device: {device}')

model.eval()
model.to(device)
y = model(batch.to(device))
print(y.shape)

The error is as below

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-50-03488007067c> in <module>
      1 from torchvision import models
----> 2 model = models.alexnet(pretrained=True)
      3 
      4 # set the device
      5 device = 'cuda' if torch.cuda.is_available() else 'cpu'

~\anaconda3\lib\site-packages\torchvision\models\alexnet.py in alexnet(pretrained, progress, **kwargs)
     61     model = AlexNet(**kwargs)
     62     if pretrained:
---> 63         state_dict = load_state_dict_from_url(model_urls['alexnet'],
     64                                               progress=progress)
     65         model.load_state_dict(state_dict)

~\anaconda3\lib\site-packages\torch\hub.py in load_state_dict_from_url(url, model_dir, map_location, progress, check_hash, file_name)
    555     if _is_legacy_zip_format(cached_file):
    556         return _legacy_zip_load(cached_file, model_dir, map_location)
--> 557     return torch.load(cached_file, map_location=map_location)

~\anaconda3\lib\site-packages\torch\serialization.py in load(f, map_location, pickle_module, **pickle_load_args)
    598             # reset back to the original position.
    599             orig_position = opened_file.tell()
--> 600             with _open_zipfile_reader(opened_file) as opened_zipfile:
    601                 if _is_torchscript_zip(opened_zipfile):
    602                     warnings.warn("'torch.load' received a zip file that looks like a TorchScript archive"

~\anaconda3\lib\site-packages\torch\serialization.py in __init__(self, name_or_buffer)
    240 class _open_zipfile_reader(_opener):
    241     def __init__(self, name_or_buffer) -> None:
--> 242         super(_open_zipfile_reader, self).__init__(torch._C.PyTorchFileReader(name_or_buffer))
    243 
    244 

RuntimeError: PytorchStreamReader failed reading zip archive: failed finding central directory

someone help me understand this please. Thank you.



Solution 1:[1]

I think this issue happens with the file is not downloaded completely.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vishwaak Chandran