目录
前言
🍨 本文为
中的学习记录博客
[🔗365天深度学习训练营]
🍖 原作者:
[K同学啊]
说在前面
1)本周任务:在基于tensorflow的框架下
2)运行环境:Python3.6、Pycharm2020、tensorflow2.4.0
一、前期工作
1.1 导入所需的库并设置GPU
代码如下:
import tensorflow as tf
from tensorflow.keras import datasets, layers, models
import matplotlib.pyplot as plt
#1.1 设置GPU
gpus = tf.config.list_physical_devices("GPU")
if gpus:
gpu0 = gpus[0] # 如果有多个GPU,仅使用第0个GPU
tf.config.experimental.set_memory_growth(gpu0, True) # 设置GPU显存用量按需使用
tf.config.set_visible_devices([gpu0], "GPU")
print(gpus)
打印输出:
[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
1.2 导入数据
1.2.1 数据集介绍
数据集介绍:MNIST手写数字数据集来源于是美国国家标准与技术研究所,是著名的公开数据集之一。数据集中的数字图片是由250个不同职业的人纯手写绘制,数据集获取的网址为:MNIST handwritten digit database, Yann LeCun, Corinna Cortes and Chris Burges(下载后需解压)。我们一般会采用(train_images, train_labels), (test_images, test_labels) = datasets.mnist.load_data()这行代码直接调用,这样就比较简单
MNIST手写数字数据集中包含了70000张图片,其中60000张为训练数据,10000为测试数据,70000张图片均是28*28
,数据集样本如下: