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

相关推荐
AI街潜水的八角2 小时前
基于Pytorch深度学习神经网络MNIST手写数字识别系统源码(带界面和手写画板)
pytorch·深度学习·神经网络
云和数据.ChenGuang4 小时前
人工智能实践之基于CNN的街区餐饮图片识别案例实践
人工智能·深度学习·神经网络·机器学习·cnn
zhangfeng11336 小时前
spss 性别类似的二分类变量 多分类变量 做线性回归分析
分类·数据挖掘·线性回归
Bony-7 小时前
驾驶员行为检测:基于卷积神经网络(CNN)的识别方法
人工智能·神经网络·cnn
bst@微胖子9 小时前
HuggingFace项目实战之分类任务实战
pytorch·深度学习·分类
:mnong10 小时前
辅助学习神经网络
人工智能·神经网络·学习
摸鱼仙人~12 小时前
BERT分类的上下文限制及解决方案
人工智能·分类·bert
摸鱼仙人~12 小时前
使用 BERT 系列模型实现 RAG Chunk 分类打标
人工智能·分类·bert
2503_9469718612 小时前
【BruteForce/Pruning】2026年度物理层暴力破解与神经网络剪枝基准索引 (Benchmark Index)
人工智能·神经网络·算法·数据集·剪枝·网络架构·系统运维
不惑_13 小时前
通俗理解经典CNN架构:VGGNet
人工智能·神经网络·cnn