【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、结果展示

相关推荐
LaughingZhu2 天前
Product Hunt 每日热榜 | 2026-09-19
人工智能·深度学习·神经网络·搜索引擎·百度
Ivanqhz2 天前
SVD++算法
java·服务器·网络·深度学习·神经网络
LaughingZhu3 天前
Product Hunt 每日热榜 | 2026-09-20
人工智能·深度学习·神经网络·搜索引擎·百度
zhanghaha13143 天前
HTML系列教程:18_HTML / CSS 颜色零基础详解
css·html·tensorflow
richard_yuu4 天前
LMS 算法:从最小二乘到随机梯度下降,工业自适应滤波的核心
深度学习·神经网络·机器学习
TAN-90°-4 天前
Deep Learning for Computer Vision——Generative Models 2
人工智能·深度学习·神经网络·算法·目标检测·机器学习·计算机视觉
程序猿在线码字4 天前
深度学习(一)
python·深度学习·神经网络·机器学习
tigershang4 天前
从工具到结构:工科数学的升阶之路
神经网络·机器学习·概率论
一只废狗狗狗狗狗狗狗狗狗4 天前
机器学习任务攻略
神经网络·机器学习
Ivanqhz4 天前
BM1688 双核架构
python·深度学习·神经网络·cnn·mlir