在Keras中下载ResNet50会生成“ SSL:CERTIFICATE_VERIFY_FAILED”

AlG*_*ara 4 python keras tensorflow

我在Tensorflow上使用python 3.6和Keras(2.0.9)

尝试下载经过训练的resnet50模型,但遇到以下错误:异常:https : //github.com/fchollet/deep-learning-models/releases/download/v0.2/resnet50_weights_tf_dim_ordering_tf_kernels.h5上的URL提取失败:无- [SSL:CERTIFICATE_VERIFY_FAILED]证书验证失败(_ssl.c:777)

以下是使用的代码:

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])
Run Code Online (Sandbox Code Playgroud)

sos*_*418 12

您可以考虑一下

下载数据集之前,我还使用SSL模块。它解决了这个问题!

像这样:

import ssl

ssl._create_default_https_context = ssl._create_unverified_context
Run Code Online (Sandbox Code Playgroud)

  • 有效,但这究竟是做什么的? (3认同)

小智 8

刚遇到同样的问题。我在这里找到了答案: Mac OSX python ssl.SSLError:[SSL:CERTIFICATE_VERIFY_FAILED]证书验证失败(_ssl.c:749)

浏览到Applications / Python 3.6文件夹,然后双击Install Certificates.command

我在Mac上对其进行了测试,并且可以正常工作。