MLP手写数字识别(1)-MNIST数据集下载与可视化(tensorflow)

1.下载与查看MNIST数据集

python 复制代码
from keras.datasets import mnist

(x_train_image,y_train_label),(x_test_image,y_test_label) = mnist.load_data()
print("train images:",x_train_image.shape)
print("test images:",x_test_image.shape)
print("train labels:",y_train_label.shape)
print("test labels:",y_test_label.shape)

代码下载数据集后,会将数据保存在四个集合中,分别为:

  • x_train_image:保存训练数字图像,共60000个。
  • y_train_label:保存训练数字图像的正确数字,共60000个。
  • x_test_image:保存测试数字图像,共10000个。
  • y_test_label:保存测试数字图像的正确数字,共10000个。
  • 数据保存位置'~/.keras/datasets/'+path

2.图像绘制

image是一副28*28的灰度图片,数组中每一个单元的数值在0~255之间。其中0表示白色,255表示黑色。

python 复制代码
import matplotlib.pyplot as plt
def plot_image(image):
    fig = plt.gcf()
    fig.set_size_inches(2,2)
    plt.imshow(image,cmap='binary')
    plt.show()
plot_image(x_train_image[0])
print(y_train_label[0])
print(x_train_image[0])

3.绘制多张图像

python 复制代码
def plot_images_lables(images,labels,start_idx,num=5):
    fig = plt.gcf()
    fig.set_size_inches(12,14)
    for i in range(num):
        ax = plt.subplot(1,num,1+i)
        ax.imshow(images[start_idx+i],cmap='binary')
        title = 'label=' + str(labels[start_idx+i])
        ax.set_title(title,fontsize=10)
        ax.set_xticks([])
        ax.set_yticks([])
    plt.show()
plot_images_lables(x_train_image,y_train_label,0,5)
plot_images_lables(x_test_image,y_test_label,0,5)
相关推荐
思绪无限10 分钟前
YOLOv5至YOLOv12升级:金属锈蚀检测系统的设计与实现(完整代码+界面+数据集项目)
人工智能·python·深度学习·目标检测·计算机视觉·yolov12
憨波个43 分钟前
【说话人日志】多说话人数据仿真 Property-Aware Simulation
人工智能·深度学习·音频·语音识别
华清远见IT开放实验室2 小时前
AI 算法核心知识清单(深度实战版2)
人工智能·深度学习·算法·机器学习·ai·模型训练
隔壁大炮2 小时前
09.PyTorch_创建全0_1_指定值张量&&创建线性和随机张量
人工智能·pytorch·深度学习
人机与认知实验室2 小时前
神经网络与态势感知
人工智能·深度学习·神经网络·机器学习
陶陶然Yay4 小时前
神经网络池化层梯度公式推导
人工智能·深度学习·神经网络
萌新小码农‍4 小时前
神经系统与深度学习介绍 学习笔记day1
人工智能·深度学习·神经网络·机器学习·语言模型
适应规律4 小时前
深度学习专有名称发音
人工智能·深度学习
LDG_AGI4 小时前
【搜索引擎】Elasticsearch(六):向量搜索深度解析:从参数原理到混合查询实战
人工智能·深度学习·算法·elasticsearch·机器学习·搜索引擎
AI人工智能+4 小时前
表格识别技术:通过深度学习与计算机视觉融合,实现复杂文档中表格的版面还原及数据的结构化转换。
深度学习·计算机视觉·ocr·表格识别