Bird
Raised Fist0
TensorFlowml~20 mins

Pooling layers (MaxPool, AvgPool) in TensorFlow - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Pooling Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output shape after MaxPooling2D layer
Given the following TensorFlow code, what is the shape of the output tensor after applying the MaxPooling2D layer?
TensorFlow
import tensorflow as tf
input_tensor = tf.random.uniform(shape=(1, 28, 28, 3))
max_pool = tf.keras.layers.MaxPooling2D(pool_size=(2, 2), strides=2)
output_tensor = max_pool(input_tensor)
output_shape = output_tensor.shape
A(1, 7, 7, 3)
B(1, 14, 14, 3)
C(1, 28, 28, 3)
D(1, 13, 13, 3)
Attempts:
2 left
💡 Hint
Remember that MaxPooling2D with pool_size (2,2) and stride 2 reduces each spatial dimension by half when padding is 'valid'.
🧠 Conceptual
intermediate
1:30remaining
Difference between MaxPooling and AveragePooling
Which statement correctly describes the difference between MaxPooling and AveragePooling layers in convolutional neural networks?
AMaxPooling selects the maximum value in each pooling window, while AveragePooling computes the average value in each pooling window.
BMaxPooling computes the average value in each pooling window, while AveragePooling selects the maximum value.
CBoth MaxPooling and AveragePooling select the minimum value in each pooling window.
DMaxPooling and AveragePooling both compute the sum of values in each pooling window.
Attempts:
2 left
💡 Hint
Think about how each pooling method summarizes the values in a small region.
❓ Hyperparameter
advanced
2:00remaining
Effect of stride on output size in pooling layers
If you apply a MaxPooling2D layer with pool_size=(3,3) and stride=1 on an input tensor of shape (1, 10, 10, 1) with padding='valid', what will be the spatial dimensions (height and width) of the output?
A(8, 8)
B(7, 7)
C(10, 10)
D(9, 9)
Attempts:
2 left
💡 Hint
Use the formula: output_size = (input_size - pool_size) / stride + 1
🔧 Debug
advanced
2:00remaining
Identifying error in pooling layer usage
What error will occur when running the following TensorFlow code snippet?
TensorFlow
import tensorflow as tf
input_tensor = tf.random.uniform(shape=(1, 28, 28, 3))
max_pool = tf.keras.layers.MaxPooling2D(pool_size=(2, 2), strides=3)
output_tensor = max_pool(input_tensor)
print(output_tensor.shape)
AValueError due to stride larger than input dimension
BNo error; output shape will be (1, 13, 13, 3)
CTypeError because strides must be a tuple, not an integer
DNo error; output shape will be (1, 9, 9, 3)
Attempts:
2 left
💡 Hint
Check if strides can be an integer and how output shape is computed.
❓ Model Choice
expert
2:30remaining
Choosing pooling layer for noise robustness
You want to build a convolutional neural network that is robust to small noisy activations in feature maps. Which pooling layer choice is best to reduce the effect of noise?
ANo pooling layer, to preserve all activations including noise
BMaxPooling, because it selects the strongest activation which may amplify noise
CAveragePooling, because it smooths activations and reduces noise impact
DGlobalMaxPooling, because it selects the maximum activation over the entire feature map
Attempts:
2 left
💡 Hint
Consider how each pooling method treats small noisy values.

Practice

(1/5)
1. What is the main purpose of a MaxPooling layer in a neural network?
easy
A. To reduce the size of the input while keeping the strongest features
B. To increase the size of the input by adding more pixels
C. To randomly change pixel values for data augmentation
D. To convert images into grayscale

Solution

  1. Step 1: Understand MaxPooling function

    MaxPooling scans small regions of the input and selects the maximum value, reducing size but keeping strong signals.
  2. Step 2: Compare options with MaxPooling role

    Only To reduce the size of the input while keeping the strongest features describes reducing size while keeping strongest features, matching MaxPooling's purpose.
  3. Final Answer:

    To reduce the size of the input while keeping the strongest features -> Option A
  4. Quick Check:

    MaxPooling = reduce size + keep max [OK]
Hint: MaxPooling keeps max values, shrinking input size [OK]
Common Mistakes:
  • Confusing MaxPooling with data augmentation
  • Thinking MaxPooling increases input size
  • Mixing MaxPooling with color conversion
2. Which of the following is the correct way to create a 2x2 MaxPooling layer with stride 2 in TensorFlow?
easy
A. tf.keras.layers.MaxPooling2D(pool_size=(2, 2), strides=2)
B. tf.keras.layers.MaxPooling2D(pool_size=2, stride=2)
C. tf.keras.layers.MaxPooling2D(pool=(2, 2), strides=(2, 2))
D. tf.keras.layers.MaxPooling2D(size=2, stride=2)

Solution

  1. Step 1: Recall correct TensorFlow MaxPooling2D syntax

    The correct parameters are pool_size and strides, both can be tuples or integers.
  2. Step 2: Check each option's parameter names and values

    tf.keras.layers.MaxPooling2D(pool_size=(2, 2), strides=2) uses pool_size=(2, 2) and strides=2, which is valid. Others use wrong parameter names or formats.
  3. Final Answer:

    tf.keras.layers.MaxPooling2D(pool_size=(2, 2), strides=2) -> Option A
  4. Quick Check:

    Correct params: pool_size, strides [OK]
Hint: Use pool_size and strides parameters exactly [OK]
Common Mistakes:
  • Using 'stride' instead of 'strides'
  • Using 'pool' or 'size' instead of 'pool_size'
  • Passing integers without tuple when tuple needed
3. Given the input tensor below, what is the output shape after applying a 2x2 MaxPooling layer with stride 2?
input_tensor = tf.constant([[[[1], [2], [3], [4]],
                             [[5], [6], [7], [8]],
                             [[9], [10], [11], [12]],
                             [[13], [14], [15], [16]]]], dtype=tf.float32)
medium
A. (1, 3, 3, 1)
B. (1, 4, 4, 1)
C. (1, 2, 2, 1)
D. (1, 1, 1, 1)

Solution

  1. Step 1: Understand input shape and pooling parameters

    Input shape is (1, 4, 4, 1). Pool size is 2x2, stride 2, so output spatial dims shrink by factor 2.
  2. Step 2: Calculate output shape after pooling

    Height and width: floor(4/2) = 2. Channels and batch size remain same. Output shape is (1, 2, 2, 1).
  3. Final Answer:

    (1, 2, 2, 1) -> Option C
  4. Quick Check:

    Pooling halves spatial dims = (1, 2, 2, 1) [OK]
Hint: Output dims = input dims divided by stride [OK]
Common Mistakes:
  • Forgetting batch and channel dimensions
  • Using input size instead of divided size
  • Confusing stride with pool size
4. You wrote this code but get an error:
layer = tf.keras.layers.AvgPooling2D(pool_size=2, strides=2)
output = layer(input_tensor)
What is the most likely cause of the error?
medium
A. input_tensor must be a numpy array, not a tensor
B. pool_size must be a tuple, not an integer
C. AvgPooling2D does not accept strides parameter
D. input_tensor is missing batch dimension

Solution

  1. Step 1: Check input_tensor shape requirements

    Pooling layers expect 4D input: (batch, height, width, channels). Missing batch dimension causes error.
  2. Step 2: Verify other options

    pool_size can be int or tuple, strides is accepted, and input can be tensor. So only missing batch dimension is likely cause.
  3. Final Answer:

    input_tensor is missing batch dimension -> Option D
  4. Quick Check:

    Pooling needs 4D input [OK]
Hint: Pooling layers require 4D input tensors [OK]
Common Mistakes:
  • Passing 3D tensor without batch size
  • Thinking strides parameter is invalid
  • Confusing tensor and numpy array input
5. You want to reduce noise in feature maps but keep important edges. Which pooling strategy should you use and why? MaxPooling or AveragePooling?
hard
A. Use MaxPooling because it keeps strongest signals like edges
B. Use AveragePooling because it smooths out noise by averaging
C. Use MaxPooling because it averages values to reduce noise
D. Use AveragePooling because it selects max values to keep edges

Solution

  1. Step 1: Understand effect of MaxPooling and AveragePooling

    MaxPooling keeps max values, emphasizing strong signals like edges but may keep noise spikes. AveragePooling smooths values, reducing noise.
  2. Step 2: Match goal with pooling type

    To reduce noise but keep edges, smoothing by AveragePooling is better. MaxPooling keeps edges but may keep noise.
  3. Final Answer:

    Use AveragePooling because it smooths out noise by averaging -> Option B
  4. Quick Check:

    Noise reduction = AveragePooling [OK]
Hint: AveragePooling smooths noise; MaxPooling keeps edges [OK]
Common Mistakes:
  • Confusing max with average effects
  • Thinking MaxPooling reduces noise
  • Mixing pooling effects on edges and noise
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard