# Read Error while loading vgg16

**URL:** <https://discuss.pytorch.org/t/read-error-while-loading-vgg16/1942>\
**Category:** Uncategorized\
**Created:** [April 18, 2017, 2:01am UTC](https://discuss.pytorch.org/t/read-error-while-loading-vgg16/1942 "2017-04-18T02:01:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sarthak1996](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/s/43a26b/32.png) [@sarthak1996](https://discuss.pytorch.org/u/sarthak1996)\
**Post date:** [April 18, 2017, 2:01am UTC](https://discuss.pytorch.org/t/read-error-while-loading-vgg16/1942/1 "2017-04-18T02:01:42Z")

</div>

I am loading a pretrained model of vgg16:  
`vgg16=torchvision.models.vgg16(pretrained=True)`  
I am getting the following error:

```
---------------------------------------------------------------------------
ReadError Traceback (most recent call last)
<ipython-input-21-48bdd58aa112> in <module>()
----> 1 vgg16=torchvision.models.vgg16(pretrained=True)

/home/sarthak/anaconda2/lib/python2.7/site-packages/torchvision/models/vgg.pyc in vgg16(pretrained, **kwargs)
    122 model = VGG(make_layers(cfg['D']), **kwargs)
    123 if pretrained:
--> 124 model.load_state_dict(model_zoo.load_url(model_urls['vgg16']))
    125 return model
    126 

/home/sarthak/anaconda2/lib/python2.7/site-packages/torch/utils/model_zoo.pyc in load_url(url, model_dir)
     55 hash_prefix = HASH_REGEX.search(filename).group(1)
     56 _download_url_to_file(url, cached_file, hash_prefix)
---> 57 return torch.load(cached_file)
     58 
     59 

/home/sarthak/anaconda2/lib/python2.7/site-packages/torch/serialization.pyc in load(f, map_location, pickle_module)
    246 f = open(f, 'rb')
    247 try:
--> 248 return _load(f, map_location, pickle_module)
    249 finally:
    250 if new_fd:

/home/sarthak/anaconda2/lib/python2.7/site-packages/torch/serialization.pyc in _load(f, map_location, pickle_module)
    312 return deserialized_objects[int(saved_id)]
    313 
--> 314 with closing(tarfile.open(fileobj=f, mode='r:', format=tarfile.PAX_FORMAT)) as tar, \
    315 mkdtemp() as tmpdir:
    316 

/home/sarthak/anaconda2/lib/python2.7/tarfile.pyc in open(cls, name, mode, fileobj, bufsize, **kwargs)
   1691 else:
   1692 raise CompressionError("unknown compression type %r" % comptype)
-> 1693 return func(name, filemode, fileobj, **kwargs)
   1694 
   1695 elif "|" in mode:

/home/sarthak/anaconda2/lib/python2.7/tarfile.pyc in taropen(cls, name, mode, fileobj, **kwargs)
   1721 if mode not in ("r", "a", "w"):
   1722 raise ValueError("mode must be 'r', 'a' or 'w'")
-> 1723 return cls(name, mode, fileobj, **kwargs)
   1724 
   1725 @classmethod

/home/sarthak/anaconda2/lib/python2.7/tarfile.pyc in __init__ (self, name, mode, fileobj, format, tarinfo, dereference, ignore_zeros, encoding, errors, pax_headers, debug, errorlevel)
   1585 if self.mode == "r":
   1586 self.firstmember = None
-> 1587 self.firstmember = self.next()
   1588 
   1589 if self.mode == "a":

/home/sarthak/anaconda2/lib/python2.7/tarfile.pyc in next(self)
   2368 continue
   2369 elif self.offset == 0:
-> 2370 raise ReadError(str(e))
   2371 except EmptyHeaderError:
   2372 if self.offset == 0:

ReadError: invalid header
```

---

<div class="post-metadata">

**Author:** ![smth](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/smth/32/13_2.png) [@smth](https://discuss.pytorch.org/u/smth)\
**Post date:** [April 18, 2017, 2:49am UTC](https://discuss.pytorch.org/t/read-error-while-loading-vgg16/1942/2 "2017-04-18T02:49:36Z")

</div>

Either:

1. you are not on the latest pytorch `0.1.11`  
or
2. The download didn’t finish and the file is corrupted. Clear $HOME/.torch

---

<div class="post-metadata">

**Author:** ![sarthak1996](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/s/43a26b/32.png) [@sarthak1996](https://discuss.pytorch.org/u/sarthak1996)\
**Post date:** [April 18, 2017, 2:51am UTC](https://discuss.pytorch.org/t/read-error-while-loading-vgg16/1942/3 "2017-04-18T02:51:02Z")

</div>

I deleted the file and then downloaded it again but still the same error  
I get the same error with `vgg19` but not with `resnet50` and `alexnet`  
My pytorch version is `0.1.7`. How do I get the latest version.  
I tried `conda update pytorch` but it says up to date.

---

<div class="post-metadata">

**Author:** ![sarthak1996](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/s/43a26b/32.png) [@sarthak1996](https://discuss.pytorch.org/u/sarthak1996)\
**Post date:** [April 18, 2017, 3:20am UTC](https://discuss.pytorch.org/t/read-error-while-loading-vgg16/1942/4 "2017-04-18T03:20:47Z")

</div>

Thanks for the help. I updated the pytorch version and now it works
