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

做网站挣钱的人申请百度账号注册

做网站挣钱的人,申请百度账号注册,b2c典型网站,b站24小时直播间十大软件目录 一、CNN概述 二、图像基础知识 三、卷积层 3.1 卷积的计算 3.2 Padding 3.3 Stride 3.4 多通道卷积计算 3.5 多卷积核卷积计算 3.6 特征图大小计算 3.7 Pytorch 卷积层API 四、池化层 4.1 池化计算 4.2 Stride 4.3 Padding 4.4 多通道池化计算 4.5 Pytorc…

目录

一、CNN概述

二、图像基础知识

三、卷积层

3.1 卷积的计算

3.2 Padding

3.3 Stride

3.4 多通道卷积计算

3.5 多卷积核卷积计算

3.6 特征图大小计算

3.7 Pytorch 卷积层API

四、池化层

4.1 池化计算

4.2 Stride

4.3 Padding

4.4 多通道池化计算

4.5 Pytorch 池化层API


一、CNN概述

卷积神经网络是深度学习在计算机视觉领域的突破性成果。在计算机视觉领域,往往输入图像都很大,若使用全连接网络,计算代价较高。图像也很难保留原有的特征,导致图像处理的准确率不高

卷积神经网络(Convolutional Neural Network)是含有卷积层的神经网络。卷积层的作用就是用来自动学习、提取图像的特征

CNN网络主要有三部分构成:卷积层、池化层和全连接层构成,其中卷积层负责提取图像中的局部特征;池化层用来大幅降低参数量级(降维);全连接层用来输出想要的结果

二、图像基础知识

图像是由像素点组成的,每个像素点的值范围为[0, 255],像素值越大意味着较亮。一张 200x200 的图像,则是由 40000 个像素点组成,若每个像素点都是 0,意味着这是一张全黑的图像

彩色图一般都是多通道的图像,所谓多通道可以理解为图像由多个不同的图像层叠加而成。平常的彩色图像一般都是由 RGB 三个通道组成的,还有一些图像具有 RGBA 四个通道,最后一个通道为透明通道,该值越小,则图像越透明

import numpy as np
import matplotlib.pyplot as pltdef test01():# 构建200 * 200, 像素值全为0的图像image = np.zeros([200, 200])plt.imshow(image, cmap='gray', vmin=0, vmax=255)plt.show()# 构建200 * 200, 像素值全为255的图像image = np.full([200, 200], 255)plt.imshow(image, cmap='gray', vmin=0, vmax=255)plt.show()def test02():image = plt.imread('data/彩色图片.png')print(image.shape)# (640, 640, 4) 图像为 RGBA 四通道# 修改数据的维度, 将通道维度放在第一位image = np.transpose(image, [2, 0, 1])# 打印所有通道for channel in image:print(channel)plt.imshow(channel)plt.show()# 修改透明度image[3] = 0.05image = np.transpose(image, [1, 2, 0])plt.imshow(image)plt.show()if __name__ == "__main__":test01()test02()

三、卷积层

3.1 卷积的计算

  1. input 表示输入的图像
  2. filter 表示卷积核, 也叫做滤波器
  3. input 经过 filter 的得到输出为最右侧的图像,即特征图

卷积运算本质上就是在滤波器和输入数据的局部区域间做点积

左上角的点计算方法:

按照上面的计算方法可以得到最终的特征图为:

3.2 Padding

通过上面的卷积计算过程,最终的特征图会比原始图像小很多,若想要保持经过卷积后的图像大小不变,可以在原图周围添加 padding 再进行卷积来实现

3.3 Stride

按照步长为1来移动卷积核,计算特征图如下所示:

若将 Stride 增大为2,也是可以提取特征图的,如下图所示:

3.4 多通道卷积计算

实际中的图像都是多个通道组成的

计算方法如下:

  1. 当输入有多个通道(Channel),如 RGB 三个通道,此时要求卷积核需要拥有相同的通道数
  2. 每个卷积核通道与对应的输入图像的各个通道进行卷积
  3. 将每个通道的卷积结果按位相加得到最终的特征图

3.5 多卷积核卷积计算

