0
0
TensorFlowml~20 mins

Convolution operation concept in TensorFlow - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Convolution Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What does a convolution operation do in a CNN?

Imagine you have a photo and you want to find edges or patterns in it. What does the convolution operation do in this context?

AIt randomly changes pixel values to create new images.
BIt multiplies the image by a filter to highlight specific features like edges or textures.
CIt compresses the image into a smaller size without losing any information.
DIt converts the image into text data for easier processing.
Attempts:
2 left
💡 Hint

Think about how a filter moves over an image to detect patterns.

Predict Output
intermediate
2:00remaining
Output shape after convolution

Given a 28x28 grayscale image input and a convolutional layer with 16 filters, kernel size 3x3, stride 1, and 'valid' padding, what is the output shape?

TensorFlow
import tensorflow as tf
input_tensor = tf.random.uniform([1, 28, 28, 1])
conv_layer = tf.keras.layers.Conv2D(filters=16, kernel_size=3, strides=1, padding='valid')
output = conv_layer(input_tensor)
print(output.shape)
A(1, 27, 27, 16)
B(1, 28, 28, 16)
C(1, 25, 25, 16)
D(1, 26, 26, 16)
Attempts:
2 left
💡 Hint

Use the formula: output_size = input_size - kernel_size + 1 when padding is 'valid'.

Hyperparameter
advanced
2:00remaining
Effect of stride on convolution output size

If you increase the stride from 1 to 2 in a convolutional layer, what happens to the output feature map size?

AThe output size becomes smaller because the filter moves more pixels at a time.
BThe output size becomes unpredictable and random.
CThe output size stays the same because stride does not affect size.
DThe output size becomes larger because the filter covers more area.
Attempts:
2 left
💡 Hint

Think about how skipping pixels affects the number of positions the filter can be applied.

Metrics
advanced
2:00remaining
Calculating number of parameters in a Conv2D layer

How many trainable parameters are there in a Conv2D layer with 32 filters, kernel size 3x3, and input channels 3?

A864
B288
C896
D320
Attempts:
2 left
💡 Hint

Use the formula: (kernel_height * kernel_width * input_channels + 1) * number_of_filters.

🔧 Debug
expert
3:00remaining
Why does this convolution code raise an error?

Consider this TensorFlow code snippet:

import tensorflow as tf
input_tensor = tf.random.uniform([1, 28, 28, 1])
conv_layer = tf.keras.layers.Conv2D(filters=16, kernel_size=3, strides=1, padding='same')
output = conv_layer(input_tensor[0])
print(output.shape)

Why does this code raise an error?

ABecause input_tensor[0] removes the batch dimension, causing shape mismatch.
BBecause kernel_size must be an odd number greater than 3.
CBecause padding='same' is not supported in Conv2D.
DBecause filters must be equal to input channels.
Attempts:
2 left
💡 Hint

Check the shape of input_tensor[0] compared to what Conv2D expects.