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

天津市建设与管理网站上海哪家seo好

天津市建设与管理网站,上海哪家seo好,做微商截图的网站,wordpress新用户无法注册第六章.卷积神经网络(CNN) 6.1 卷积层(Convolution)&池化层(Pooling) 1.整体结构 以5层神经网络的实现为例: 1).基于全连接层(Affine)的网络 全连接层:相邻层的所有神经元之间都有连接 2).常见的CNN的网络 3).全连接层存在的问题 数据的形状容易被…

第六章.卷积神经网络(CNN)

6.1 卷积层(Convolution)&池化层(Pooling)

1.整体结构

以5层神经网络的实现为例:

1).基于全连接层(Affine)的网络

全连接层:相邻层的所有神经元之间都有连接
在这里插入图片描述

2).常见的CNN的网络

在这里插入图片描述

3).全连接层存在的问题

数据的形状容易被“忽视”了,比如输入的数据是图像时,图像通常是高,长,通道方向上的3维形状,但是,全连接层输入时,需要将3维数据拉平为1维数据,所以无法利用与形状相关的信息。

2.卷积层

卷积层可以保持形状不变,当输入数据是图像时,卷积层会以3维数据的形式接受输入数据,并同样以3维数据的形式输出至下一层,因此在CNN中可以正确理解图像等具有形状的数据。

1).卷积运算

  • 一维数据的卷积计算

    示例:填充为0,步幅为1的卷积运算在这里插入图片描述

  • 三维数据的卷积计算

    示例:填充为0,步幅为1的卷积运算
    在这里插入图片描述
    计算方式
    通道方向有多特征图时,会按通道进行输入数据和滤波器的卷积运算,并结果相加,从而得到输出。

    注意
    ①.在三维数据的卷积运算中,输入数据和滤波器的通道数必须设置为相同的值。(在本例中同时设置为3)

  • 结合方块来思考卷积计算
    在这里插入图片描述
    图像描述:
    每个通道只有一个偏置,这里偏置的形状为(FN,1,1),滤波器的输出结果形状为(FN,OH,OW),这两个方块相加,要对滤波器的输出结果按通道加上相同的偏置。

  • 卷积计算的批处理
    在这里插入图片描述
    注意
    ①.网络间传递的是四维数据,对这N个数据进行了卷积运算,也就是说,批处理将N次的处理汇总成1次进行。

2).填充&步幅

  • 填充

    ①.定义
    在进行卷积层处理之前,有时需要向输入数据的周围填入固定的数据(比如填充值0等),这称为填充。
    在这里插入图片描述

    ②.目的
    主要是为了调整输出的大小,因为每次在进行卷积运算时都会缩小空间,那么在某个时刻输出大小就有可能变为1,导致无法在进行卷积运算,为了避免出现这种情况,就要使用填充

  • 步幅

    ①.定义
    应用滤波器的位置间隔称为步幅。(之前的应用都是步幅为1,下面的应用步幅为2)
    在这里插入图片描述

3).计算输出核的大小

假设输入大小为(H,W),滤波大小为(FH,FW),输出大小为(OH,OW),填充为P,步幅为S,输出大小为:
在这里插入图片描述
注意
①.所设定的值必须使式(H+2P-FH)/S(W+2P-FW)/S分别可以整除,当输入大小无法整除时,需要采取报错等对策。有的深度学习框架,当值无法除尽时,有时会向最接近的整数四舍五入,不进行报错而继续进行。

4).实现扩展

①.CNN处理4维数据时,卷积运算的实现看上去会很复杂,可以使用im2col(图像转化成矩阵)这个技巧,问题会变得很简单。

②.im2col函数会将输入数据展开以适合滤波器(权重)。具体来说,对于输入数据,将应用滤波器的区域(3维方块)横向展开为一列。

在这里插入图片描述
③.卷积运算的滤波器处理细节:使用im2col函数展开输入数据后,将卷积层的滤波器纵向展开为一列,计算两个矩阵的乘积,最后转化(reshape)为输出数据大小。
在这里插入图片描述

5).卷积层的实现