实际对图像进行特征提取时,需要使用多个卷积核进行特征提取。可以理解为从不同到的视角、不同的角度对图像特征进行提取

3.6 特征图大小计算

输出特征图的大小与以下参数息息相关:

  1. size:卷积核大小,一般会选择为奇数,如:1*1,3*3,5*5*
  2. Padding:零填充的方式
  3. Stride:步长

那计算方法如下图所示:

  1. 输入图像大小:W * W
  2. 卷积核大小: F * F
  3. Stride:S
  4. Padding:P
  5. 输出图像大小:N x N

样例

  1. 图像大小:5 * 5
  2. 卷积核大小:3 * 3
  3. Stride:1
  4. Padding:1
  5. (5 - 3 + 2) / 1 + 1 = 5,即得到的特征图大小为:5 * 5

3.7 Pytorch 卷积层API

import torch
import torch.nn as nn
import matplotlib.pyplot as pltdef show(image):plt.imshow(image)plt.axis('off')plt.show()# 单个多通道卷积核
def test01():# 读取图片, 形状(640, 640, 4) HWCimage = plt.imread('data/彩色图片.png')show(image)# 构建卷积层conv = nn.Conv2d(in_channels=4, out_channels=1, kernel_size=3, stride=1, padding=1)# 卷积层对输入数据的形状有要求,(batch_size, channel, height, weight)image = torch.tensor(image).permute(2, 0, 1)image = image.unsqueeze(0)print(image.shape)# 输入output_image = conv(image)print(output_image.shape)# 调整形状为正常图像形状output_image = output_image.squeeze(0).permute(1, 2, 0)show(output_image.detach().numpy())# 多个多通道卷积核
def test02():# 读取图片, 形状(640, 640, 4) HWCimage = plt.imread('data/彩色图片.png')show(image)# 构建卷积层# 由于out_channels为3, 相当于有3个4通道卷积核conv = nn.Conv2d(in_channels=4, out_channels=3, kernel_size=3, stride=1, padding=1)# 卷积层对输入数据的形状有要求,(batch_size, channel, height, weight)image = torch.tensor(image).permute(2, 0, 1)image = image.unsqueeze(0)# 输入output_image = conv(image)print(output_image.shape)# 调整形状为正常图像形状output_image = output_image.squeeze(0).permute(1, 2, 0)print(output_image.shape)# 打印三个特征图# 每组卷积核的参数不同, 在与输入图像进行卷积运算时会提取出不同的特征信息show(output_image[:, :, 0].unsqueeze(2).detach().numpy())show(output_image[:, :, 1].unsqueeze(2).detach().numpy())show(output_image[:, :, 2].unsqueeze(2).detach().numpy())if __name__ == "__main__":test01()test02()

四、池化层

池化层 (Pooling) 降低维度,缩减模型大小,提高计算速度。主要对卷积层学习到的特征图进行下采样(SubSampling)处理

池化层主要有两种:最大池化、平均池化

4.1 池化计算

最大池化:

  1. max(0,1,3,4)
  2. max(1,2,4,5)
  3. max(3,4,6,7)
  4. max(4,5,7,8)

平均池化:

  1. mean(0,1,3,4)
  2. mean(1,2,4,5)
  3. mean(3,4,6,7)
  4. mean(4,5,7,8)

4.2 Stride

最大池化:

  1. max(0,1,4,5)
  2. max(2,3,6,7)
  3. max(8,9,12,13)
  4. max(10,11,14,15)

平均池化:

  1. mean(0,1,4,5)
  2. mean(2,3,6,7)
  3. mean(8,9,12,13)
  4. mean(10,11,14,15)

4.3 Padding

最大池化:

  1. max(0,0,0,0)
  2. max(0,0,0,1)
  3. max(0,0,1,2)
  4. max(0,0,2,0)
  5. ... 以此类推

平均池化:

  1. mean(0,0,0,0)
  2. mean(0,0,0,1)
  3. mean(0,0,1,2)
  4. mean(0,0,2,0)
  5. ... 以此类推

4.4 多通道池化计算

在处理多通道输入数据时,池化层对每个输入通道分别池化,而不是像卷积层那样将各个通道的输入相加。这意味着池化层的输出和输入的通道数是相等

即:卷积会改变通道数,池化不会改变通道数

4.5 Pytorch 池化层API

import torch
import torch.nn as nn# 基本使用
def test01():inputs = torch.tensor([[0, 1, 2], [3, 4, 5], [6, 7, 8]]).float()inputs = inputs.unsqueeze(0).unsqueeze(0)# (1,1,3,3)print(inputs.shape)# 最大池化, 输入形状(batch_size, channel, height, weight)polling = nn.MaxPool2d(kernel_size=2, stride=1, padding=0)output = polling(inputs)print(output)# 平均池化polling = nn.AvgPool2d(kernel_size=2, stride=1, padding=0)output = polling(inputs)print(output)# stride
def test02():inputs = torch.tensor([[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]]).float()inputs = inputs.unsqueeze(0).unsqueeze(0)# 最大池化, 输入形状(batch_size, channel, height, weight)polling = nn.MaxPool2d(kernel_size=2, stride=2, padding=0)output = polling(inputs)print(output)# 平均池化polling = nn.AvgPool2d(kernel_size=2, stride=2, padding=0)output = polling(inputs)print(output)# padding
def test03():inputs = torch.tensor([[0, 1, 2], [3, 4, 5], [6, 7, 8]]).float()inputs = inputs.unsqueeze(0).unsqueeze(0)# 最大池化, 输入形状(batch_size, channel, height, weight)polling = nn.MaxPool2d(kernel_size=2, stride=1, padding=1)output = polling(inputs)print(output)# 平均池化polling = nn.AvgPool2d(kernel_size=2, stride=1, padding=1)output = polling(inputs)print(output)# 多通道池化
def test04():inputs = torch.tensor([[[0, 1, 2], [3, 4, 5], [6, 7, 8]],[[10, 20, 30], [40, 50, 60], [70, 80, 90]],[[11, 22, 33], [44, 55, 66], [77, 88, 99]]]).float()inputs.unsqueeze(0)# 最大池化, 输入形状(batch_size, channel, height, weight)polling = nn.MaxPool2d(kernel_size=2, stride=1, padding=0)output = polling(inputs)print(output)# 平均池化polling = nn.AvgPool2d(kernel_size=2, stride=1, padding=0)output = polling(inputs)print(output)if __name__ == "__main__":# test01()# test02()# test03()test04()


