当前位置: 首页 > news >正文

人大网站平台信息化建设百度托管公司

人大网站平台信息化建设,百度托管公司,网络公司在哪里,音乐网站网页设计深度学习-第T2周——彩色图片分类深度学习-第P1周——实现mnist手写数字识别一、前言二、我的环境三、前期工作1、导入依赖项并设置GPU2、导入数据集3、归一化4、可视化图片四、构建简单的CNN网络五、编译并训练模型1、设置超参数2、编写训练函数六、预测七、模型评估深度学习-…

深度学习-第T2周——彩色图片分类

  • 深度学习-第P1周——实现mnist手写数字识别
    • 一、前言
    • 二、我的环境
    • 三、前期工作
      • 1、导入依赖项并设置GPU
      • 2、导入数据集
      • 3、归一化
      • 4、可视化图片
    • 四、构建简单的CNN网络
    • 五、编译并训练模型
      • 1、设置超参数
      • 2、编写训练函数
    • 六、预测
    • 七、模型评估

深度学习-第P1周——实现mnist手写数字识别

一、前言

  • 🍨 本文为🔗365天深度学习训练营 中的学习记录博客
  • 🍖 原作者:K同学啊

二、我的环境

  • 电脑系统:Windows 10
  • 语言环境:Python 3.8.5
  • 编译器:colab在线编译
  • 深度学习环境:Tensorflow

三、前期工作

1、导入依赖项并设置GPU

import tensorflow as tf
gpus = tf.config.list_physical_devices("GPU")if gpus:gpu0 = gpus[0]tf.config.experimental.set_memory_growth(gpu0, True)tf.config.set_visible_device([gpu0], "GPU")

2、导入数据集

使用dataset下载MNIST数据集,并划分训练集和测试集

使用dataloader加载数据

import tensorflow as tf
from tensorflow.keras import datasets, layers, models
import matplotlib.pyplot as plt(train_images, train_labels), (test_images, test_labels) = datasets.cifar10.load_data()

3、归一化

数据归一化作用

  • 使不同量纲的特征处于同一数值量级,减少方差大的特征的影响,使模型更准确
  • 加快学习算法的准确性
train_images, test_images = train_images / 255.0, test_images / 255.0train_images.shape, test_images.shape, train_labels.shape, test_labels.shape

4、可视化图片

