cnn卷积过程简略概述

假设输入:4通道的featureMap  大小为4*28*28

输出:96通道的featureMap

4通道的featureMap 卷积后变为96个通道的featureMap

需要96个卷积核,每个卷积核的大小为4*kernel_h*kernel_w(卷积核是有深度的,切记!!!)

需要bias 为96个

 

卷积过程:

1、计算卷积后的featureMap大小:

top_n = bottom_n

top_c = num_output

top_h = (bottom_h +2*pad_h-kernel_h)/stride_h+1

top_w = (bottom_w+2*pad_w-kernel_w)/stride_w+1

 

2、计算卷积过程中响应点对应的输入坐标矩阵

offset_h = top_h*stride_h-pad_h

offset_w = top_w*stride_w-pad_w

响应矩阵为:[offset_h:offset_h+kernel_h,offset_w:offset_w+kernel_w]

 

3、卷积计算

把相应点对应的响应矩阵与对应的卷积核分别卷积后,进行相加,再加上对应的bias(切记!!!bias一个响应点输出只加一次)

卷积代码如下:

def __conv(self,bottom_blob,top_blob):
        bottom_n,bottom_c,bottom_h,bottom_w = bottom_blob.shape
        top_n,top_c,top_h,top_w = top_blob.shape
        for t_n in range(top_n):
            for t_c in range(top_c):
                for h in range(top_h):
                    for w in range(top_w):
                        for b_c in range(bottom_c):
                            for row in range(self.__kernel_h):
                                offset_h = self.__stride_h*h-self.__pad_h + row
                                if offset_h < 0 or offset_h >= bottom_h:
                                    continue
                                for col in range(self.__kernel_w):
                                    offset_w = self.__stride_w*w-self.__pad_w+col
                                    if offset_w<0 or offset_w>=bottom_w:
                                        continue
                                    top_blob[t_n][t_c][h][w] += bottom_blob[t_n][b_c][offset_h][offset_w]*self._w[t_c][b_c][row][col]

                        top_blob[t_n][t_c][h][w] += self._b[t_c]

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值