How can I import the MNIST dataset that has been manually downloaded?

前端 未结 4 1110
北海茫月
北海茫月 2021-02-05 18:36

I have been experimenting with a Keras example, which needs to import MNIST data

from keras.datasets import mnist
import numpy as np
(x_train, _), (x_test, _) =          


        
4条回答
  •  礼貌的吻别
    2021-02-05 18:56

    Keras file is located into a new path in Google Cloud Storage (Before it was in AWS S3):

    https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz
    

    When using:

    tf.keras.datasets.mnist.load_data()

    You can pass a path parameter.

    load_data() will call get_file() which takes as parameter fname, if path is a full path and file exists, it will not be downloaded.

    Example:

    # gsutil cp gs://tensorflow/tf-keras-datasets/mnist.npz /tmp/data/mnist.npz
    # python3
    >>> import tensorflow as tf
    >>> path = '/tmp/data/mnist.npz'
    >>> (train_images, train_labels), (test_images, test_labels) = tf.keras.datasets.mnist.load_data(path)
    >>> len(train_images)
    >>> 60000
    

提交回复
热议问题