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)
相关推荐
悠闲蜗牛�36 分钟前
技术融合新纪元:深度学习、大数据与云原生的跨界实践
大数据·深度学习·云原生
嵌入式-老费4 小时前
自己动手写深度学习框架(感知机)
人工智能·深度学习
化作星辰5 小时前
使用 PyTorch来构建线性回归的实现
人工智能·pytorch·深度学习
谢景行^顾5 小时前
深度学习-损失函数
人工智能·深度学习
极客BIM工作室5 小时前
单层前馈神经网络的万能逼近定理
人工智能·深度学习·神经网络
无水先生6 小时前
数据集预处理:规范化和标准化
人工智能·深度学习
B站_计算机毕业设计之家7 小时前
大数据YOLOv8无人机目标检测跟踪识别系统 深度学习 PySide界面设计 大数据 ✅
大数据·python·深度学习·信息可视化·数据挖掘·数据分析·flask
武子康15 小时前
AI研究-119 DeepSeek-OCR PyTorch FlashAttn 2.7.3 推理与部署 模型规模与资源详细分析
人工智能·深度学习·机器学习·ai·ocr·deepseek·deepseek-ocr
忙碌54416 小时前
AI大模型时代下的全栈技术架构:从深度学习到云原生部署实战
人工智能·深度学习·架构
听风吹等浪起18 小时前
基于改进TransUNet的港口船只图像分割系统研究
人工智能·深度学习·cnn·transformer