动机

在用稀疏自编码器对8*8 或28*28等小图像提取特征时是可行的,但是若对大图像学习整幅图像的特征,将会非常耗时。因此需要把这种“全连接”的设计改为“部分联通”的网络。

卷积

自然图像有其固有特性——图像的一部分统计特征与其他部分是一样的,这也意味着我们在这一部分上学习的特征也能用在另一部分上,所以对这个图像上的所以位置,我们都能使用同样的学习特征。
比如,可以8*8的样本中学习到一些特征,并把这个特征应用到图像的任意地方去。特别是,我们可以从8*8的样本中学习的特征跟原来的大尺寸图像做卷积。

池化

得到的卷积特征就可以去训练分类器了,但是由于卷积特征的维数很高,除了计算慢之外,还容易出现过拟合。因此把每一个的卷积特征进行池化。如卷积特征是89^2*400,表示400个特征,每个特征有89^2维。池化就是对每一特征89^2,平均分成若干固定大小不相干的块,可以用块内的平均或最大值代表,这样若分成了10块,则89^2维就变成了10维。
池化具有平移性

练习

这个部分感觉做了练习才理解的清楚了。
step1:从大图像中随机提取8*8的小块–> ZCA白化–>用SparseEncoder提取出特征。
step2:实现卷积

function convolvedFeatures = cnnConvolve(patchDim, numFeatures, images, W, b, ZCAWhite, meanPatch)
%cnnConvolve Returns the convolution of the features given by W and b with
%the given images
%
% Parameters:
%  patchDim - patch (feature) dimension
%  numFeatures - number of features
%  images - large images to convolve with, matrix in the form
%           images(r, c, channel, image number)
%  W, b - W, b for features from the sparse autoencoder
%  ZCAWhite, meanPatch - ZCAWhitening and meanPatch matrices used for
%                        preprocessing
%
% Returns:
%  convolvedFeatures - matrix of convolved features in the form
%                      convolvedFeatures(featureNum, imageNum, imageRow, imageCol)numImages = size(images, 4);
imageDim = size(images, 1);
imageChannels = size(images, 3);%convolvedFeatures = zeros(numFeatures, numImages, imageDim - patchDim + 1, imageDim - patchDim + 1);% Instructions:
%   Convolve every feature with every large image here to produce the
%   numFeatures x numImages x (imageDim - patchDim + 1) x (imageDim - patchDim + 1)
%   matrix convolvedFeatures, such that
%   convolvedFeatures(featureNum, imageNum, imageRow, imageCol) is the
%   value of the convolved featureNum feature for the imageNum image over
%   the region (imageRow, imageCol) to (imageRow + patchDim - 1, imageCol + patchDim - 1)
%
% Expected running times:
%   Convolving with 100 images should take less than 3 minutes
%   Convolving with 5000 images should take around an hour
%   (So to save time when testing, you should convolve with less images, as
%   described earlier)% -------------------- YOUR CODE HERE --------------------
% Precompute the matrices that will be used during the convolution. Recall
% that you need to take into account the whitening and mean subtraction
% stepsWT=W*ZCAWhite;
b_mean = b - WT*meanPatch;% --------------------------------------------------------convolvedFeatures = zeros(numFeatures, numImages, imageDim - patchDim + 1, imageDim - patchDim + 1);
for imageNum = 1:numImagesfor featureNum = 1:numFeatures% convolution of image with feature matrix for each channelconvolvedImage = zeros(imageDim - patchDim + 1, imageDim - patchDim + 1);for channel = 1:imageChannels% Obtain the feature (patchDim x patchDim) needed during the convolution% ---- YOUR CODE HERE ----feature = zeros(8,8); % You should replace thisoffset=(channel-1)*patchDim*patchDim;fea=WT(featureNum,offset+1:offset+patchDim*patchDim);feature=reshape(fea,patchDim,patchDim);% ------------------------% Flip the feature matrix because of the definition of convolution, as explained laterfeature = flipud(fliplr(squeeze(feature)));% Obtain the imageim = squeeze(images(:, :, channel, imageNum));% Convolve "feature" with "im", adding the result to convolvedImage% be sure to do a 'valid' convolution% ---- YOUR CODE HERE ----convolvedImage=convolvedImage+conv2( im,feature,'valid' );% ------------------------end% Subtract the bias unit (correcting for the mean subtraction as well)% Then, apply the sigmoid function to get the hidden activation% ---- YOUR CODE HERE ----convolvedImage=sigmoid(convolvedImage+b_mean(featureNum));% ------------------------% The convolved feature is the sum of the convolved values for all channelsconvolvedFeatures(featureNum, imageNum, :, :) = convolvedImage;end
endendfunction sigm=sigmoid(x)sigm=1./(1+exp(-x));
end

step3:池化

