9

I am using python 3.6 and Keras (2.0.9) over Tensorflow

trying to download trained models of resnet50 but encounter the following error: Exception: URL fetch failure on https://github.com/fchollet/deep-learning-models/releases/download/v0.2/resnet50_weights_tf_dim_ordering_tf_kernels.h5: None -- [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)

the following is the code used:

from keras.applications.resnet50 import ResNet50
from keras.preprocessing import image
from keras.applications.resnet50 import preprocess_input, decode_predictions
import numpy as np

model = ResNet50(weights='imagenet')

img_path = 'elephant.jpg'
img = image.load_img(img_path, target_size=(224, 224))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
model.summary()
preds = model.predict(x)

print('Predicted:', decode_predictions(preds, top=3)[0])
AlGhara
  • 99
  • 1
  • 3
  • Does this answer your question? [Mac OSX python ssl.SSLError: \[SSL: CERTIFICATE\_VERIFY\_FAILED\] certificate verify failed (\_ssl.c:749)](https://stackoverflow.com/questions/42098126/mac-osx-python-ssl-sslerror-ssl-certificate-verify-failed-certificate-verify) – AMC Jan 21 '20 at 03:06

3 Answers3

32

You can consider this.

I also use the SSL module before downloading the data set. It solved this problem!

Like this:

import ssl

ssl._create_default_https_context = ssl._create_unverified_context
sos418
  • 782
  • 8
  • 13
  • 3
    Works, but what exactly is this doing? – wordsforthewise Mar 28 '19 at 20:33
  • Does not work, getting a 403 foridden error for github: Exception: URL fetch failure on https://github.com/keras-team/keras-applications/releases/download/resnet/resnet50_weights_tf_dim_ordering_tf_kernels.h5: 403 -- Forbidden – gilgamash Sep 12 '20 at 12:02
  • I had the same problem for "InceptionV3" -- the solution helped in my case. To answer @wordsforthewise 's question: I guess that this way you "allow" downloading from "unverified" domains. Maybe SSL certificate expired for the domain or something like that. – Mikolaj Buchwald Apr 28 '23 at 22:38
8

Just ran into the same issue. I found the answer here: Mac OSX python ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)

Browse to Applications/Python 3.6 folder and double-click Install Certificates.command

I tested it on Mac and it worked.

Roman Mirochnik
  • 196
  • 1
  • 8
1

Combining either or both the @Roman Mirochnik and @sos418 method should work i.e.

  1. Browse to Applications/Python 3.x folder and double-click Install Certificates.command

  2. Add to code:

    import ssl
    ssl._create_default_https_context = ssl._create_unverified_context
    
Taiwotman
  • 885
  • 14
  • 27