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

相关推荐
Dev7z18 分钟前
基于神经网络的风电机组齿轮箱故障诊断研究与设计
人工智能·深度学习·神经网络
serve the people23 分钟前
tensorflow 零基础吃透:RaggedTensor 的评估(访问值的 4 种核心方式)
人工智能·tensorflow
Good kid.2 小时前
基于XGBoost的中文垃圾分类系统实战(TF-IDF + XGBoost)
人工智能·分类·tf-idf
sali-tec11 小时前
C# 基于halcon的视觉工作流-章67 深度学习-分类
开发语言·图像处理·人工智能·深度学习·算法·计算机视觉·分类
serve the people12 小时前
tensorflow 零基础吃透:RaggedTensor 的索引与切片(规则 + 示例 + 限制)
人工智能·tensorflow·neo4j
文弱_书生13 小时前
关于模型学习策略
人工智能·深度学习·神经网络
serve the people14 小时前
tensorflow 零基础吃透:RaggedTensor 与其他张量类型的转换
人工智能·tensorflow·neo4j
serve the people14 小时前
tensorflow 核心解析:tf.RaggedTensorSpec 作用与参数说明
人工智能·python·tensorflow
聊询QQ:6882388614 小时前
纯电动汽车Simulink仿真模型建模全记录
tensorflow
LaughingZhu16 小时前
Product Hunt 每日热榜 | 2025-12-10
人工智能·经验分享·深度学习·神经网络·产品运营