无法运行以使用CiFAR10、PyCharm/python和pyplot渲染/显示图像

无法运行以使用CiFAR10、PyCharm/python和pyplot渲染/显示图像,python,tensorflow,matplotlib,keras,pycharm,Python,Tensorflow,Matplotlib,Keras,Pycharm,这是我的第一篇帖子 我目前正在完成一门名为“构建和训练数据模型以识别图像中的对象!”的Udemy课程(在2019年MacBook Pro 10.15.6版上运行,使用PyCharm IDE),其中一项任务我遇到了困难 该任务需要运行以下代码才能从CiFAR10数据集中打开/渲染图像: from PIL import Image labels = ['airplane', 'automobile', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', '

这是我的第一篇帖子

我目前正在完成一门名为“构建和训练数据模型以识别图像中的对象!”的Udemy课程(在2019年MacBook Pro 10.15.6版上运行,使用PyCharm IDE),其中一项任务我遇到了困难

该任务需要运行以下代码才能从CiFAR10数据集中打开/渲染图像:

from PIL import Image

labels = ['airplane', 'automobile', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck']

from keras.datasets import cifar10
# X_train = images, y_train = labels
(X_train, y_train), (X_test, y_test) = cifar10.load_data()

index = 5
display_image = X_train[index]
display_label = y_train[index][0]

from matplotlib import pyplot as plt

final_image = plt.imshow(display_image)
final_image.show()
然而,我得到以下错误,不知道该怎么办。我在这门课上发过帖子,但我3岁了,我不认为有人能跟上它的进度,也没有人能收到回复

/Users/muratuckan/PycharmProjects/TensorFlow/venv/bin/python /Users/muratuckan/PycharmProjects/TensorFlow/ImageRecognitionTrainer.py
Downloading data from https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1350, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1255, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1301, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1250, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1010, in _send_output
    self.send(msg)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 950, in send
    self.connect()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1424, in connect
    self.sock = self._context.wrap_socket(self.sock,
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line 500, in wrap_socket
    return self.sslsocket_class._create(
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line 1040, in _create
    self.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line 1309, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/muratuckan/PycharmProjects/TensorFlow/venv/lib/python3.8/site-packages/tensorflow/python/keras/utils/data_utils.py", line 278, in get_file
    urlretrieve(origin, fpath, dl_progress)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 247, in urlretrieve
    with contextlib.closing(urlopen(url, data)) as fp:
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 525, in open
    response = self._open(req, data)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 542, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 502, in _call_chain
    result = func(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1393, in https_open
    return self.do_open(http.client.HTTPSConnection, req,
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1353, 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:1123)>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/muratuckan/PycharmProjects/TensorFlow/ImageRecognitionTrainer.py", line 19, in <module>
    (X_train, y_train), (X_test, y_test) = cifar10.load_data()
  File "/Users/muratuckan/PycharmProjects/TensorFlow/venv/lib/python3.8/site-packages/tensorflow/python/keras/datasets/cifar10.py", line 52, in load_data
    path = get_file( dirname, origin=origin, untar=True)
  File "/Users/muratuckan/PycharmProjects/TensorFlow/venv/lib/python3.8/site-packages/tensorflow/python/keras/utils/data_utils.py", line 282, in get_file
    raise Exception(error_msg.format(origin, e.errno, e.reason))
Exception: URL fetch failure on https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz: None -- [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)

Process finished with exit code 1
/Users/muratuchan/PycharmProjects/TensorFlow/venv/bin/python/Users/muratuchan/PycharmProjects/TensorFlow/ImageRecognitionTrainer.py
从下载数据https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz
回溯(最近一次呼叫最后一次):
文件“/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py”,第1350行,打开
h、 请求(请求获取方法()、请求选择器、请求数据、标题、,
请求中的文件“/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py”,第1255行
self.\u发送\u请求(方法、url、正文、标题、编码\u分块)
文件“/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py”,第1301行,在发送请求中
self.endheaders(body,encode\u chunked=encode\u chunked)
文件“/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py”,第1250行,在endheaders中
self.\u发送\u输出(消息体,encode\u chunked=encode\u chunked)
文件“/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py”,第1010行,在发送输出中
self.send(msg)
文件“/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py”,第950行,在send中
self.connect()
文件“/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py”,第1424行,在connect中
self.sock=self.\u context.wrap\u套接字(self.sock,
文件“/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py”,第500行,在wrap_套接字中
返回self.sslsocket\u类。\u创建(
文件“/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py”,第1040行,在
self.do_握手
文件“/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py”,第1309行,在do_握手中
赛尔夫:握手
ssl.SSLCertVerificationError:[ssl:证书\u验证\u失败]证书验证失败:无法获取本地颁发者证书(\u ssl.c:1123)
在处理上述异常期间,发生了另一个异常:
回溯(最近一次呼叫最后一次):
文件“/Users/muratuckan/PycharmProjects/TensorFlow/venv/lib/python3.8/site packages/TensorFlow/python/keras/utils/data_utils.py”,第278行,在get_文件中
urlretrieve(源、fpath、dl_进度)
文件“/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py”,第247行,在urlretrieve中
使用contextlib.closing(urlopen(url,data))作为fp:
urlopen中的文件“/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py”,第222行
返回opener.open(url、数据、超时)
文件“/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py”,第525行,打开
响应=自身打开(请求,数据)
文件“/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py”,第542行,打开
结果=self.\u调用\u链(self.handle\u打开,协议,协议+
文件“/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py”,第502行,在调用链中
结果=func(*args)
文件“/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py”,第1393行,https_open
返回self.do_open(http.client.HTTPSConnection,req,
dou open中的文件“/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py”,第1353行
引发URL错误(err)
urllib.error.urleror:
在处理上述异常期间,发生了另一个异常:
回溯(最近一次呼叫最后一次):
文件“/Users/muratuckan/PycharmProjects/TensorFlow/ImageRecognitionTrainer.py”,第19行,在
(X_列,y_列),(X_测试,y_测试)=cifar10.负载数据()
文件“/Users/muratuckan/PycharmProjects/TensorFlow/venv/lib/python3.8/site packages/TensorFlow/python/keras/datasets/cifar10.py”,第52行,加载数据
path=get_文件(dirname,origin=origin,untar=True)
文件“/Users/muratuckan/PycharmProjects/TensorFlow/venv/lib/python3.8/site packages/TensorFlow/python/keras/utils/data_utils.py”,第282行,在get_文件中
引发异常(错误消息格式(origin,e.errno,e.reason))
异常:上的URL获取失败https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz:None--[SSL:CERTIFICATE\u VERIFY\u FAILED]CERTIFICATE VERIFY失败:无法获取本地颁发者证书(\u SSL.c:1123)
进程已完成,退出代码为1
我发现的唯一信息提到我可能有一个不稳定的互联网连接,但事实并非如此

在一些帖子中,我注意到他们的run终端上写着“使用TensorFlow后端”,而我的却没有这样说,它只写着“从服务器下载数据”


请帮助。谢谢你。

这是由@tsj回答的。我要做的是在python文件夹中找到“Install Certificates.command”(我只是使用搜索搜索它)并运行该文件。我重新启动了pycharm并更正了该错误。

这是由@tsj回答的。我要做的是找到“Install Certificates.command”“在python文件夹中(我只是使用搜索功能搜索了它)并运行了该文件。我重新启动了pycharm并更正了该错误。

我无法编辑我的帖子,但帖子的开头应该是“您好,这是我的第一篇帖子…”和单词uddery=Udemy(自动更正)请您的问题添加一些解释或代码,而不是像您那样使用注释。堆栈跟踪可能看起来过多