首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >PytorchStreamReader读取压缩归档失败:找不到中心目录

PytorchStreamReader读取压缩归档失败:找不到中心目录
EN

Stack Overflow用户
提问于 2022-03-25 13:15:06
回答 1查看 13K关注 0票数 5

我正试着从一本书中学习火把,但它对我来说似乎不是一条直线。我处理了下面的代码,并粘贴在我的jupyter笔记本上运行,但它给了我一个错误,我无法解释我的水平!

代码语言:javascript
运行
复制
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)

错误如下

代码语言:javascript
运行
复制
---------------------------------------------------------------------------
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

谁能帮我理解一下。谢谢。

EN

回答 1

Stack Overflow用户

发布于 2022-05-02 11:17:53

我认为这个问题发生在文件没有被完全下载的时候。

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71617570

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档