Unpickling stack underflow

880n: <p>Hi, I’m meeting a problem loading the pre-trained model of Resnet-50.<br>
I just simply load the model and meet the following problem. I can’t find a solution to solve it.</p>
<blockquote>
<blockquote>
<blockquote>
<p>import torchvision<br>
res= torchvision.models.resnet50(pretrained=True)<br>
Traceback (most recent call last):<br>
File “”, line 1, in <br>
File “/home/hzha3251/.local/lib/python3.6/site-packages/torchvision/models/resnet.py”, line 261, in resnet50<br>
**kwargs)<br>
File “/home/hzha3251/.local/lib/python3.6/site-packages/torchvision/models/resnet.py”, line 223, in _resnet<br>
progress=progress)<br>
File “/home/hzha3251/.local/lib/python3.6/site-packages/torch/hub.py”, line 506, in load_state_dict_from_url<br>
return torch.load(cached_file, map_location=map_location)<br>
File “/home/hzha3251/.local/lib/python3.6/site-packages/torch/serialization.py”, line 529, in load<br>
return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)<br>
File “/home/hzha3251/.local/lib/python3.6/site-packages/torch/serialization.py”, line 692, in _legacy_load<br>
magic_number = pickle_module.load(f, **pickle_load_args)<br>
_pickle.UnpicklingError: unpickling stack underflow</p>
</blockquote>
</blockquote>
</blockquote>

ptrblck: <p>This error might be thrown, if <code>pickle</code> ends unexpectedly, e.g. if the downloaded file is corrupt.<br>
Did you try to rerun the code?<br>
If you still see this error, could you please delete the cached files?<br>
They should be located in</p>
<pre><code class="lang-auto">/home/USER/.cache/torch/checkpoints
</code></pre>
<p>by default.</p>

880n: <p>Yeah, this deals my problem. Thanks very much</p>

DmitryT: <p>Hi!<br>
I faced the same issue. I work in venv in RHEL. Can you please tell me where can I find .cache directory?<br>
I am using torch 1.5.0.<br>
Error comes from here: /path/to/my/venv/lib64/python3.6/site-packages/torch/serialization.py</p>

ptrblck: <p>Is the <code>.cache</code> folder not in the home folder I’ve posted above?</p>

DmitryT: <p>Sorry, I have .cache directory, but there is no “torch” directory in it (only matplotlib and pip).</p>

ptrblck: <p>Did you change the default cache location?<br>
Could you post the error message, please?<br>
Are you seeing the same error after trying to re-download the model?</p>

DmitryT: <p>I found bug in my code… I tried to load not .pt object with torch.load().<br>
Everything works fine now.<br>
Thank you!)</p>

sunruina2: <p>File “/opt/conda/lib/python3.6/site-packages/torchvision/models/resnet.py”, line 217, in _resnet<br>
progress=progress)<br>
File “/opt/conda/lib/python3.6/site-packages/torch/hub.py”, line 499, in load_state_dict_from_url<br>
return torch.load(cached_file, map_location=map_location)<br>
File “/opt/conda/lib/python3.6/site-packages/torch/serialization.py”, line 426, in load<br>
return _load(f, map_location, pickle_module, **pickle_load_args)<br>
File “/opt/conda/lib/python3.6/site-packages/torch/serialization.py”, line 603, in _load<br>
magic_number = pickle_module.load(f, **pickle_load_args)<br>
_pickle.UnpicklingError: unpickling stack underflow</p>
<p>thank you for suggest!  this deals my problem<br>
the main reason is “e.g. if the pretrain model downloaded file is corrupt.”<br>
step1: vim the last error file “/opt/conda/lib/python3.6/site-packages/torch/serialization.py”<br>
step2: find the error code line,and add “print(”#####", f)" before the error line.<br>
step3: run your code again, then remove the wrong pretrain file “ rm /root/.cache/torch/checkpoints/resnet152-b121ed2d.pth”</p>

1978500828: <p>Hello, bro, excuse me, I met the same problem as you, how did you solve it at last</p>