使用pip安装tensorflow
python3 -m pip install tensorflow
使用tensorflow提供的input_data.read_data_sets
方法载入mnist数据集,并将其保存在项目的data目录中(该目录依据情况指定即可)
# coding:utf-8
from tensorflow.examples.tutorials.mnist import input_data
# input_data.read_data_sets 将mnist自动划分为train,validation和test数据集
mnist = input_data.read_data_sets("../data",one_hot=True)
print("Training data size:",mnist.train.num_examples)
print("Validation data size:",mnist.validation.num_examples)
print("Testing data size:", mnist.test.num_examples)
print("Example training data:",mnist.train.images[0])
print("Example training data label:",mnist.train.labels[0])
网友评论