質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
機械学習

機械学習は、データからパターンを自動的に発見し、そこから知能的な判断を下すためのコンピューターアルゴリズムを指します。人工知能における課題のひとつです。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

1回答

4147閲覧

tensorflow2, mnistが読み込めない

Jumptt

総合スコア1

機械学習

機械学習は、データからパターンを自動的に発見し、そこから知能的な判断を下すためのコンピューターアルゴリズムを指します。人工知能における課題のひとつです。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2020/07/04 22:34

前提・実現したいこと

tensorflow の学習中にmnistのデータセットを用いようとしたのですが、以下のようなエラーが発生しました。なぜ発生するのかお教えいただきたいです。

発生している問題・エラーメッセージ

Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz --------------------------------------------------------------------------- SSLCertVerificationError Traceback (most recent call last) /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py in do_open(self, http_class, req, **http_conn_args) 1318 try: -> 1319 h.request(req.get_method(), req.selector, req.data, headers, 1320 encode_chunked=req.has_header('Transfer-encoding')) /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py in request(self, method, url, body, headers, encode_chunked) 1229 """Send a complete request to the server.""" -> 1230 self._send_request(method, url, body, headers, encode_chunked) 1231 /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py in _send_request(self, method, url, body, headers, encode_chunked) 1275 body = _encode(body, 'body') -> 1276 self.endheaders(body, encode_chunked=encode_chunked) 1277 /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py in endheaders(self, message_body, encode_chunked) 1224 raise CannotSendHeader() -> 1225 self._send_output(message_body, encode_chunked=encode_chunked) 1226 /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py in _send_output(self, message_body, encode_chunked) 1003 del self._buffer[:] -> 1004 self.send(msg) 1005 /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py in send(self, data) 943 if self.auto_open: --> 944 self.connect() 945 else: /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py in connect(self) 1398 -> 1399 self.sock = self._context.wrap_socket(self.sock, 1400 server_hostname=server_hostname) /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py in wrap_socket(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, session) 499 # ctx._wrap_socket() --> 500 return self.sslsocket_class._create( 501 sock=sock, /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py in _create(cls, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, context, session) 1039 raise ValueError("do_handshake_on_connect should not be specified for non-blocking sockets") -> 1040 self.do_handshake() 1041 except (OSError, ValueError): /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py in do_handshake(self, block) 1308 self.settimeout(None) -> 1309 self._sslobj.do_handshake() 1310 finally: SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108) During handling of the above exception, another exception occurred: URLError Traceback (most recent call last) /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tensorflow/python/keras/utils/data_utils.py in get_file(fname, origin, untar, md5_hash, file_hash, cache_subdir, hash_algorithm, extract, archive_format, cache_dir) 262 try: --> 263 urlretrieve(origin, fpath, dl_progress) 264 except HTTPError as e: /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py in urlretrieve(url, filename, reporthook, data) 246 --> 247 with contextlib.closing(urlopen(url, data)) as fp: 248 headers = fp.info() /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context) 221 opener = _opener --> 222 return opener.open(url, data, timeout) 223 /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py in open(self, fullurl, data, timeout) 524 sys.audit('urllib.Request', req.full_url, req.data, req.headers, req.get_method()) --> 525 response = self._open(req, data) 526 /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py in _open(self, req, data) 541 protocol = req.type --> 542 result = self._call_chain(self.handle_open, protocol, protocol + 543 '_open', req) /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args) 501 func = getattr(handler, meth_name) --> 502 result = func(*args) 503 if result is not None: /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py in https_open(self, req) 1361 def https_open(self, req): -> 1362 return self.do_open(http.client.HTTPSConnection, req, 1363 context=self._context, check_hostname=self._check_hostname) /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py in do_open(self, http_class, req, **http_conn_args) 1321 except OSError as err: # timeout error -> 1322 raise URLError(err) 1323 r = h.getresponse() URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)> During handling of the above exception, another exception occurred: Exception Traceback (most recent call last) <ipython-input-17-49e15817fb9c> in <module> ----> 1 m_data=mnist.load_data() /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tensorflow/python/keras/datasets/mnist.py in load_data(path) 56 """ 57 origin_folder = 'https://storage.googleapis.com/tensorflow/tf-keras-datasets/' ---> 58 path = get_file( 59 path, 60 origin=origin_folder + 'mnist.npz', /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tensorflow/python/keras/utils/data_utils.py in get_file(fname, origin, untar, md5_hash, file_hash, cache_subdir, hash_algorithm, extract, archive_format, cache_dir) 265 raise Exception(error_msg.format(origin, e.code, e.msg)) 266 except URLError as e: --> 267 raise Exception(error_msg.format(origin, e.errno, e.reason)) 268 except (Exception, KeyboardInterrupt) as e: 269 if os.path.exists(fpath): Exception: URL fetch failure on https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz: None -- [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)

該当のソースコード

python

1import tensorflow as tf 2mnist = tf.keras.datasets.mnist 3m_data=mnist.load_data()

試したこと

Exceptionで挙げられているurlに飛んでみると、no such objectと返されます。
しかし、書籍を見ても、他のサイトを見てもソースコードは同じなので困惑しています。

補足情報(FW/ツールのバージョンなど)

実行環境 Jupyter Notebook

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

具体的にどうすればよいか?を示す回答ではありませんが、参考まで。
mnistデータ取得
環境構築ガイド 〉 macOS環境のPython - SSL証明書のインストール

投稿2020/07/04 22:52

編集2020/07/05 02:04
can110

総合スコア38266

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Jumptt

2020/07/05 01:55

大変参考になる回答ありがとうございます。 過去質問に参照されていたリンクに飛び、 /Applications/Python\ 3.8/Install\ Certificates.command /Applications/Python\ 3.8.2/Install\ Certificates.command の両方をターミナルで実行したのですが、どちらもzsh: no such file or directoryとなってしまいました。
can110

2020/07/05 02:05

GUI上での操作を説明しているサイトが見つかりましたので回答に追記しています。
Jumptt

2020/07/05 02:27

わざわざありがとうございます。 本当にたすかりました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問