ufldl学习笔记和编程作业:Feature Extraction Using Convolution,Pooling(卷积和汇集特征提取)
ufldl学习笔记与编程作业:Feature Extraction Using Convolution,Pooling(卷积和池化抽取特征)
ufldl出了新教程,感觉比之前的好,从基础讲起。系统清晰。又有编程实践。
在deep learning高质量群里面听一些前辈说。不必深究其它机器学习的算法。能够直接来学dl。
于是近期就開始搞这个了。教程加上matlab编程,就是完美啊。
新教程的地址是:http://ufldl.stanford.edu/tutorial/
这里用了conv2来算均值,能够优化性能。
记得。这里不须要激活函数。!!
function convolvedFeatures = cnnConvolve(filterDim, numFilters, images, W, b)
%cnnConvolve Returns the convolution of the features given by W and b with
%the given images
%
% Parameters:
% filterDim - filter (feature) dimension
% numFilters - number of feature maps
% images - large images to convolve with, matrix in the form
% images(r, c, image number) % -------------注意维度的位置
% W, b - W, b for features from the sparse autoencoder
% W is of shape (filterDim,filterDim,numFilters)
% b is of shape (numFilters,1)
%
% Returns:
% convolvedFeatures - matrix of convolved features in the form
% convolvedFeatures(imageRow, imageCol, featureNum, imageNum) % ----------注意维度的位置 numImages = size(images, 3);
imageDim = size(images, 1); %行数,即是高度。 这里没算宽度,貌似默认高宽相等。
convDim = imageDim - filterDim + 1; % 卷积后,特征的高度 convolvedFeatures = zeros(convDim, convDim, numFilters, numImages); % Instructions:
% Convolve every filter with every image here to produce the
% (imageDim - filterDim + 1) x (imageDim - filterDim + 1) x numFeatures x numImages
% matrix convolvedFeatures, such that
% convolvedFeatures(imageRow, imageCol, featureNum, imageNum) is the
% value of the convolved featureNum feature for the imageNum image over
% the region (imageRow, imageCol) to (imageRow + filterDim - 1, imageCol + filterDim - 1)
%
% Expected running times:
% Convolving with 100 images should take less than 30 seconds
% Convolving with 5000 images should take around 2 minutes
% (So to save time when testing, you should convolve with less images, as
% described earlier) for imageNum = 1:numImages
for filterNum = 1:numFilters % convolution of image with feature matrix
convolvedImage = zeros(convDim, convDim); % Obtain the feature (filterDim x filterDim) needed during the convolution %%% YOUR CODE HERE %%%
filter = W(:,:,filterNum); % Flip the feature matrix because of the definition of convolution, as explained later
filter = rot90(squeeze(filter),2); %squeeze是把仅仅有一个维度的那一维给去掉。 这里就是把第三维给去掉,三维变二维。 % Obtain the image
im = squeeze(images(:, :, imageNum)); % Convolve "filter" with "im", adding the result to convolvedImage
% be sure to do a 'valid' convolution %%% YOUR CODE HERE %%%
convolvedImage =conv2(im, filter,"valid");%加上valid參数,以下代码不要了。 %conv2Dim = size(convolvedImage,1);
%im_start = (conv2Dim - convDim+2)/2;
%im_end = im_start+convDim-1;
%convolvedImage = convolvedImage(im_start:im_end,im_start:im_end);%取中间部分 % Add the bias unit
% Then, apply the sigmoid function to get the hidden activation %%% YOUR CODE HERE %%%
convolvedImage = convolvedImage.+b(filterNum);
convolvedImage = sigmoid(convolvedImage);
convolvedImage = reshape(convolvedImage,convDim, convDim, 1, 1);%2维变维4维 convolvedFeatures(:, :, filterNum, imageNum) = convolvedImage;
end
end end
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(imageRow, imageCol, featureNum, imageNum)
%
% Returns:
% pooledFeatures - matrix of pooled features in the form
% pooledFeatures(poolRow, poolCol, featureNum, imageNum)
% numImages = size(convolvedFeatures, 4);
numFilters = size(convolvedFeatures, 3);
convolvedDim = size(convolvedFeatures, 1); pooledFeatures = zeros(convolvedDim / poolDim, ...
convolvedDim / poolDim, numFilters, numImages); % Instructions:
% Now pool the convolved features in regions of poolDim x poolDim,
% to obtain the
% (convolvedDim/poolDim) x (convolvedDim/poolDim) x numFeatures x numImages
% matrix pooledFeatures, such that
% pooledFeatures(poolRow, poolCol, featureNum, imageNum) is the
% value of the featureNum feature for the imageNum image pooled over the
% corresponding (poolRow, poolCol) pooling region.
%
% Use mean pooling here. %%% YOUR CODE HERE %%%
filter = ones(poolDim);
for imageNum=1:numImages
for filterNum=1:numFilters
im = squeeze(squeeze(convolvedFeatures(:, :,filterNum,imageNum)));%貌似squeeze不要也能够
pooledImage =conv2(im, filter,"valid");
pooledImage = pooledImage(1:poolDim:end,1:poolDim:end);%取中间部分
pooledImage = pooledImage./(poolDim*poolDim); %pooledImage = sigmoid(pooledImage); %不须要sigmoid
pooledImage = reshape(pooledImage,convolvedDim / poolDim, convolvedDim / poolDim, 1, 1);%2维变维4维 pooledFeatures(:, :, filterNum, imageNum) = pooledImage;
end
end end
版权声明:本文博客原创文章。博客,未经同意,不得转载。
ufldl学习笔记和编程作业:Feature Extraction Using Convolution,Pooling(卷积和汇集特征提取)的更多相关文章
- ufldl学习笔记和编程作业:Softmax Regression(softmax回报)
ufldl学习笔记与编程作业:Softmax Regression(softmax回归) ufldl出了新教程.感觉比之前的好,从基础讲起.系统清晰,又有编程实践. 在deep learning高质量 ...
- ufldl学习笔记与编程作业:Softmax Regression(vectorization加速)
ufldl学习笔记与编程作业:Softmax Regression(vectorization加速) ufldl出了新教程,感觉比之前的好.从基础讲起.系统清晰,又有编程实践. 在deep learn ...
- ufldl学习笔记与编程作业:Multi-Layer Neural Network(多层神经网络+识别手写体编程)
ufldl学习笔记与编程作业:Multi-Layer Neural Network(多层神经网络+识别手写体编程) ufldl出了新教程,感觉比之前的好,从基础讲起,系统清晰,又有编程实践. 在dee ...
- ufldl学习笔记与编程作业:Logistic Regression(逻辑回归)
ufldl学习笔记与编程作业:Logistic Regression(逻辑回归) ufldl出了新教程,感觉比之前的好,从基础讲起.系统清晰,又有编程实践. 在deep learning高质量群里面听 ...
- ufldl学习笔记与编程作业:Linear Regression(线性回归)
ufldl学习笔记与编程作业:Linear Regression(线性回归) ufldl出了新教程,感觉比之前的好.从基础讲起.系统清晰,又有编程实践. 在deep learning高质量群里面听一些 ...
- 我的学习笔记_Windows_HOOK编程 2009-12-03 11:19
一.什么是HOOK? "hook"这个单词的意思是"钩子","Windows Hook"是Windows消息处理机制的一个重要扩展,程序猿能 ...
- 大数据学习笔记——Hadoop编程实战之Mapreduce
Hadoop编程实战——Mapreduce基本功能实现 此篇博客承接上一篇总结的HDFS编程实战,将会详细地对mapreduce的各种数据分析功能进行一个整理,由于实际工作中并不会过多地涉及原理,因此 ...
- 大数据学习笔记——Hadoop编程实战之HDFS
HDFS基本API的应用(包含IDEA的基本设置) 在上一篇博客中,本人详细地整理了如何从0搭建一个HA模式下的分布式Hadoop平台,那么,在上一篇的基础上,我们终于可以进行编程实操了,同样,在编程 ...
- 学习笔记之编程珠玑 Programming Pearls
Programming Pearls (2nd Edition): Jon Bentley: 0785342657883: Amazon.com: Books https://www.amazon.c ...
随机推荐
- OpenSSL命令---rand
用途: 用来产生伪随机字节.随机数字产生器需要一个seed,先已经说过了,在没有/dev/srandom系统下的解决方法是自己做一个~/.rnd文件.如果该程序能让随机数字产生器很满意的被seeded ...
- Spring如何管理Session【转贴】
在使用Spring进行系统开发的时候,数据库连接一般都是配置在Spring的配置文件中,并且由Spring来管理的.在利用Spring + Hibernate进行开发时也是如此.下面是一个简单的Spr ...
- 一个Java程序的执行过程(转)
我们手工执行java程序是这样的: 1.在记事本中或者是UE的文本编辑器中,写好源程序: 2.使用javac命令把源程序编译成.class文件: 编译后的.class(类字节码)文件中会包含 ...
- php 父类子类构造函数注意事项
网上流传的2点: PHP的构造函数继承必须满足以下条件: 当父类有构造函数的声明时,子类也必须有声明,否则会出错. 在执行父类的构造函数时,必须在子类中引用parent关键字. 第1点不需要. 第二个 ...
- 设计模式 ( 十九 ) 模板方法模式Template method(类行为型)
设计模式 ( 十九 ) 模板方法模式Template method(类行为型) 1.概述 在面向对象开发过程中,通常我们会遇到这样的一个问题:我们知道一个算法所需的关键步骤,并确定了这些步骤的执行 ...
- cocos2d-x游戏开发系列教程-超级玛丽02-代码结构
代码下载链接 http://download.csdn.net/detail/yincheng01/6864893 解压密码:c.itcast.cn 前景回顾 上一篇博文提到超级马里奥的游戏效果,大家 ...
- 神奇的矩阵 NOI模拟题
神奇的矩阵 题目大意 有一个矩阵\(A\),第一行是给出的,接下来第\(x\)行,第\(y\)个元素的值为数字\(A_{x-1,y}\)在\(\{A_{x-1,1},A_{x-1,2},A_{x-1, ...
- ArduinoYun教程之配置Arduino Yun环境
ArduinoYun教程之配置Arduino Yun环境 配置Arduino Yun 不管你使用前面介绍的哪种方式连接Arduino Yun.如今都能够配置你的Arduino Yun了.首先须要的是使 ...
- libevent: linux安装libevent
http://libevent.org/上下载最新的libevent, 如 libevent-2.0.22-stable.tar.gz. 然后解压,按照README里面的步骤安装.
- Eclipse生成Jar包方法
Eclipse生成jar包 第一:普通类导出jar包,我说的普通类就是指此类包含main方法,并且没有用到别的jar包. 1.在eclipse中选择你要导出的类或者package,右击,选择Exp ...