0
点赞
收藏
分享

微信扫一扫

tensorflow mnist手写字体读取使用


1 . 关于mnist手写字体的详细说明可见:​​http://yann.lecun.com/exdb/mnist/​​ ,简言之所包含的数据已经经过大量预处理,可简单的直接应用到机器学习的任务中。


2 . 在tensorflow中已经有相关的读取操作, 以下代码为简单应用并可视化:

from tensorflow.examples.tutorials.mnist import input_data
import matplotlib.pyplot as plt

img_size = 28
# img_size_flat = img_size * img_size
img_shape = (img_size, img_size)
# num_classes = 10

def plot_images(images, cls_true, cls_pred=None):
assert len(images) == len(cls_true) == 9

fig, axes = plt.subplots(3, 3)
fig.subplots_adjust(hspace=0.3, wspace=0.3)

for i, ax in enumerate(axes.flat):
ax.imshow(images[i].reshape(img_shape), cmap='binary')

if cls_pred is None:
xlabel = "True: {0}".format(cls_true[i])
else:
xlabel = "True: {0}, Pred: {1}".format(cls_true[i], cls_pred[i])

ax.set_xlabel(xlabel)

ax.set_xticks([])
ax.set_yticks([])
plt.show()


data = input_data.read_data_sets("data/MNIST/", one_hot=False)
# 第一次运行较慢,程序会下载mnist数据集

# print(data.test.images[0].reshape(img_shape))
images = data.test.images[0:9]
cls_true = data.test.labels[0:9]
# print(cls_true)

3 . 效果如图:

tensorflow mnist手写字体读取使用_tensorflow


举报

相关推荐

0 条评论