deep-learning-with-pytorch / dlwpt-code

Code for the book Deep Learning with PyTorch by Eli Stevens, Luca Antiga, and Thomas Viehmann.
https://www.manning.com/books/deep-learning-with-pytorch
4.69k stars 1.98k forks source link

SSL: CERTIFICATE_VERIFY_FAILED Solution while downloading CIFAR10 #87

Open naiborhujosua opened 2 years ago

naiborhujosua commented 2 years ago

For anyone who is getting errors while downloading CIFAR-10, you can use this trick

## by turning off SSL verification 
import ssl
ssl._create_default_https_context = ssl._create_unverified_context

from torchvision import datasets, transforms
data_path = '../data-unversioned/p1ch7/'
cifar10 = datasets.CIFAR10(
    data_path, train=True, download=True,
    transform=transforms.Compose([
        transforms.ToTensor(),
        transforms.Normalize((0.4915, 0.4823, 0.4468),
                             (0.2470, 0.2435, 0.2616))
    ]))