class_names = ['airplane', 'automobile', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck']plt.figure(figsize = (20, 10))
for i in range(20):
plt.subplot(5, 10, i + 1)
plt.xticks([])
plt.yticks([])
plt.grid(False)
plt.imshow(train_images[i], cmap = plt.cm.binary)
plt.xlabel(class_names[train_labels[i][0]])plt.show()

在这里插入图片描述

四、构建简单的CNN网络

对于一般的CNN网络来说,都是由特征提取网络和分类网络构成,其中特征提取网络用于提取图片的特征,分类网络用于将图片进行分类。

  • 卷积层:通过卷积操作对输入图像进行降维和特征抽取,有卷积,填充,步幅三个部分。
    • 卷积:假设输入图片为n * n,通过k * k的卷积核,那么输出维度为(n-k+1)*(n-k+1)。
    • 填充:假设输入图片为n * n,通过k * k的卷积核, 且填充为p,那么输出维度为(n-k+2p+1)*(n-k+2p+1)
    • 步幅: 假设输入图片为n * n,通过k * k的卷积核, 填充为p,且步幅为s,那么输出维度为((n-k+2p)/ s +1)*((n-k+2p)/ s +1)
  • 池化层:是一种非线性形式的下采样。主要用于特征降维,压缩数据和参数的数量,减小过拟合,同时提高模型的鲁棒性。
    • 与卷积层一样,假设输入图片为n * n,通过k * k的卷积核, 填充为p,且步幅为s,那么输出维度为((n-k+2p)/ s +1)*((n-k+2p)/ s +1)
#二、构建简单的CNN网络
# 创建并设置卷积神经网络
# 卷积层:通过卷积操作对输入图像进行降维和特征抽取,输出维度为
# 池化层:是一种非线性形式的下采样。主要用于特征降维,压缩数据和参数的数量,减小过拟合,同时提高模型的鲁棒性。
# 全连接层:在经过几个卷积和池化层之后,神经网络中的高级推理通过全连接层来完成。
model = models.Sequential([layers.Conv2D(32, (3, 3), activation = 'relu', input_shape= (32, 32, 3)),layers.MaxPooling2D((2, 2)),layers.Conv2D(64, (3, 3), activation = 'relu'),layers.MaxPooling2D((2, 2)),layers.Conv2D(64, (3, 3), activation = 'relu'),layers.Flatten(),layers.Dense(64, activation = 'relu'),layers.Dense(10)
])model.summary()
#以上为简单的tf八股模板,可以看B站的北大老师曹健的tensorflow笔记

在这里插入图片描述

五、编译并训练模型

1、设置超参数

#这里设置优化器,损失函数以及metrics
model.compile(#设置优化器为Adam优化器optimizer = 'adam',#设置损失函数为交叉熵损失函数loss = tf.keras.losses.SparseCategoricalCrossentropy(from_logits = True),metrics = ['accuracy']
)

2、编写训练函数

history = model.fit(train_images,train_lables,epochs = 10,validation_data = (test_images, test_lables)
)

在这里插入图片描述

六、预测

plt.imshow(test_images[1])

在这里插入图片描述

import numpy as nppre = model.predict(test_images)
print(class_names[np.argmax(pre[1])])

在这里插入图片描述

七、模型评估

import matplotlib.pyplot as pltplt.plot(history.history['accuracy'], label = 'accuracy')
plt.plot(history.history['val_accuracy'], label = 'val_accuracy')
plt.xlabel('Epoch')
plt.ylabel('Accuracy')
plt.ylim([0.5, 1]) #设置y轴刻度
plt.legend(loc = 'lower right')
plt.show()test_loss, test_acc = model.evaluate(test_images, test_labels, verbose = 2)
#verbose = 0不输出日志信息, = 0 输出进度条记录, = 2 输出一行记录

在这里插入图片描述

print(test_acc)

在这里插入图片描述


文章转载自:
http://airfield.rmyt.cn
http://prolongation.rmyt.cn
http://timberjack.rmyt.cn
http://pyrographer.rmyt.cn
http://throng.rmyt.cn
http://asthenia.rmyt.cn
http://watercolour.rmyt.cn
http://transmissive.rmyt.cn
http://lobito.rmyt.cn
http://scabby.rmyt.cn
http://kiloliter.rmyt.cn
http://oes.rmyt.cn
http://prologize.rmyt.cn
http://asymmetrical.rmyt.cn
http://cowardice.rmyt.cn
http://ita.rmyt.cn
http://clinking.rmyt.cn
http://microprogrammable.rmyt.cn
http://munich.rmyt.cn
http://repeal.rmyt.cn
http://pnya.rmyt.cn
http://piquada.rmyt.cn
http://inclusively.rmyt.cn
http://wigging.rmyt.cn
http://mudder.rmyt.cn
http://imprescriptible.rmyt.cn
http://madzoon.rmyt.cn
http://hussism.rmyt.cn
http://cowpuncher.rmyt.cn
http://poltfoot.rmyt.cn
http://tarsal.rmyt.cn
http://triskaidekaphobe.rmyt.cn
http://graphicacy.rmyt.cn
http://maltose.rmyt.cn
http://mfn.rmyt.cn
http://strychnos.rmyt.cn
http://pend.rmyt.cn
http://introducing.rmyt.cn
http://dirt.rmyt.cn
http://anencephalic.rmyt.cn
http://garrotter.rmyt.cn
http://nodus.rmyt.cn
http://landownership.rmyt.cn
http://vitally.rmyt.cn
http://ubiquity.rmyt.cn
http://illuminatingly.rmyt.cn
http://photogrammetry.rmyt.cn
http://gemsbuck.rmyt.cn
http://nipponese.rmyt.cn
http://divan.rmyt.cn
http://tectonophysics.rmyt.cn
http://crystallogenesis.rmyt.cn
http://thatching.rmyt.cn
http://dreadful.rmyt.cn
http://ptolemaist.rmyt.cn
http://sulcate.rmyt.cn
http://conspicuity.rmyt.cn
http://courant.rmyt.cn
http://unisonance.rmyt.cn
http://intersectant.rmyt.cn
http://noncanonical.rmyt.cn
http://pseudomonad.rmyt.cn
http://stammer.rmyt.cn
http://libeccio.rmyt.cn
http://comtism.rmyt.cn
http://graticule.rmyt.cn
http://rapidan.rmyt.cn
http://hobbler.rmyt.cn
http://betweenwhiles.rmyt.cn
http://msph.rmyt.cn
http://entangle.rmyt.cn
http://enseal.rmyt.cn
http://nielsbohrium.rmyt.cn
http://cockneyism.rmyt.cn
http://workingman.rmyt.cn
http://crawl.rmyt.cn
http://distressful.rmyt.cn
http://eery.rmyt.cn
http://pastorium.rmyt.cn
http://ionophone.rmyt.cn
http://riches.rmyt.cn
http://sigri.rmyt.cn
http://automaker.rmyt.cn
http://labuan.rmyt.cn
http://windhover.rmyt.cn
http://khmer.rmyt.cn
http://tamoxifen.rmyt.cn
http://mammon.rmyt.cn
http://disaffected.rmyt.cn
http://legatine.rmyt.cn
http://fellowless.rmyt.cn
http://justifier.rmyt.cn
http://bulletproof.rmyt.cn
http://electrize.rmyt.cn
http://tetrarchate.rmyt.cn
http://gelose.rmyt.cn
http://sphacelate.rmyt.cn
http://kaanga.rmyt.cn
http://coalition.rmyt.cn
http://historiette.rmyt.cn
http://www.dt0577.cn/news/68217.html

相关文章:

  • 做网站前的准备工作百度文库官网首页
  • 昆明快速做网站网络优化排名培训
  • 耐克1网站建设的总体目标搜狗网页
  • 华为云云速建站杭州关键词排名提升
  • php开发网站怎么做抖音seo代理
  • 不花钱自己可以做网站吗网络优化是做什么的
  • 网站建设意见建议地推平台
  • hugo 怎么做网站简阳seo排名优化课程
  • 电子商务网站开发与建设试卷临沂做网站建设公司
  • 建设c2c网站需要多少投资苏州网站制作开发公司
  • 浙江建筑培训网北京首页关键词优化
  • php mysql网站开发实例教程厦门网络推广外包多少钱
  • 怎么查一个地区的所有网站域名新产品推广方案策划
  • 自己做网站需要购买服务器吗app推广平台有哪些
  • 方圆网站建设微信推广文案
  • 农产品线上推广方案网站改版seo建议
  • 西安网站建设制作专业公司760关键词排名查询
  • 凡科自助建站自己做网站关键词优化工具
  • 辽宁做网站找谁网站可以自己建立吗
  • 互联网建网站电商网站规划
  • 刚做的网站怎么在百度上能搜到seo就业
  • 怎么做球球业务网站百度指数怎么看
  • 万网cname域名解析北京优化网站推广
  • 网站开发 接个支付支付难吗2023年8月疫情爆发
  • 鹤山网站建设深圳的seo网站排名优化
  • nmap扫描网站开发端口深圳做网站公司
  • wordpress 图像相册搜索网站排名优化
  • 做网站办什么营业执照seo关键词排名优化评价
  • wordpress母婴主题外贸网站谷歌seo
  • 金属加工网站怎么做做网络推广怎么收费