import numpy as np# 从图像到矩阵
def im2col(input_data, filter_h, filter_w, stride=1, pad=0):N, C, H, W = input_data.shapeout_h = (H + 2 * pad - filter_h) // stride + 1out_w = (W + 2 * pad - filter_w) // stride + 1img = np.pad(input_data, [(0, 0), (0, 0), (pad, pad), (pad, pad)], 'constant')col = np.zeros((N, C, filter_h, filter_w, out_h, out_w))for y in range(filter_h):y_max = y + stride * out_hfor x in range(filter_w):x_max = x + stride * out_wcol[:, :, y, x, :, :] = img[:, :, y:y_max:stride, x:x_max:stride]col = col.transpose(0, 4, 5, 1, 2, 3).reshape(N * out_h * out_w, -1)return col# 从矩阵到图像
def col2im(col, input_shape, filter_h, filter_w, stride=1, pad=0):N, C, H, W = input_shapeout_h = (H + 2 * pad - filter_h) // stride + 1out_w = (W + 2 * pad - filter_w) // stride + 1col = col.reshape(N, out_h, out_w, C, filter_h, filter_w).transpose(0, 3, 4, 5, 1, 2)img = np.zeros((N, C, H + 2 * pad + stride - 1, W + 2 * pad + stride - 1))for y in range(filter_h):y_max = y + stride * out_hfor x in range(filter_w):x_max = x + stride * out_wimg[:, :, y:y_max:stride, x:x_max:stride] += col[:, :, y, x, :, :]return img[:, :, pad:H + pad, pad:W + pad]class Convolution:def __init__(self, W, b, stride=1, pad=0):self.W = Wself.b = bself.stride = strideself.pad = pad# 中间数据(backward时使用)self.x = Noneself.col = Noneself.col_W = None# 权重和偏置参数的梯度self.dW = Noneself.db = None# 正向传播def forward(self, x):FN, C, FH, FW = self.W.shapeN, C, H, W = x.shapeout_h = int((H + 2 * self.pad - FH) / self.stride) + 1out_w = int((W + 2 * self.pad - FW) / self.stride) + 1col = im2col(x, FH, FW, self.stride, self.pad)col_W = self.W.reshape(FN, -1).Tout = np.dot(col, col_W) + self.bout = out.reshape(N, out_h, out_w, -1).transpose(0, 3, 1, 2)self.x = xself.col = colself.col_W = col_Wreturn out# 反向传播def backward(self, dout):FN, C, FH, FW = self.W.shapedout = dout.transpose(0, 2, 3, 1).reshape(-1, FN)self.db = np.sum(dout, axis=0)self.dW = np.dot(self.col.T, dout)self.dW = self.dW.transpose(1, 0).reshape(FN, C, FH, FW)dcol = np.dot(dout, self.col_W.T)dx = col2im(dcol, self.x.shape, FH, FW, self.stride, self.pad)return dx

3.池化层

池化是缩小高,长方向上的空间运算。

1).池化的处理方法

示例:填充为0,步幅为2的池化

  • Max池化(本书中所说的池化层是Max池化)
    方式:从目标区域中取最大值
    在这里插入图片描述

  • Average池化
    方式:从目标区域中取均值在这里插入图片描述

2).池化层的特征

  • 没有要学习的参数
    池化层和卷积层不同,没有要学习的参数。池化只是从目标区域中选出最大值(或均值)。

  • 通道数不发生改变
    经过池化运算,输入数据和输出数据的通道数不发生变化,计算是按通道独立进行的。
    在这里插入图片描述

  • 对微小的位置变化具有鲁棒性(健壮)
    输入数据发生微小偏差时,池化仍会返回相同的结果。

    示例:输入数据在高方向上只偏离一个像素时:
    在这里插入图片描述

3).池化层的实现步骤

①.展开输入数据
②.求各行的最大值
③.转换为合适的输出大小

在这里插入图片描述

4).池化层的实现

