我正在尝试使用Macbook中的keras代码导入mnist数据集。但是它给出了下面的错误。
# Loading the data
from keras.datasets import mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
我得到的错误:
During handling of the above exception, another exception occurred:
Exception Traceback (most recent call last)
<ipython-input-11-fdb6855f8337> in <module>()
2 from keras.datasets import mnist
3
----> 4 (x_train, y_train), (x_test, y_test) = mnist.load_data()
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/keras/datasets/mnist.py in load_data(path)
21 path = get_file(path,
22 origin='https://s3.amazonaws.com/img-datasets/mnist.npz',
---> 23 file_hash='8a61469f7ea1b51cbae51d4f78837e45')
24 f = np.load(path)
25 x_train, y_train = f['x_train'], f['y_train']
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/keras/utils/data_utils.py in get_file(fname, origin, untar, md5_hash, file_hash, cache_subdir, hash_algorithm, extract, archive_format, cache_dir)
222 urlretrieve(origin, fpath, dl_progress)
223 except URLError as e:
--> 224 raise Exception(error_msg.format(origin, e.errno, e.reason))
225 except HTTPError as e:
226 raise Exception(error_msg.format(origin, e.code, e.msg))
Exception: URL fetch failure on https://s3.amazonaws.com/img-datasets/mnist.npz: None -- [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)
提前致谢
(注意:我尝试删除.keras/datasets/
中的文件,如issue中所述
答案 0 :(得分:1)
在Mac上,转到keras文件夹。应该位于〜/ .keras /
那里将有一个名为数据集的文件夹。从here下载数据集并将其移至该文件夹。现在,运行相同的代码。
答案 1 :(得分:1)
如果在Mac上遇到此问题,那是因为Mac上的Python3.6没有证书,并且无法从Github验证证书。
运行以下命令以安装证书:
/Applications/Python 3.6/Install Certificates.command
查看这些链接以获取有关此问题的更多信息