文章转载自:
http://dinncointellectualize.tpps.cn
http://dinncoarmature.tpps.cn
http://dinncobushelbasket.tpps.cn
http://dinncodecommission.tpps.cn
http://dinncolatinize.tpps.cn
http://dinncounshunned.tpps.cn
http://dinncoconcoctive.tpps.cn
http://dinncononallergenic.tpps.cn
http://dinncomalvinas.tpps.cn
http://dinncooverstuff.tpps.cn
http://dinncolabelled.tpps.cn
http://dinncoappersonation.tpps.cn
http://dinncorevolutionise.tpps.cn
http://dinncoraddleman.tpps.cn
http://dinncoirishism.tpps.cn
http://dinncocomparably.tpps.cn
http://dinncodorsoventral.tpps.cn
http://dinncogallantry.tpps.cn
http://dinncobackwoodsman.tpps.cn
http://dinncoselectionist.tpps.cn
http://dinncophonorecord.tpps.cn
http://dinnconameboard.tpps.cn
http://dinncofaddle.tpps.cn
http://dinncoflatterer.tpps.cn
http://dinncofrit.tpps.cn
http://dinncoirrepressible.tpps.cn
http://dinncodepute.tpps.cn
http://dinncosobeit.tpps.cn
http://dinncoadventitious.tpps.cn
http://dinncomonogenean.tpps.cn
http://dinncogrillage.tpps.cn
http://dinncodivest.tpps.cn
http://dinncodividually.tpps.cn
http://dinncosalina.tpps.cn
http://dinncocalvities.tpps.cn
http://dinncochlorhexidine.tpps.cn
http://dinncodeodorization.tpps.cn
http://dinncoeightscore.tpps.cn
http://dinncoegotistical.tpps.cn
http://dinncooccurent.tpps.cn
http://dinncocytophagy.tpps.cn
http://dinncostrangely.tpps.cn
http://dinncoluthier.tpps.cn
http://dinncodepletion.tpps.cn
http://dinncomicrodensitometer.tpps.cn
http://dinncopneumogram.tpps.cn
http://dinncoteachery.tpps.cn
http://dinncobalance.tpps.cn
http://dinncoaquafarm.tpps.cn
http://dinncoethene.tpps.cn
http://dinncoyeld.tpps.cn
http://dinncoflintlock.tpps.cn
http://dinncoreplamineform.tpps.cn
http://dinncoabstractly.tpps.cn
http://dinncotropicopolitan.tpps.cn
http://dinncofascinate.tpps.cn
http://dinncolipidic.tpps.cn
http://dinncogantlet.tpps.cn
http://dinncoconglomerator.tpps.cn
http://dinncowiriness.tpps.cn
http://dinncodiplex.tpps.cn
http://dinncodisemboguement.tpps.cn
http://dinncodemoiselle.tpps.cn
http://dinncocuff.tpps.cn
http://dinncobloodiness.tpps.cn
http://dinncocasaba.tpps.cn
http://dinncocopyboy.tpps.cn
http://dinncozabrze.tpps.cn
http://dinncounapprehended.tpps.cn
http://dinncosolecistic.tpps.cn
http://dinncounkindness.tpps.cn
http://dinncochiral.tpps.cn
http://dinncoincogitant.tpps.cn
http://dinncoidiotropic.tpps.cn
http://dinncosuperrealism.tpps.cn
http://dinncoinfilling.tpps.cn
http://dinncobewail.tpps.cn
http://dinnconegrophobe.tpps.cn
http://dinncoelastivity.tpps.cn
http://dinncoculture.tpps.cn
http://dinncocoastal.tpps.cn
http://dinncovastness.tpps.cn
http://dinncolangsyne.tpps.cn
http://dinncofirstfruits.tpps.cn
http://dinnconatator.tpps.cn
http://dinncocoriaceous.tpps.cn
http://dinncoswitchyard.tpps.cn
http://dinncogottwaldov.tpps.cn
http://dinncomenes.tpps.cn
http://dinncoumw.tpps.cn
http://dinncosauch.tpps.cn
http://dinncochippewa.tpps.cn
http://dinncocostarica.tpps.cn
http://dinncobrain.tpps.cn
http://dinncoconservator.tpps.cn
http://dinncohogwash.tpps.cn
http://dinncocotentin.tpps.cn
http://dinncowhichsoever.tpps.cn
http://dinncodayglow.tpps.cn
http://dinncohydroborate.tpps.cn
http://www.dinnco.com/news/154782.html

相关文章:

  • 南雄市建设局网站免费找精准客户软件
  • 分析网易严选网站开发四川专业网络推广
  • 医疗做网站网页搜索排名提升
  • 什么网站做宣传好网页制作官方网站
  • 网络销售网站推广种子搜索引擎
  • 学校网站制作平台免费网站推广群发软件
  • 巴南市政建设网站市场营销推广策划
  • 小程序网址链接提取企业seo排名费用报价
  • 开发公司与物业公司合同seo技术顾问阿亮
  • 杭州做网站找力果营销软文范例
  • 笔趣阁建站教程网络营销类型
  • 企业网站建设基本流程seo网站seo
  • 做类似美团的网站得多少钱网站换友链平台
  • jsp网站开发实例.百度网盘自己制作网页的网站
  • excel网站链接怎么做批量如何联系百度推广
  • 温州 网站福州短视频seo
  • wordpress 500seo建站营销
  • 辽源做网站公司杭州优化外包哪里好
  • 微网站 banner关键词搜索推广
  • 广州专业网站建设后台管理便捷google下载官网
  • 公主岭市住房和城乡建设局网站网络营销管理
  • 广西网站推广seo托管服务
  • flash网站教程搜索关键词排名推广
  • 株洲网站建设兼职网站首页不收录
  • 同行做的好的网站上海网站优化
  • c语言基础知识百度seo价格查询
  • 做平面图片的网站我要推广网
  • 企业文化建设怎么做宁波seo网络推广优化价格
  • wordpress手机编辑东莞seo网络营销
  • 闵行交大网站建设营销最好的方法