【问题标题】:MNIST fashion dataset not loadingMNIST 时尚数据集未加载
【发布时间】:2020-06-13 13:41:15
【问题描述】:

我正在做一个 ML/Tensorflow hello world,通过使用 MNIST 数据集来预测某种服装是什么,但是当我尝试使用 data.load_data() 将数据加载到我的 doe 时,它​​给了我这个错误:

使用 TensorFlow 后端。 从https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-labels-idx1-ubyte.gz下载数据 回溯(最近一次通话最后): 文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py”,第 1317 行,在 do_open encode_chunked=req.has_header('传输编码')) 文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py”,第 1229 行,在请求中 self._send_request(方法、url、正文、标头、encode_chunked) _send_request 中的文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py”,第 1275 行 self.endheaders(正文,encode_chunked=encode_chunked) 文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py”,第 1224 行,在 endheaders self._send_output(message_body, encode_chunked=encode_chunked) _send_output 中的文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py”,第 1016 行 自我发送(味精) 文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py”,第 956 行,在发送中 self.connect() 文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py”,第 1392 行,在连接中 服务器主机名=服务器主机名) wrap_socket 中的文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py”,第 412 行 会话=会话 _create 中的文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py”,第 853 行 self.do_handshake() 文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py”,第 1117 行,在 do_handshake 中 self._sslobj.do_handshake() ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败:无法获取本地颁发者证书 (_ssl.c:1056)

在处理上述异常的过程中,又发生了一个异常:

Traceback(最近一次调用最后一次): 文件“/Users/NAME/MNISTifying Clothing Predictor/lib/python3.7/site-packages/tensorflow_core/python/keras/utils/data_utils.py”,第 264 行,在 get_file urlretrieve(来源,fpath,dl_progress) 文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py”,第 247 行,在 urlretrieve 使用 contextlib.closing(urlopen(url, data)) 作为 fp: 文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py”,第 222 行,在 urlopen 返回 opener.open(url, 数据, 超时) 文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py”,第 525 行,打开 响应 = self._open(请求,数据) _open 中的文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py”,第 543 行 '_open',请求) _call_chain 中的文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py”,第 503 行 结果 = 函数(*args) https_open 中的文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py”,第 1360 行 上下文=self._context,check_hostname=self._check_hostname) 文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py”,第 1319 行,在 do_open 引发 URLError(err) urllib.error.URLError:

在处理上述异常的过程中,又发生了一个异常:

Traceback(最近一次调用最后一次): 文件“/Users/NAME/Python Projects/MNISTifying Clothing Predictor/MNISTifying Clothing Predictor.py”,第 10 行,在 (train_images, train_labels), (test_images, test_labels) = data.load_data() 文件“/Users/NAME/MNISTifying Clothing Predictor/lib/python3.7/site-packages/tensorflow_core/python/keras/datasets/fashion_mnist.py”,第 52 行,在 load_data path.append(get_file(fname, origin=base + fname, cache_subdir=dirname)) 文件“/Users/NAME/MNISTifying Clothing Predictor/lib/python3.7/site-packages/tensorflow_core/python/keras/utils/data_utils.py”,第 268 行,在 get_file 引发异常(error_msg.format(origin,e.errno,e.reason)) 例外:https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-labels-idx1-ubyte.gz 上的 URL 获取失败:无 -- [SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败:无法获取本地颁发者证书 (_ssl.c:1056)

这是我的代码: 这是我输入的代码:

将张量流导入为 tf 从张量流导入 keras 从 keras.datasets 导入 fashion_mnist 将 numpy 导入为 np 将 matplotlib.pyplot 导入为 plt

数据 = keras.datasets.fashion_mnist

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

打印(train_labels1)

【问题讨论】:

    标签: python python-3.x tensorflow keras


    【解决方案1】:

    转到您的 Python 文件夹并找到一个名为 Install Certificates.command 的脚本。双击运行它,它将安装一个名为certifi 的库。此工具将为您处理 SSL 认证。

    如果您使用的是 Mac,请点击此处:/Applications/Python\ 3.6/Install\ Certificates.command

    【讨论】:

      【解决方案2】:

      您提供的以下代码运行良好,

      import tensorflow as tf 
      from tensorflow import keras 
      from keras.datasets import fashion_mnist 
      import numpy as np 
      import matplotlib.pyplot as plt
      
      data = keras.datasets.fashion_mnist
      
      (train_images, train_labels), (test_images, test_labels) = data.load_data()
      
      print(train_labels)
      

      但是当您从特定网站下载数据时受到该浏览器的限制。请参考此链接以修复 SSLCertVerificationError。 Link

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-04-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-12-11
        • 1970-01-01
        相关资源
        最近更新 更多