First time here? Checkout the FAQ!
x
+5 votes
5.4k views
asked in Deep Learning by (115k points)  
reshown by

Assume we have a $5\times5$ px RGB image with 3 channels respectively for R, G, and B. If

R
2 0 0 0 0
1 2 0 0 1
2 0 1 0 2
1 2 1 0 1
0 1 0 2 0
G
0 2 1 2 2
1 1 1 0 0
0 0 2 2 0
2 0 0 2 0
0 2 1 1 1
B
0 1 0 0 1
1 1 2 0 1
1 0 2 0 2
1 0 1 1 0
1 2 1 1 2

 

We have one $3\times3$ px kernel (filter) with 3 channels as follows:

Filter - R
0 0 1
1 0 1
1 0 0
Filter - G
0 0 -1
1 0 0
1 -1 0
Filter - B
1 0 1
0 1 -1
1 -1 0

 

a) If Stride = 2, and Zero-padding = 1, and Bias = 1, what will be the result of convolution?

b) What is the result after applying a ReLU layer ($max(z,0)$)on the result with the same size of the reuslt in part a?

c) Calculate the output by applying max-pooling layer with the size of $2\times2$ on the output of part b, and Stride = 1. (hint: max-pooling layer here and usually do not include any zero-paddings)

d) What is the result after applying flatten on the output of part c and creating a vector?

e) Assume the vector you created contains m elements. Consider it as the input vector for a Softmax Regression classifier (without any hidden layers and biases and it is fully connected). Assume there are 2 classes of 0 and 1. For all the weights from each element in the feature vector, the optimized weights are 1 for odd elements and 2 for even elements. For example, if the feature vector is [10,11,12,13,14], all the weights from 10 are 1 (because 10 is element 1 and 1 is odd), all the weights from 11 are 2, all the weights from 12 are 1, all the weights from 13 are 2 and all the weights from 14 are 1 and so on. Draw the Softmax Regression network and calculate the class should be 0 or 1?

Hint: 
Softmax Regression: $p_{i}=\frac{e^{z_{i}}}{\sum_{i=1}^{c} e^{z_{i}}}$
Where $p_{i}$ is the probability of class $i$ anc $c$ is the number of classes.

  
commented by (160 points)  
+1
G filter and B channel values of the image are not matching in the question and the solution.
commented by (115k points)  
Fixed. Thanks

1 Answer

0 votes
answered by (115k points)  
 
Best answer

Answers:

a)
The result is shown in the figure below. For an alternative question, when we have two $3\times3$ RGB kernels please take a look at Convolution Demo section of this page. The result is the Green matrix.

b) The result of part (a) is shown in the above image in Green matrix. The ReLU layer makes the negative elements 0, and do not change the rest of the elements. Therefore, the result is as follows:

ReLU of result
0 4 3
1 5 8
3 5 7

c) The result of max-pulling on ReLU with Stride = 1:

Max-pooling of ReLU
5 8
5 8

 

d) Flatten technique is shown in the figure below. Therefore, the result feature vector is $[5,8,5,8]$

e) The Softmax Regression network is shown in figure below. If you calculate the probabilities of class 0 and 1, both are 50%. Therefore, it could be both class 0 and class 1 with the same probability.

commented by (115k points)  
This is a wrong calculation. There are 2 possible reasons for it:
1) You did not Stride vertically or horizontally correctly
2) You forgot the bias
commented by (100 points)  
B-out should be [-2 -1 0] [1 0 3] [-1 1 3]  (instead of [1 2 3])
commented by (140 points)  
+1
there is some differences between the given data and the solved data the second filter (3,1) is zero instead of 1. and the number of the original data before padding (3,4) element is 2 instead of zero
commented by (280 points)  
reshown by
edit: just saw EH said the same thing

it is because the solution solved RGB matrices and filters that aren't exactly the same. The B matrix has a 0 instead of a 2 in the 4th column, 3rd row, and the G filter has a 1 instead of a 0 in the 1st column, 3rd row.
commented by (100 points)  
for part a I am getting below results fo rconcolved features:
R: 0 2 0 , 2 2 0, 3 3 2
G: -1 2 2 , -3 0 4 , 0 0 1
B: -2 -2 0, 1 2 2 , -1 1 3
How do we consider the bias for this section?

Related questions

...