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)
相关推荐
呆萌很1 小时前
消融实验对比方法
人工智能·深度学习
xx_xxxxx_3 小时前
论文阅读-SAR
人工智能·深度学习·机器学习
量子-Alex7 小时前
【大模型后训练SFT】Finetuning with Sampling: SFT Learns Better Than You Think
人工智能·深度学习·机器学习
ForDreamMusk7 小时前
Transformer Encoder Block
人工智能·深度学习·transformer
打工仔折腾 AI7 小时前
LLaMA 1 到 LLaMA 3 架构演进拆解:从 RoPE、GQA 到词表扩张
人工智能·后端·python·深度学习·langchain·llama
这张生成的图像能检测吗9 小时前
(论文速读)LINN:液体神经网络与脉冲神经元融合的可解释旋转机械故障诊断
人工智能·深度学习·神经网络·故障诊断
东方佑9 小时前
v24 (Hybrid2Fast) 架构与实验报告
人工智能·深度学习·语言模型·自然语言处理·架构
龍德明宇9 小时前
无摩擦的智能与有重力的主体-龍德明宇
人工智能·深度学习·ai哲学·负主体性·ai存在论
成为深度学习高手12 小时前
SEMixer:以随机注意力增强patch语义、渐进混合多尺度的轻量长期时序预测模型
人工智能·深度学习·机器学习·数据挖掘·时间序列
阡陌数智13 小时前
大模型领域自适应微调:小样本场景下过拟合抑制与数据构建方法论
人工智能·深度学习·机器学习