pytorch / vision

Datasets, Transforms and Models specific to Computer Vision
https://pytorch.org/vision
BSD 3-Clause "New" or "Revised" License
15.99k stars 6.92k forks source link

Trying to CIFAR-10 from torchvision.datasets and receiving URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1129)> #5039

Open BenjaminPoole opened 2 years ago

BenjaminPoole commented 2 years ago

🐛 Bug

Trying to download CIFAR-10 from torchvision.datasets and receiving URLError:<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1129)> when downloading Download fails

To Reproduce

Steps to reproduce the behavior:

dataset = torchvision.datasets.CIFAR10(root='dataset/',train=True,transform=transform,download=True)

Expected behavior

Pre-trained models should be downloaded without certificate failures

Environment

PyTorch version: 1.9.1+cu111 Is debug build: False CUDA used to build PyTorch: 11.1 ROCM used to build PyTorch: N/A

OS: Microsoft Windows 10 Pro GCC version: Could not collect Clang version: Could not collect CMake version: Could not collect Libc version: N/A

Python version: 3.9.5 (tags/v3.9.5:0a7dcbd, May 3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)] (64-bit runtime) Python platform: Windows-10-10.0.19044-SP0 Is CUDA available: True CUDA runtime version: 11.2.67

GPU models and configuration: GPU 0: NVIDIA GeForce GT 1030 Nvidia driver version: 465.89 cuDNN version: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\bin\cudnn_ops_train64_8.dll HIP runtime version: N/A MIOpen runtime version: N/A

Versions of relevant libraries: [pip3] numpy==1.19.5

[pip3] pytorch-lightning==1.5.1

[pip3] torch==1.9.1+cu111

[pip3] torch-tb-profiler==0.2.1

[pip3] torchaudio==0.9.1

[pip3] torchmetrics==0.6.0

[pip3] torchvision==0.10.1+cu111

cc @pmeier @YosuaMichael @fmassa @vfdev-5

BenjaminPoole commented 2 years ago

I found turning off SSL verification solved this for me

import ssl ssl._create_default_https_context = ssl._create_unverified_context

malfet commented 2 years ago

Moving issue to https://github.com/pytorch/vision

pmeier commented 2 years ago

Internally, we do something like

from torchvision.datasets.utils import download_and_extract_archive

download_and_extract_archive(
    "https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz",
    ".",
    md5="c58f30108f718f92721af3b95e74349a",
)

This works for me without modifying SSL in any form:

>>> import ssl
>>> ssl._create_default_https_context
>>> <function create_default_context at 0x7f354d653950>

The only thing that stands out from the envs posted here and in #6007 is that they are Windows builds. I'll try to reproduce in a VM.

rsokl commented 2 years ago

Any status update on this? My students are hitting this frequently.

pmeier commented 2 years ago

So far I'm unable to reproduce this with this VM. @rsokl if you or your students are

hitting this frequently

would you be able to either debug this or compile a minimal example / setup I can use to reproduce?

dstkibrom commented 1 year ago

I have been getting similar error but fixed it with the recommendation from @pmeier, but instead of adding the ssl script like he suggested, editing the Pytorch library url has worked for me. In the library the url has a value of "https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz". To bypass the error we just have to change the url to one with out the ssl, http://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz. To do this:

torchvision.datasets.CIFAR10.url="http://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz"

then the torch vision data download should work fine without error.

all_images = torchvision.datasets.CIFAR10(train=True, root="data",download=True)

kennedy-u commented 1 year ago

I found turning off SSL verification solved this for me

import ssl ssl._create_default_https_context = ssl._create_unverified_context

Hi Benjamin, this solution worked for me as well, thanks

pkarthik88 commented 10 months ago

Faced this issue recently. The url doesn't seem to work anymore.

torchvision.datasets.CIFAR10.url="https://data.brainchip.com/dataset-mirror/cifar10/cifar-10-python.tar.gz"

Updating the url to the above works.