Python深度学习入门之mnist-VGG(Tensorflow2.0实现)

该博客介绍了如何利用Tensorflow2.0构建VGG网络来处理MNIST手写数字识别任务。首先加载和预处理MNIST数据集,接着搭建VGG网络模型,包括多个卷积层、池化层、批量归一化和Dropout层。通过Adam优化器进行训练,并绘制训练、验证和测试集的损失及准确率曲线。最后,模型在测试集上进行评估并保存权重文件。
摘要由CSDN通过智能技术生成

mnist手写数字数据集深度学习最常用的数据集,本文以mnist数据集为例,利用Tensorflow2.0框架搭建VGG网络,实现mnist数据集识别任务,并画出各个曲线。

Demo完整代码如下:

import tensorflow as tf
from tensorflow.keras import layers
import numpy as np

#加载mnist数据集
(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()
#预处理
x_train, x_test = x_train.astype(np.float32)/255., x_test.astype(np.float32)/255.
x_train, x_test = np.expand_dims(x_train, axis=3), np.expand_dims(x_test, axis=3)
# 创建训练集50000、验证集10000以及测试集10000
x_val = x_train[-10000:]
y_val = y_train[-10000:]
x_train = x_train[:-10000]
y_train = y_train[:-10000]
#标签转为one-hot格式
y_train = tf.one_hot(y_train, depth=10).numpy()
y_val = tf.one_hot(y_val, depth=10).numpy()
y_test = tf.one_hot(y_test, depth=10).numpy()

# tf.data.Dataset 批处理
train_dataset = tf.data.Dataset.from_tensor_slices((x_train, y_train)).batch(100).repeat()

val_dataset = tf.data.Dataset.from_tensor_slices((x_val, y_val)).batch(100).repeat()

test_dataset = tf.data.Dataset.from_tensor_slices((x_test<
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值