首页 > 解决方案 > RuntimeError:意外的 EOF,预计多 3302200 个字节。文件可能已损坏

问题描述

我正在尝试实现以下存储库的预训练模型。我需要您的帮助来纠正错误。

RuntimeError:意外的 EOF,预计多 3302200 个字节。该文件可能已损坏。

我尝试使用 google Collab 在以下 repo 中实现 CANNet 的预训练模型,并遵循(先决条件、克隆、数据准备和测试)的所有步骤

https://github.com/gjy3035/NWPU-Crowd-Sample-Code.git

详细错误如下

Traceback (most recent call last):
File "test.py", line 118, in
main()
File "test.py", line 46, in main
test(lines, model_path)
File "test.py", line 55, in test
net.load_state_dict(torch.load(model_path))
File "/usr/local/lib/python3.7/dist-packages/torch/serialization.py", line 593, in load
return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
File "/usr/local/lib/python3.7/dist-packages/torch/serialization.py", line 779, in _legacy_load
deserialized_objects[key]._set_from_file(f, offset, f_should_read_directly)
RuntimeError: unexpected EOF, expected 3302200 more bytes. The file might be corrupted.

标签: pytorchpre-trained-modeltorchvision

解决方案


查看这个 github 链接:https ://github.com/huggingface/transformers/issues/1491 它建议应该使用force_downloadarg。这相当于force_reload假设您正在使用torch.load.hub加载预训练模型。另一个适用于 windows 用户的选项是删除下载的模型并重新下载。

我有同样的问题,但 --settingforce_reload=True并没有为我清除它,我认为我有空间问题,但我认为值得一试。


推荐阅读