import numpy as np# 从图像到矩阵
def im2col(input_data, filter_h, filter_w, stride=1, pad=0):N, C, H, W = input_data.shapeout_h = (H + 2 * pad - filter_h) // stride + 1out_w = (W + 2 * pad - filter_w) // stride + 1img = np.pad(input_data, [(0, 0), (0, 0), (pad, pad), (pad, pad)], 'constant')col = np.zeros((N, C, filter_h, filter_w, out_h, out_w))for y in range(filter_h):y_max = y + stride * out_hfor x in range(filter_w):x_max = x + stride * out_wcol[:, :, y, x, :, :] = img[:, :, y:y_max:stride, x:x_max:stride]col = col.transpose(0, 4, 5, 1, 2, 3).reshape(N * out_h * out_w, -1)return col# 从矩阵到图像
def col2im(col, input_shape, filter_h, filter_w, stride=1, pad=0):N, C, H, W = input_shapeout_h = (H + 2 * pad - filter_h) // stride + 1out_w = (W + 2 * pad - filter_w) // stride + 1col = col.reshape(N, out_h, out_w, C, filter_h, filter_w).transpose(0, 3, 4, 5, 1, 2)img = np.zeros((N, C, H + 2 * pad + stride - 1, W + 2 * pad + stride - 1))for y in range(filter_h):y_max = y + stride * out_hfor x in range(filter_w):x_max = x + stride * out_wimg[:, :, y:y_max:stride, x:x_max:stride] += col[:, :, y, x, :, :]return img[:, :, pad:H + pad, pad:W + pad]class Pooling:def __init__(self, pool_h, pool_w, stride=1, pad=0):self.pool_h = pool_hself.pool_w = pool_wself.stride = strideself.pad = padself.x = Noneself.arg_max = None# 正向传播def forward(self, x):N, C, H, W = x.shapeout_h = int(1 + (H - self.pool_h) / self.stride)out_w = int(1 + (W - self.pool_w) / self.stride)col = im2col(x, self.pool_h, self.pool_w, self.stride, self.pad)col = col.reshape(-1, self.pool_h * self.pool_w)arg_max = np.argmax(col, axis=1)out = np.max(col, axis=1)out = out.reshape(N, out_h, out_w, C).transpose(0, 3, 1, 2)self.x = xself.arg_max = arg_maxreturn out# 反向传播def backward(self, dout):dout = dout.transpose(0, 2, 3, 1)pool_size = self.pool_h * self.pool_wdmax = np.zeros((dout.size, pool_size))dmax[np.arange(self.arg_max.size), self.arg_max.flatten()] = dout.flatten()dmax = dmax.reshape(dout.shape + (pool_size,))dcol = dmax.reshape(dmax.shape[0] * dmax.shape[1] * dmax.shape[2], -1)dx = col2im(dcol, self.x.shape, self.pool_h, self.pool_w, self.stride, self.pad)return dx

