Tensorflow之快速加载MNIST数据集

一世执手 提交于 2019-12-05 07:47:18
from tensorflow.examples.tutorials.mnist import input_data
import tensorflow as tf

def myprint(v):
    print(v)
    print(type(v))
    try:
        print(v.shape)
    except:
        try:
            print(len(v))
        except:
            pass


if __name__ == '__main__':
    mnist = input_data.read_data_sets('./input_data', one_hot=True, validation_size=100)
    myprint(mnist.train.labels)
    myprint(mnist.validation.labels)
    myprint(mnist.test.labels)
    myprint(mnist.train.images)
    myprint(mnist.validation.images)
    myprint(mnist.test.images)


可能由于网络问题,程序无法把数据集下载到'./input_data'目录下,可以手动下载到对应目录:(mnist官网:http://yann.lecun.com/exdb/mnist/  The MNIST database of handwritten digits, available from this page, has a training set of 60,000 examples, and a test set of 10,000 examples.)

train-images-idx3-ubyte.gz:  training set images (9912422 bytes) 
train-labels-idx1-ubyte.gz:  training set labels (28881 bytes) 
t10k-images-idx3-ubyte.gz:   test set images (1648877 bytes) 
t10k-labels-idx1-ubyte.gz:   test set labels (4542 bytes)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!