首页 > 代码库 > Convolution & Pooling exercise
Convolution & Pooling exercise
convolution
First, we want to compute σ(Wx(r,c) + b) for all valid (r,c) (valid meaning that the entire 8x8 patch is contained within the image; this is as opposed to a full convolution, which allows the patch to extend outside the image, with the area outside the image assumed to be 0), where W and b are the learned weights and biases from the input layer to the hidden layer, and x(r,c) is the 8x8 patch with the upper left corner at (r,c).
卷积操作是为了解除输入层和隐藏层之间的全链接 —— 全链接会带来很高的计算成本
这样只是对局部patch进行sigmoid(W,b),卷积操作使用matlab的conv2函数
First, conv2 performs a 2-D convolution, but you have 5 "dimensions" - image number, feature number, row of image, column of image, and (color) channel of image - that you want to convolve over. Because of this, you will have to convolve each feature and image channel separately for each image, using the row and column of the image as the 2 dimensions you convolve over. This means that you will need three outer loops over the image number imageNum, feature number featureNum, and the channel number of the image channel.
卷积的作用对象不是直接的像素点,而是图像中提取出的特征
Second, because of the mathematical definition of convolution, the feature matrix must be "flipped" before passing it toconv2. The following implementation tip explains the "flipping" of feature matrices when using MATLAB‘s convolution
使用matlab计算卷积,需要对卷积patch进行反转
In particular, you did the following to the patches:
- subtract the mean patch, meanPatch to zero the mean of the patches
- ZCA whiten using the whitening matrix ZCAWhite.
These same three steps must also be applied to the input image patches.
Taking the preprocessing steps into account, the feature activations that you should compute is , whereT is the whitening matrix and is the mean patch. Expanding this, you obtain , which suggests that you should convolve the images with WT rather than W as earlier, and you should add , rather than just b toconvolvedFeatures, before finally applying the sigmoid function.
对每个patch计算其均值和ZCA whiten
Pooling
首先在前面的使用convolution时是利用了图像的stationarity特征,即不同部位的图像的统计特征是相同的,那么在使用convolution对图片中的某个局部部位计算时,得到的一个向量应该是对这个图像局部的一个特征,既然图像有stationarity特征,那么对这个得到的特征向量进行统计计算的话,所有的图像局部块应该也都能得到相似的结果。对convolution得到的结果进行统计计算过程就叫做pooling,由此可见pooling也是有效的。常见的pooling方法有max pooling和average pooling等。并且学习到的特征具有旋转不变性
Convolution & Pooling exercise