-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathPool.m
53 lines (48 loc) · 1.93 KB
/
Pool.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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);
resDim = floor(convolvedDim / poolDim);
pooledFeatures = zeros(numFeatures, numImages, floor(convolvedDim / poolDim), floor(convolvedDim / poolDim));
% -------------------- YOUR CODE HERE --------------------
% Instructions:
% Now pool the convolved features in regions of poolDim x poolDim,
% to obtain the
% numFeatures x numImages x (convolvedDim/poolDim) x (convolvedDim/poolDim)
% matrix pooledFeatures, such that
% pooledFeatures(featureNum, imageNum, poolRow, poolCol) is the
% value of the featureNum feature for the imageNum image pooled over the
% corresponding (poolRow, poolCol) pooling region
% (see http://ufldl/wiki/index.php/Pooling )
%
% Use mean pooling here.
% -------------------- YOUR CODE HERE --------------------
for imageNum = 1:numImages
for featureNum = 1:numFeatures
for poolRow = 1:resDim
rowStart = (poolRow - 1) * poolDim + 1;
rowEnd = rowStart + poolDim - 1;
for poolCol = 1:resDim
colStart = (poolCol - 1) * poolDim + 1;
colEnd = colStart + poolDim - 1;
patch = convolvedFeatures(featureNum, imageNum, ...
rowStart:rowEnd, ...
colStart:colEnd);
pooledFeatures(featureNum, imageNum, poolRow, poolCol) ...
= max(patch(:));
end
end
end
end
end