RuntimeError: unexpected EOF, expected 73963 more bytes. The file might be corrupted.解决方案

RuntimeError: unexpected EOF, expected 73963 more bytes. The file might be corrupted. 解决方案

问题描述:

项目工程执行python脚本时,在下载pytorch的预训练模型权重的时候,如果因网络不稳定等原因导致权重没下载完,就会报错 RuntimeError: unexpected EOF, expected xxxxx more bytes. The file might be corrupted.
报错


原因分析:

该报错表明下载的权重文件可能已经损坏了,需要把损坏的权重文件删除,再执行代码即可重新下载。


解决方案:

要找到下载的权重文件保存的位置,本文分析三种情况:

  1. Windows系统Anaconda环境:
    如问题描述小节图片红框位置可见,download位置是 D:\Anaconda3\anaconda\envs\yypy36\Lib\site-packages\facexlib\weightsdetection_Resnet50_Final.pth 因此直接进入对应的文件夹,删除权重文件即可。如下图所示:
    权重文件位置

  2. Windows系统普通Python环境:
    代码自动下载模型权重文件后会保存到C:\Users\用户名/.cache\torch\checkpoints文件夹下。注意 .cache可能是隐藏文件,需要查看隐藏文件才能看到,删除权重文件即可。

  3. Linux系统:
    Linux系统权重文件通常保存在:\home\用户名\.cache\torch 下。要注意,.cache是个隐藏文件夹,在winSCP中按 ctrl+Alt+H 才会显示;或者,在home目录下,使用 ls -a 可以显示出来。root 模式下,下载的权重文件默认保存路径在:/root/.cache/torch/checkpoints下。删除权重文件即可。

以上三种情况,删除权重文件后,重新执行代码即可重新下载。

补充

如果执行程序下载代码太慢或者网络稳定性不好,我们可以直接到权重文件所在网站手动下载,并放入指定位置,Linux系统可采用wget大法。

wget -P 权重文件保存的本地路径 权重文件地址

如果下载中断了,wget支持断点续传,加个参数 -c 即可:

wget -P 权重文件保存的本地路径 -c 权重文件地址

eg:

wget -P /home/20220222Proj/pretrained_models -c https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.1/RealESRGAN_x2plus.pth

本文参考:

1、unexpected EOF, expected 455433 more bytes. The file might be corrupted.解决方案
2、RuntimeError: unexpected EOF, expected 23361873 more bytes. The file might be
3、unexpected EOF, expected 65478 more bytes. The file might be corrupted.问题解决方案
4、RuntimeError: unexpected EOF, expected 309663195 more bytes. The file might be corrupted.暴力解决

来源:小白白程序员

物联沃分享整理
物联沃-IOTWORD物联网 » RuntimeError: unexpected EOF, expected 73963 more bytes. The file might be corrupted.解决方案

发表评论