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)
plot_images(images=images, cls_true=cls_true)

3 . 效果如图:
这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值