python-3.x - 异常 : URL fetch failure when loading data

标签 python-3.x tensorflow keras python-3.7 tensorflow2.0

我正在尝试设置我的机器以运行 Tensorflow 2。我从未使用过 Tensorflow,只是下载了 Python 3.7。我不确定这是否是我机器的问题。我按照 TensorFlow's website 上列出的安装说明进行操作.我按照安装说明进行操作,似乎一切正常。

苹果操作系统 10.15.3

python 3.7

tensorflow 2

我创建了一个小程序来测试一些东西。这是我的:

import io
import matplotlib.pyplot as plt
import tensorflow as tf
from tensorflow import keras
import numpy as np

data = keras.datasets.fashion_mnist

(train_images, train_labels), (test_images, test_labels) = data.load_data()

当我运行 data.load_data() 时出现此错误:

Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-labels-idx1-ubyte.gz
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1317, in do_open
    encode_chunked=req.has_header('Transfer-encoding'))
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1244, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1290, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1239, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1026, in _send_output
    self.send(msg)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 966, in send
    self.connect()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1414, in connect
    server_hostname=server_hostname)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 423, in wrap_socket
    session=session
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 870, in _create
    self.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 1139, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tensorflow/python/keras/utils/data_utils.py", line 263, in get_file
    urlretrieve(origin, fpath, dl_progress)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 247, in urlretrieve
    with contextlib.closing(urlopen(url, data)) as fp:
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 525, in open
    response = self._open(req, data)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 543, in _open
    '_open', req)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 503, in _call_chain
    result = func(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1360, in https_open
    context=self._context, check_hostname=self._check_hostname)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1319, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/jacksonmelcher/Development/Personal/TensorFlow/tf_embeddings.py", line 12, in <module>
    (train_images, train_labels), (test_images, test_labels) = data.load_data()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tensorflow/python/keras/datasets/fashion_mnist.py", line 75, in load_data
    paths.append(get_file(fname, origin=base + fname, cache_subdir=dirname))
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tensorflow/python/keras/utils/data_utils.py", line 267, in get_file
    raise Exception(error_msg.format(origin, e.errno, e.reason))
Exception: URL fetch failure on https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-labels-idx1-ubyte.gz: None -- [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)

同样,这是我第一次使用 Tensorflow 和 Keras,但这似乎是与 google 的 api 服务的连接问题。

任何帮助将不胜感激,因为我找不到任何东西。

最佳答案

您可以尝试使用 Chrome 访问下载数据集 this link is dataset of 然后更改您的代码

(train_images, train_labels), (test_images, test_labels) = data.load_data()

作为

(train_images, train_labels), (test_images, test_labels) = data.load_data(path='the file path you download')

希望能帮到你!

关于python-3.x - 异常 : URL fetch failure when loading data,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60255470/

相关文章:

python - 如何获取查询集的不同值?

python - keras中张量之间的划分

tensorflow - 如何将 hdf5 转换为 tensorflow 检查点

machine-learning - Keras 有状态 RNN 数据分批的正确方法

python - 正则表达式:如何匹配语言的字符集(有一些异常(exception))?

python - 我正在犯什么语法错误?

tensorflow - TensorFlow 中的引导反向传播

python - tf.keras `predict()` 得到不同的结果

python - 如何在我的图层中找到不可微分的操作?

python - 从python列表的每个元素中删除文本