谷歌把数据集从tensorflow里独立出来了,需要先pip install tensorflow_datasets。但像mnist这样常用的包在原来的地方依然能找到。所有数据的列表在下面的网站:https://tensorflow.google.cn/datasets
回到问题,从tensorflow_datasets读取文件还是很简单的。
import tensorflow as tf
import tensorflow_datasets as tfds
x_train,x_test = tfds.load( name="mnist",split=["train","test"] )
print(x_train)
<PrefetchDataset shapes: {image: (28, 28, 1), label: ()}, types: {image: tf.uint8, label: tf.int64}>
类型是PrefetchDataset,其实就是Da