from __future__ import absolute_import, division, print_function, unicode_literals import tensorflow as tf mnist = tf.keras.datasets.mnist (x_train, y_train), (x_test, y_test) = mnist.load_data() x_train, x_test = x_train/ 255.0, x_test / 255.0 model = tf.keras.models.Sequential([ tf.keras.layers.Flatten(input_shape=(28, 28)), tf.keras.layers.Dense(128, activation = 'relu'), tf.keras.layers.Dropout(0.2), tf.keras.layers.Dense(10, activation= 'softmax') ]) model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) model.fit(x_train, y_train, epochs=5) model.evaluate(x_test, y_test, verbose=2)
Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz Traceback (most recent call last): File "/opt/anaconda3/envs/tensorflow2/lib/python3.7/urllib/request.py", line 1317, in do_open encode_chunked=req.has_header('Transfer-encoding')) File "/opt/anaconda3/envs/tensorflow2/lib/python3.7/http/client.py", line 1229, in request self._send_request(method, url, body, headers, encode_chunked) File "/opt/anaconda3/envs/tensorflow2/lib/python3.7/http/client.py", line 1275, in _send_request self.endheaders(body, encode_chunked=encode_chunked) File "/opt/anaconda3/envs/tensorflow2/lib/python3.7/http/client.py", line 1224, in endheaders self._send_output(message_body, encode_chunked=encode_chunked) File "/opt/anaconda3/envs/tensorflow2/lib/python3.7/http/client.py", line 1016, in _send_output self.send(msg) File "/opt/anaconda3/envs/tensorflow2/lib/python3.7/http/client.py", line 956, in send self.connect() File "/opt/anaconda3/envs/tensorflow2/lib/python3.7/http/client.py", line 1392, in connect server_hostname=server_hostname) File "/opt/anaconda3/envs/tensorflow2/lib/python3.7/ssl.py", line 412, in wrap_socket session=session File "/opt/anaconda3/envs/tensorflow2/lib/python3.7/ssl.py", line 850, in _create self.do_handshake() File "/opt/anaconda3/envs/tensorflow2/lib/python3.7/ssl.py", line 1108, in do_handshake self._sslobj.do_handshake() ConnectionResetError: [Errno 54] Connection reset by peer
數據集下不下來python
mnist.npz
百度網盤上有,直接下載下來,放到 .keras/datasets
目錄下,再次運行。api
mac 電腦上找了下這個目錄, 在根目錄下輸入:session
find ./ | grep datasets
看到有一條:socket
.//.keras/datasets
將下載好的 mnist.npz
放入這個目錄後, 運行代碼。google