You are on page 1of 6

The advantage of data padding is that _____________.

- It prevents data dimension from going too small (Correct)

If data is of dimension 16 x 16, filter 2x 2, padding 2, and stride 2, then the


output dimension after convolution is given by _____________.
- 8 x 8 (Correct)

If the data input for CNN is of shape m x nh x nw x c then dimension m represents


the number of samples.
- True (Correct)

Which of these could be the additional advantage of data padding apart from
dimensionality reduction?
- Learns more features from image corners (Correct)

On performing strided convolution on an image of dimension 20 x 20 x 1 with filter


size 4x4 and stride = 1, what would be the output dimension after convolution?
- 17 x 17 x 1 (Correct)

On performing strided convolution on an image of dimension 20 x 20 x 1 with filter


size 4x4 and stride = 2 what would be the output dimension after convolution?
- 9 x 9 x 1 (Correct)

The limitation of training a fully connected neural network instead of CNN for
image recognition is _________________.
- All the options (Correct)

What would be the number of feature vectors if the convolution is performed on an


image of 3 channels by a filter of 6 channels?
- 6 (Correct)

If data is of dimension n x n, filter f x f, padding p, and stride s, then the


output dimension after convolution is given by ________.
- $\small(\frac{n - f + 2p}{s} + 1)$ (Correct)

If the data dimension is 16 x 16, filter 5x5, and stride 1, then what is the amount
of padding required so that convolution output has the same dimension as the input?
- 2 (Correct)

The purpose of 1x1 convolution in inception network is ____________.


- Reduce the dimension of feature vector (Correct)

A residual neural network reduces ___________ problem.


- Vanishing gradient (Correct)

The size of each filter should always be equal t the dimension of the receptive
field.
- True (Correct)

If feature vector is of the dimension n x n, pooling filter f x f, padding p, and


stride s, then the output dimension after pooling is given by ____________.
- $\small(\frac{n - f + 2p}{s} + 1)$(Correct)

Which of the following is the advantage of pooling?


- All the options (Correct)

Which of the following network has the least number of parameters to learn?
- LeNet (Correct)
The pixel intensity of the grayscale image varies between ___________.
- 0 to 255 (Correct)

The output after convolution operation is known as __________.


- Feature vector (Correct)

What would be the number of feature vectors if the convolution is performed on the
image of 3 channels by a filter of 6 channels?
- 6 (Correct)

Which of the following network has least number of parameters to learn


- LeNet (Correct)

if feature vector is of dimension n x n and pooling filter f x f , padding p, and


stride s then output dimension after pooling is given by
- $\small(\frac{n - f + 2p}{s} + 1)$ (Correct)

If the data is of dimension n x n, filter f x f, padding p, stride s, then the


output dimension after convolution is given by _________.
- $\small(\frac{n - f + 2p}{s} + 1)$ (Correct)

residual neural network reduce which of the following problem


- Vanishing gradient (Correct)

The size of each filter should always be equal to the dimension of the receptive
field.
- True (Correct)

Which of these could be the additional advantage of data padding apart from
reducing dimensionality reduction?
- Learns more features from image corners (Correct)

The pooling filter has no weights to learn


- True (Correct)

On which of the following input data dimension was the AlexNet trained?
- 227 x 227 x 3 (Correct)

Which of the following architecture uses multiple filters of different dimensions


in the same convolution layer?
- InceptionNet (Correct)

The local region of the input data over which convolution is performed is known as
___________.
- Receptive field (Correct)

The size of the input data diminishes as it passes through the CNN layers.
- True (Correct)

On performing strided convolution on an image of dimension 20 x 20 x 1 with filter


size 4x4 and stride 2, what would be the output dimension after convolution?
- 9 x 9 x 1 (Correct)

The trade-off for increasing pooling filter size is ______________.


- Losing important features (Correct)

On performing strided convolution on an image of dimension 20 x 20 x 1 with filter


