deep learning convolution and pooling(卷积和池化)

一、首先先给出图示,什么叫卷积。()

当然很多人会疑问,,为什么卷积后的图像会缩小,那是因为在进行图像滤波的时候边缘没有加0进行填充。正常的图像滤波边缘是会填充0,这样滤波出来的图像与原图像的大小保持一致。卷积可以用如下表示式来表示:

训练卷积核的方式(第一种):

当你在监督学习的时候你不用改变它的参数,它的参数时固定的。例如:你想提取人脸的特征,目前你已经有了自己的数据集,想训练9×9的卷积核(滤波器),这时你可以从你的数据集上取任意去9×9的小块,当然你取的小块越多,训练出来的卷积核越鲁棒。下面我按步骤来说明:

(1)取数据集上大量的小块,为训练滤波器做准备,滤波器的大小决定了你取小块的大小。

先给出图示:

选择图像中的连续范围作为池化区域,并且只是池化相同(重复)的隐藏单元产生的特征,那么,这些池化单元就具有平移不变性(translation invariant)。这就意味着即使图像经历了一个小的平移之后,依然会产生相同的(池化的) 特征。

下面给出实验的结果和代码

实验参用的数据库为英国剑桥的大学的ORL人脸数据库。

图 ORL人脸数据库

个滤波器如下图所示。

下面分别是任意一张人脸卷积和池化的结果图

卷积后的结果图

池化后结果图

数据库下载地址:html。 图片大小为112×92,一共200张,可以处理200×10304,并保存为FaceContainer.mat

下面是展示图片结果的函数

display_network.m

<span style="font-family:Times New Roman;font-size:18px;">function [h, array] = display_network(A,sz1,sz, opt_normalize, opt_graycolor, cols, opt_colmajor)% This function visualizes filters in matrix A. Each column of A is a% filter. We will reshape each column into a square image and visualizes% on each cell of the visualization panel. % All other parameters are optional, usually you do not need to worry% about it.% opt_normalize: whether we need to normalize the filter so that all of% them can have similar contrast. Default value is true.% opt_graycolor: whether we use gray as the heat map. Default is true.% cols: how many columns are there in the display. Default value is the% squareroot of the number of columns in A.% opt_colmajor: you can switch convention to row major for A. In that% case, each row of A is a filter. Default value is false.warning off allif ~exist('opt_normalize', 'var') || isempty(opt_normalize)opt_normalize= true;endif ~exist('opt_graycolor', 'var') || isempty(opt_graycolor)opt_graycolor= true;endif ~exist('opt_colmajor', 'var') || isempty(opt_colmajor)opt_colmajor = false;end% rescaleA = A – mean(A(:));if opt_graycolor, colormap(gray); end% compute rows, cols[L M]=size(A);%sz=sqrt(L);buf=1;if ~exist('cols', 'var')if floor(sqrt(M))^2 ~= Mn=ceil(sqrt(M));while mod(M, n)~=0 && n<1.2*sqrt(M), n=n+1; endm=ceil(M/n);elsen=sqrt(M);m=n;endelsen = cols;m = ceil(M/n);endarray=-ones(buf+m*(sz1+buf),buf+n*(sz+buf));if ~opt_graycolorarray = 0.1.* array;endif ~opt_colmajork=1;for i=1:mfor j=1:nif k>M,continue;endclim=max(abs(A(:,k)));if opt_normalizearray(buf+(i-1)*(sz1+buf)+(1:sz1),buf+(j-1)*(sz+buf)+(1:sz))=reshape(A(:,k),sz1,sz)/clim;elsearray(buf+(i-1)*(sz1+buf)+(1:sz1),buf+(j-1)*(sz+buf)+(1:sz))=reshape(A(:,k),sz1,sz)/max(abs(A(:)));endk=k+1;endendelsek=1;for j=1:nfor i=1:mif k>M,continue;endclim=max(abs(A(:,k)));if opt_normalizearray(buf+(i-1)*(sz1+buf)+(1:sz1),buf+(j-1)*(sz+buf)+(1:sz))=reshape(A(:,k),sz1,sz)/clim;elsearray(buf+(i-1)*(sz1+buf)+(1:sz1),buf+(j-1)*(sz+buf)+(1:sz))=reshape(A(:,k),sz1,sz);endk=k+1;endendendif opt_graycolorh=imagesc(array,'EraseMode','none',[-1 1]);elseh=imagesc(array,'EraseMode','none',[-1 1]);endaxis image offdrawnow;warning on all</span>有理想在的地方,地狱就是天堂

deep learning convolution and pooling(卷积和池化)

相关文章:

你感兴趣的文章:

标签云: