【tensorflow框架神经网络实现MNIST分类_Keras】

文章目录

1、代码

python 复制代码
import tensorflow as tf

# 1、数据导入/构建数据集
mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
# 2、数据预处理/数据归一化
x_train, x_test = x_train / 255.0, x_test / 255.0
# 3、构建模型
model = tf.keras.models.Sequential([
    tf.keras.layers.Flatten(input_shape=(28, 28)),
    tf.keras.layers.Dense(128, activation='relu'),
    tf.keras.layers.Dropout(0.2),
    tf.keras.layers.Dense(10, activation='softmax')
])

model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
# 4-5、模型训练及验证
model.fit(x_train, y_train, batch_size=32, epochs=5, validation_data=(x_test, y_test), validation_freq=1)
model.summary()

2、结果展示

相关推荐
呆萌很7 天前
卷积神经网络的基石——基础卷积模块
神经网络
海天一色y7 天前
粒子群算法(PSO)优化BP神经网络:从原理到实战
人工智能·深度学习·神经网络
小鸡吃米…7 天前
基于 TensorFlow 的图像识别
人工智能·python·tensorflow
小鸡吃米…7 天前
TensorFlow - 构建计算图
人工智能·python·tensorflow
有梦想的攻城狮7 天前
卷积神经网络(CNN)详解
人工智能·神经网络·cnn·卷积神经网络
LaughingZhu7 天前
Product Hunt 每日热榜 | 2026-02-25
数据库·人工智能·经验分享·神经网络·chatgpt
A懿轩A7 天前
【2026 最新】TensorFlow 安装配置详细指南 同时讲解安装CPU和GPU版本 小白也能轻松上手!逐步带图超详细展示(Windows 版)
人工智能·windows·python·深度学习·tensorflow
wearegogog1237 天前
基于神经网络、强化学习、模糊逻辑和小波相结合的混合方法控制欠驱动系统
人工智能·深度学习·神经网络
码农三叔7 天前
(3-2-01)视觉感知:目标检测与分类
人工智能·目标检测·分类·机器人·人机交互·人形机器人
DeepModel7 天前
【分类算法】ID3算法超详细讲解
分类·分类算法