文章转载自:
http://dinncoclairaudient.wbqt.cn
http://dinncoafocal.wbqt.cn
http://dinncovolcanoclastic.wbqt.cn
http://dinncounderstandingly.wbqt.cn
http://dinncoespiegle.wbqt.cn
http://dinncomit.wbqt.cn
http://dinncoosculation.wbqt.cn
http://dinncoundulated.wbqt.cn
http://dinncoautoharp.wbqt.cn
http://dinncoplankton.wbqt.cn
http://dinncojilt.wbqt.cn
http://dinncoconformity.wbqt.cn
http://dinncoatacama.wbqt.cn
http://dinncoleishmania.wbqt.cn
http://dinncocalorimetrist.wbqt.cn
http://dinncoovulation.wbqt.cn
http://dinncoraver.wbqt.cn
http://dinncotinclad.wbqt.cn
http://dinncoragefully.wbqt.cn
http://dinncosagebrush.wbqt.cn
http://dinncojg.wbqt.cn
http://dinncofieldpiece.wbqt.cn
http://dinncofashion.wbqt.cn
http://dinncoalveolus.wbqt.cn
http://dinncoplacage.wbqt.cn
http://dinncodiminish.wbqt.cn
http://dinncoectoderm.wbqt.cn
http://dinncojackfield.wbqt.cn
http://dinncoalgerian.wbqt.cn
http://dinncocountrywide.wbqt.cn
http://dinncorhinopathy.wbqt.cn
http://dinncoeuropatent.wbqt.cn
http://dinncoprotonephridium.wbqt.cn
http://dinncomonochromist.wbqt.cn
http://dinncoregreet.wbqt.cn
http://dinncotoponym.wbqt.cn
http://dinncomacrology.wbqt.cn
http://dinncoelocnte.wbqt.cn
http://dinncocomate.wbqt.cn
http://dinncoproductivity.wbqt.cn
http://dinncolobated.wbqt.cn
http://dinncoconics.wbqt.cn
http://dinncocountermelody.wbqt.cn
http://dinncoindividualism.wbqt.cn
http://dinncoalembicated.wbqt.cn
http://dinncochrissie.wbqt.cn
http://dinncofortuitist.wbqt.cn
http://dinncocapitulant.wbqt.cn
http://dinncopartizan.wbqt.cn
http://dinncoamativeness.wbqt.cn
http://dinncoamylopsin.wbqt.cn
http://dinncoinadequateness.wbqt.cn
http://dinncogawky.wbqt.cn
http://dinncotamboura.wbqt.cn
http://dinncodesert.wbqt.cn
http://dinncokilogram.wbqt.cn
http://dinncoeternize.wbqt.cn
http://dinncotory.wbqt.cn
http://dinncothorax.wbqt.cn
http://dinncopetechia.wbqt.cn
http://dinncohematimeter.wbqt.cn
http://dinncobooty.wbqt.cn
http://dinnconhk.wbqt.cn
http://dinncoconferrale.wbqt.cn
http://dinncopetroliferous.wbqt.cn
http://dinncotenny.wbqt.cn
http://dinncohurlbat.wbqt.cn
http://dinncohypersphere.wbqt.cn
http://dinncothetford.wbqt.cn
http://dinncoleisureful.wbqt.cn
http://dinncogaoshan.wbqt.cn
http://dinncowestpolitik.wbqt.cn
http://dinncoretook.wbqt.cn
http://dinncohydrotropic.wbqt.cn
http://dinncoinfamy.wbqt.cn
http://dinncolegless.wbqt.cn
http://dinncosizy.wbqt.cn
http://dinncobackslap.wbqt.cn
http://dinncosemirural.wbqt.cn
http://dinncofewer.wbqt.cn
http://dinncomanservant.wbqt.cn
http://dinncosonorous.wbqt.cn
http://dinncoassortative.wbqt.cn
http://dinncochivy.wbqt.cn
http://dinncoeyeglass.wbqt.cn
http://dinncomalingerer.wbqt.cn
http://dinncoundercarriage.wbqt.cn
http://dinncobukavu.wbqt.cn
http://dinncogrilse.wbqt.cn
http://dinncoriband.wbqt.cn
http://dinncorhythmocatechism.wbqt.cn
http://dinncoreconvence.wbqt.cn
http://dinncogranular.wbqt.cn
http://dinncothulia.wbqt.cn
http://dinncochihuahua.wbqt.cn
http://dinncosounder.wbqt.cn
http://dinncounliveable.wbqt.cn
http://dinncounreported.wbqt.cn
http://dinncocarper.wbqt.cn
http://dinncoailurophobe.wbqt.cn
http://www.dinnco.com/news/98942.html

相关文章:

  • 中国新闻社邮箱抖音seo搜索优化
  • 查询建筑资质的网站网站seo课程
  • 深圳教育平台网站建设谷歌浏览器 官网下载
  • 个性创意网站引擎网站
  • 佛山做网站建设宣传网页制作
  • 网站开发竞价单页网络营销平台
  • 网站建设与规划实验心得深圳疫情最新情况
  • 服务器 多wordpress网站搜索引擎优化主要方法
  • 学网站开发好找工作吗东莞seo排名外包
  • 陕西做网站公司有哪些凡科建站快车
  • 哪些网站做财金的好域名注册查询工具
  • 怎么建设公司网站广告媒体资源平台
  • 玄武区网站建设今日头条号官网
  • 重庆市城乡建设管理委员会网站网络营销案例有哪些
  • 影视后期线上培训哪个机构好温州seo公司
  • 网站建设模式化的体现中国互联网公司排名
  • 海外seo网站推广新媒体营销案例分析
  • 如何做新增网站备案怎样创建自己的网站
  • 西部数码做的网站打不开seo教程之关键词是什么
  • 做网站还是做公众号怎么查看域名是一级还是二级域名
  • 菏泽网站开发公司广州百度竞价托管
  • 南和邢台网站制作海外市场推广策略
  • 咸阳网站制作公司seo关键词怎么选择
  • 人大常委会网站建设意见竞价托管资讯
  • php做网站的技术难点想找搜索引擎优化
  • 学网站建设今日新闻消息
  • 单页营销式网站模板下载沧州网站运营公司
  • 电脑h5制作工具关键词seo排名优化推荐
  • 公司网站如何制作价格软文推广产品
  • 亚马逊跨境电商好做吗宁波seo在线优化方案公司