|
40 | 40 | % that you need to take into account the whitening and mean subtraction |
41 | 41 | % steps |
42 | 42 |
|
43 | | - |
44 | | - |
45 | | - |
46 | | - |
| 43 | +wt = W * ZCAWhite; |
| 44 | +bt = b - wt * meanPatch; |
47 | 45 |
|
48 | 46 | % -------------------------------------------------------- |
49 | 47 |
|
|
53 | 51 |
|
54 | 52 | % convolution of image with feature matrix for each channel |
55 | 53 | convolvedImage = zeros(imageDim - patchDim + 1, imageDim - patchDim + 1); |
56 | | - for channel = 1:3 |
| 54 | + for channel = 1:imageChannels |
57 | 55 |
|
58 | 56 | % Obtain the feature (patchDim x patchDim) needed during the convolution |
59 | 57 | % ---- YOUR CODE HERE ---- |
60 | | - feature = zeros(8,8); % You should replace this |
61 | | - |
62 | | - |
63 | | - |
| 58 | + feature = zeros(patchDim, patchDim); % You should replace |
| 59 | + % this |
| 60 | + first = patchDim * patchDim * (channel - 1) + 1; |
| 61 | + last = first + patchDim * patchDim - 1; |
| 62 | + feature = reshape(wt(featureNum, first:last), patchDim, patchDim); |
64 | 63 |
|
65 | 64 | % ------------------------ |
66 | 65 |
|
|
74 | 73 | % be sure to do a 'valid' convolution |
75 | 74 | % ---- YOUR CODE HERE ---- |
76 | 75 |
|
77 | | - |
78 | | - |
79 | | - |
| 76 | + convolvedImage = convolvedImage + conv2(im, feature, 'valid'); |
| 77 | + |
80 | 78 | % ------------------------ |
81 | 79 |
|
82 | 80 | end |
|
85 | 83 | % Then, apply the sigmoid function to get the hidden activation |
86 | 84 | % ---- YOUR CODE HERE ---- |
87 | 85 |
|
88 | | - |
89 | | - |
90 | | - |
| 86 | + convolvedImage = sigmoid(convolvedImage + bt(featureNum)); |
| 87 | + |
91 | 88 | % ------------------------ |
92 | 89 |
|
93 | 90 | % The convolved feature is the sum of the convolved values for all channels |
|
98 | 95 |
|
99 | 96 | end |
100 | 97 |
|
| 98 | +function sigm = sigmoid(x) |
| 99 | + sigm = 1 ./ (1 + exp(-x)); |
| 100 | +end |
0 commit comments