function pooledFeatures = cnnPool(poolDim, convolvedFeatures)
%cnnPool Pools the given convolved features
%
% Parameters:
%  poolDim - dimension of pooling region
%  convolvedFeatures - convolved features to pool (as given by cnnConvolve)
%                      convolvedFeatures(featureNum, imageNum, imageRow, imageCol)
%
% Returns:
%  pooledFeatures - matrix of pooled features in the form
%                   pooledFeatures(featureNum, imageNum, poolRow, poolCol)
%     numImages = size(convolvedFeatures, 2);
numFeatures = size(convolvedFeatures, 1);
convolvedDim = size(convolvedFeatures, 3);pooledFeatures = zeros(numFeatures, numImages, floor(convolvedDim / poolDim), floor(convolvedDim / poolDim));numRegin=floor(convolvedDim / poolDim);
for featureNum=1:numFeaturesfor imageNum=1:numImagesfor row=1:numReginfor col=1:numReginregin=convolvedFeatures(featureNum, imageNum,(row-1)*poolDim+1:row*poolDim,(col-1)*poolDim+1:col*poolDim);pooledFeatures(featureNum,imageNum,row,col)=mean(regin(:));endendend
end
end

深度学习笔记7 Working with Large Images 卷积特征提取相关推荐

  1. 深度学习笔记(三十一)三维卷积及卷积神经网络

    一.RGB三维图像的卷积 首先复习以下二维卷积运算的过程: 然后让我们看看三维图像如何进行有效的卷积运算. 计算方法和二维卷积类似,从三维图像中划分出3×3×33\times3\times33×3×3 ...

  2. 深度学习笔记(22) Padding

    深度学习笔记(22) Padding 1. 卷积的缺陷 2. Padding 3. Valid卷积 4. Same卷积 5. 奇数的过滤器 1. 卷积的缺陷 为了构建深度神经网络,需要学会使用的一个基 ...

  3. 下载量过百万的吴恩达机器学习和深度学习笔记更新了!(附PDF下载)

    今天,我把吴恩达机器学习和深度学习课程笔记都更新了,并提供下载,这两本笔记非常适合机器学习和深度学习入门.(作者:黄海广) 0.导语 我和同学将吴恩达老师机器学习和深度学习课程笔记做成了打印版,放在g ...

  4. 34.Oracle深度学习笔记——12C的AWR初步解读

    34.Oracle深度学习笔记--12C的AWR初步解读 关于AWR,蛤蟆也经常看.因为经常看别人给出的建议,很难有深刻体会.对此,计划花费几个晚上时间好好体会一把并记录下来.此处以单实例为例.列出目 ...

  5. 2020年Yann Lecun深度学习笔记(下)

    2020年Yann Lecun深度学习笔记(下)

  6. 2020年Yann Lecun深度学习笔记(上)

    2020年Yann Lecun深度学习笔记(上)

  7. 《繁凡的深度学习笔记》前言、目录大纲 一文让你完全弄懂深度学习所有基础(DL笔记整理系列)

    <繁凡的深度学习笔记>前言.目录大纲 (DL笔记整理系列) 一文弄懂深度学习所有基础 ! 3043331995@qq.com https://fanfansann.blog.csdn.ne ...

  8. 一文弄懂元学习 (Meta Learing)(附代码实战)《繁凡的深度学习笔记》第 15 章 元学习详解 (上)万字中文综述

    <繁凡的深度学习笔记>第 15 章 元学习详解 (上)万字中文综述(DL笔记整理系列) 3043331995@qq.com https://fanfansann.blog.csdn.net ...

  9. 一文让你完全弄懂逻辑回归和分类问题实战《繁凡的深度学习笔记》第 3 章 分类问题与信息论基础(上)(DL笔记整理系列)

    好吧,只好拆分为上下两篇发布了>_< 终于肝出来了,今天就是除夕夜了,祝大家新快乐!^q^ <繁凡的深度学习笔记>第 3 章 分类问题与信息论基础 (上)(逻辑回归.Softm ...

最新文章

  1. IO流(文件的读写)---本文的正确性有待您验证。
  2. Perfect service(树形dp)
  3. 一句话告诉你们什么是大数据
  4. windows家庭版 启用组策略
  5. linux分区用来支持虚拟内存,Linux分区方案
  6. sola病毒批量恢复工具 —— 大一的回忆
  7. 堪称神器的办公工具,国产精品福昕PDF编辑器上榜
  8. 计算机网络-网络规划与设计
  9. 算法入门篇:排序算法(一)
  10. Python 中那些令人防不胜防的坑(一)
  11. linux下修改tomcat默认访问主页
  12. 微信开发必备工具:利用cpolar在公网上测试本地Web网站或移动应用程序
  13. 无法打开msdn主页以及与微软相关的其他主页,但能打开其他网页
  14. java中事件监听是什么意思_Java的事件监听器学习心得
  15. php ecb加密,PHP使用TripleDes,PKCS7和ECB加密/解密
  16. h5:jquery+xgplayer实现点击封面全屏播放视频
  17. latex表格内容上下居中_latex怎么让表格里的字上下垂直居中?
  18. 零基础学Python--机器学习(一):人工智能与机器学习概述
  19. STM32入门-学习STM32要掌握的内容
  20. 期权基础:期权?期权是如何盈利的?

热门文章

  1. php中mb substr,php中中文截取函数mb_substr()详细
  2. Netty详解(五):Netty TCP粘包 拆包
  3. LetCode 3 无重复字符的最大子串
  4. 前端html5的框架有哪些,10大html5前端框架
  5. WIN下Nginx缓存加速配置方法
  6. spark面试总结1
  7. 王艳 201771010127《面向对象程序设计(java)》第十七周学习总结
  8. L1、L2正则化详解
  9. 消息队列rabitMq
  10. Android性能优化(3)