MNIST-NameError: name ‘input_data’ is not defined解决办法
其实这是由于导入工具库后没有使用正确别名的原因,只要加入as input_data即可。
应改成如下代码:
import tensorflow.examples.tutorials.mnist.input_data as input_data
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)
分为训练数据与测试数据
train_images=mnist.train.images
train_labels = mnist.train.labels
test_images = mnist.test.images
test_labels = mnist.test.labels
print("train_images_shape:", train_images.shape)
print("train_labels_shape:", train_labels.shape)
print("test_images_shape:", test_images.shape)
print("test_labels_shape:", test_labels.shape)
import tensorflow.examples.tutorials.mnist.input_data as input_data
mnist=input_data.read_data_sets("MNIST_data/",one_hot=True)
结果
train_images_shape: (55000, 784)
train_labels_shape: (55000, 10)
test_images_shape: (10000, 784)
test_labels_shape: (10000, 10)
print("train_images:", train_images[1])
结果
train_images中28*28的图片像素值介于0-1之间
print("train_images:", train_images[0])
print("train_images:", train_labels[1])
结果
train_images: [0. 0. 0. 1. 0. 0. 0. 0. 0. 0.]
print("test_labels:", test_labels[0])
结果
test_labels: [0. 0. 0. 0. 0. 0. 0. 1. 0. 0.]