VGG Convolutional Neural Networks Practical(6)learning a tiny CNN

本文介绍了一个非常简单的卷积神经网络(CNN),该网络仅由卷积层和最大池层组成。通过分析tinycnn.m文件中的代码,读者可以了解CNN的基本工作原理,并学会如何从图像中提取Blob样结构。

在这部分,我们将学习一个非常简单的CNN。 CNN完全由两层组成:卷积层和最大池层:
这里写图片描述

任务
打开文件tinycnn.m并检查代码。 说服你自己,代码计算刚刚描述的CNN。
看看代码中使用的paddings。 如果输入图像x1具有尺寸M×N,则输出特征图x3的尺寸是多少?

function res = tinycnn(x, w, b, dzdy)
% TINYCNN  A very simple CNN
%   RES = TINYCNN(X, W, B) evaluates a CNN with two layers: linear
%   filtering and max pooling. W is a QxQ filter and B its (scalar) bias
%   and X a MxN input image.
%
%   RES = TINYCNN(X, W, B, DZDY) backpropagates the CNN loss derivative DZDY
%   thorugh the network.
%
%   RES.X1, RES.X2, and RES.X3 contain the input of the first and second
%   CNN layers and of the CNN loss. RES.DZDX1, RES.DZDX2, and RES.DZDX3
%   contain the corresponding derivatives. RES.DZDW and RES.DZDB contain
%   the derivatives of the loss with respect to the parameters W and B.

% Author: Andrea Vedaldi

% Paramters of the layers
pad1 = ([size(w,1) size(w,1) size(w,2) size(w,2)] - 1) / 2 ;
rho2 = 3 ;
pad2 = (rho2 - 1) / 2 ;

% Forward pass
res.x1 = x ;
res.x2 = vl_nnconv(res.x1, w, b, 'pad', pad1) ;
res.x3 = vl_nnpool(res.x2, rho2, 'pad', pad2) ;

% Backward pass (only if passed output derivative)
if nargin > 3
  res.dzdx3 = dzdy ;
  res.dzdx2 = vl_nnpool(res.x2, rho2, res.dzdx3, 'pad', pad2) ;
  [res.dzdx1, res.dzdw, res.dzdb] = ...
    vl_nnconv(res.x1, w, b, res.dzdx2, 'pad', pad1) ;
end

在本节的其余部分中,我们将学习CNN参数,以便从图像中提取Blob样结构,如下图所示:
这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值