size 4x4 and stride 1, what would be the output dimension after convolution?
- 15 x 15 x 1 (Correct)
If the data dimension is n x n, filter fxf, and stride s 1, then what is the amount
of padding required so that convolution output has the same dimension as the input?
- $\small\frac{f-1}{2}$ (Correct)

If data is of the dimension 16 x 16, filter 2x 2, padding 2, stride 2, then the


output dimension after convolution is given by _________.
- 8 x 8 (Correct)

===================================================================================
=====================
===================================================================================
=====================

#HandsOn#

Convolution using NumPy

img = mpimg.imread("home.png")
data = img.reshape(1,img.shape[0], img.shape[1], img.shape[2])

def zero_pad(data, pad):


###Start code here
data_padded = np.pad(array = data, pad_width = ((0,0),(pad,pad), (pad,pad),
(0,0)), mode = 'constant', constant_values = 0)
return data_padded
###End code

def conv_single_step(data_slice, W, b):


###Start code
conv = np.multiply(data_slice, W)
Z = np.sum(conv) + b
###End code
return Z

def conv_forward(A_prev, W, b, hparams):


stride = hparams["stride"]
pad = hparams["pad"]
m, h_prev, w_prev, c_prev = A_prev.shape
f, f, c_prev, n_c = W.shape
n_h = int((h_prev - f + 2*pad)/stride) + 1
n_w = int((w_prev - f + 2*pad)/stride) + 1
Z = np.zeros((m, n_h, n_w, n_c))
A_prev_pad = zero_pad(A_prev, pad)
for i in range(m):
for h in range(n_h):
for w in range(n_w):
for c in range(n_c):
w_start = w * stride
w_end = w_start + f
h_start = h * stride
h_end = h_start + f
Z[i,h,w,c] = conv_single_step(A_prev_pad[i, h_start:h_end,
w_start:w_end, :], W[:,:,:,c], b[:,:,:,c])
return Z

hparams = {"pad" : 0, "stride": 1}


b = np.zeros((1, 1, 1, 1))
Z = conv_forward(data, edge_detect, b, hparams)

def max_pool(input, hparam):


###start code
m, h_prev, w_prev, c_prev = input.shape
f = hparam["f"] ## f is the filter size to use for pooling
stride = hparam["stride"]
h_out = int(((h_prev - f)/stride) + 1)
w_out = int(((w_prev -f)/stride) + 1)
output = np.zeros((m, h_out, w_out, c_prev))
for i in range(m):
for c in range(c_prev):
for h in range(h_out):
for w in range(w_out):
w_start = w * stride
w_end = w_start + f
h_start = h * stride
h_end = h_start + f
output[i, h, w, c] = np.max(input[i,h_start:h_end,
w_start:w_end, c])
print(output.shape)
assert output.shape == (m, h_out, w_out, c_prev)
###End code
return output

###start code
hparams = {'stride':1, 'f':2}
Z_pool = max_pool(input_, hparams)
###End code

===================================================================================
======================

Convolution Using TensorFlow

###Start code here


img = mpimg.imread("bird.png")
data = img.reshape(1,img.shape[0], img.shape[1], img.shape[2])
###End code

graph = tf.Graph()
with graph.as_default():
tf.random.set_seed(1)
tinput_= tf.constant(data.astype(np.float32)) ##The input data is coverted
into tensor of type float32
###Start code here
W = tf.Variable(tf.random.normal([5,5,3,32]))
b = tf.Variable(tf.random.normal([32]))

conv = tf.nn.conv2d(tinput_,filters=W, strides=[1, 1, 1, 1], padding='SAME') +


b
conv_bias = tf.nn.bias_add(conv, b)
conv_out = tf.nn.relu(conv_bias)
conv_pool = tf.nn.pool(input = conv_out , window_shape = [3,3],
padding="VALID", pooling_type="MAX")
###ENd code

You might also like