Bird
Raised Fist0
TensorFlowml~20 mins

Feature map visualization in TensorFlow - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Feature Map Visualization Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output shape of feature maps after Conv2D layer
Given the following TensorFlow code snippet, what is the shape of the feature map output after the Conv2D layer?
TensorFlow
import tensorflow as tf
input_tensor = tf.random.uniform([1, 64, 64, 3])
conv_layer = tf.keras.layers.Conv2D(filters=16, kernel_size=3, strides=2, padding='same')
output = conv_layer(input_tensor)
output_shape = output.shape
print(output_shape)
A(1, 32, 32, 16)
B(1, 31, 31, 16)
C(1, 62, 62, 16)
D(1, 64, 64, 16)
Attempts:
2 left
💡 Hint
Remember that 'same' padding keeps the spatial dimensions divided by stride.
🧠 Conceptual
intermediate
1:30remaining
Purpose of feature map visualization in CNNs
What is the main purpose of visualizing feature maps in convolutional neural networks (CNNs)?
ATo increase the number of parameters in the model for better accuracy.
BTo reduce the size of the dataset before training the model.
CTo understand which parts of the input image activate certain filters and how the network processes features.
DTo convert the CNN into a fully connected network.
Attempts:
2 left
💡 Hint
Think about what feature maps represent in CNN layers.
❓ Metrics
advanced
1:30remaining
Interpreting activation values in feature maps
In feature map visualization, what does a higher activation value in a specific spatial location generally indicate?
AThe model is overfitting to the training data.
BThe filter strongly detects a feature at that location in the input.
CThe input image has low contrast in that region.
DThe filter is not learning any useful features.
Attempts:
2 left
💡 Hint
Activation values represent how much a filter responds to input features.
🔧 Debug
advanced
2:00remaining
Identifying error in feature map extraction code
What error will occur when running this TensorFlow code to extract feature maps from a model?
TensorFlow
import tensorflow as tf
model = tf.keras.applications.VGG16(weights=None, include_top=False)
input_image = tf.random.uniform([1, 224, 224, 3])
layer_outputs = [layer.output for layer in model.layers if 'conv' in layer.name]
feature_map_model = tf.keras.Model(inputs=model.input, outputs=layer_outputs)
feature_maps = feature_map_model(input_image)
print(len(feature_maps))
ATypeError because layer.output is not a tensor.
BRuntimeError because the model was created without weights.
CValueError because model.layers contains layers without 'name' attribute.
DNo error; prints the number of convolutional layers.
Attempts:
2 left
💡 Hint
Check if all layers have a 'name' attribute and output tensor.
❓ Model Choice
expert
2:30remaining
Best model type for detailed feature map visualization
Which model architecture is best suited for detailed feature map visualization to understand hierarchical feature extraction?
AA deep convolutional neural network with multiple convolutional and pooling layers.
BA recurrent neural network designed for sequence data.
CA simple logistic regression model with no hidden layers.
DA decision tree classifier with no convolutional layers.
Attempts:
2 left
💡 Hint
Consider which model type uses convolutional layers producing feature maps.

Practice

(1/5)
1. What is the main purpose of visualizing feature maps in a convolutional neural network (CNN)?
easy
A. To reduce the size of the input images
B. To understand what patterns or features the CNN layers detect in the input image
C. To increase the training speed of the CNN model
D. To change the activation function of the CNN layers

Solution

  1. Step 1: Understand feature maps in CNNs

    Feature maps are outputs of convolutional layers showing detected features like edges or textures.
  2. Step 2: Purpose of visualization

    Visualizing feature maps helps us see what the CNN focuses on in the image, improving model interpretability.
  3. Final Answer:

    To understand what patterns or features the CNN layers detect in the input image -> Option B
  4. Quick Check:

    Feature map visualization = Understand CNN features [OK]
Hint: Feature maps show what CNN 'sees' in images [OK]
Common Mistakes:
  • Thinking visualization speeds up training
  • Confusing feature maps with input resizing
  • Believing visualization changes activation functions
2. Which TensorFlow code snippet correctly creates a model to output feature maps from the first convolutional layer named 'conv1'?
easy
A. feature_map_model = tf.keras.Model(inputs=model.get_layer('conv1').input, outputs=model.input)
B. feature_map_model = tf.keras.Sequential(model.get_layer('conv1'))
C. feature_map_model = tf.keras.Model(inputs=model.input, outputs=model.get_layer('conv1').output)
D. feature_map_model = tf.keras.Model(inputs=model.output, outputs=model.get_layer('conv1').input)

Solution

  1. Step 1: Identify correct Model creation syntax

    To get intermediate outputs, create a new Model with original inputs and desired layer outputs.
  2. Step 2: Check each option

    feature_map_model = tf.keras.Model(inputs=model.input, outputs=model.get_layer('conv1').output) correctly uses model.input and conv1 output. Others misuse inputs/outputs or use Sequential incorrectly.
  3. Final Answer:

    feature_map_model = tf.keras.Model(inputs=model.input, outputs=model.get_layer('conv1').output) -> Option C
  4. Quick Check:

    New model inputs = original inputs, outputs = layer output [OK]
Hint: Use original inputs and layer output to create feature map model [OK]
Common Mistakes:
  • Using model.output as input
  • Passing layer input as output
  • Using Sequential instead of Model for intermediate outputs
3. Given the code below, what is the shape of feature_maps if the input image shape is (1, 64, 64, 3) and the 'conv1' layer outputs 32 filters of size 62x62?

feature_map_model = tf.keras.Model(inputs=model.input, outputs=model.get_layer('conv1').output)
feature_maps = feature_map_model.predict(input_image)
medium
A. (62, 62, 32)
B. (32, 62, 62)
C. (1, 64, 64, 3)
D. (1, 62, 62, 32)

Solution

  1. Step 1: Understand input and output shapes

    Input batch size is 1, image size 64x64 with 3 channels. conv1 outputs 32 filters of size 62x62.
  2. Step 2: Predict output shape

    Output shape includes batch size, height, width, and number of filters: (1, 62, 62, 32).
  3. Final Answer:

    (1, 62, 62, 32) -> Option D
  4. Quick Check:

    Output shape = (batch, height, width, filters) [OK]
Hint: Feature map shape includes batch and filter count [OK]
Common Mistakes:
  • Ignoring batch dimension
  • Confusing input shape with output shape
  • Mixing filter count with spatial dimensions
4. You wrote this code to visualize feature maps but get an error:

feature_map_model = tf.keras.Model(inputs=model.input, outputs=model.get_layer('conv1').output)
feature_maps = feature_map_model.predict(input_image)
plt.imshow(feature_maps)

What is the likely cause of the error?
medium
A. Trying to plot a 4D tensor directly with plt.imshow
B. Using the wrong layer name in get_layer
C. Input image shape is incompatible with the model
D. Missing import for matplotlib.pyplot

Solution

  1. Step 1: Analyze the error cause

    feature_maps is a 4D array (batch, height, width, filters), but plt.imshow expects 2D or 3D image data.
  2. Step 2: Correct visualization approach

    You must select one feature map (e.g., feature_maps[0, :, :, 0]) before plotting with plt.imshow.
  3. Final Answer:

    Trying to plot a 4D tensor directly with plt.imshow -> Option A
  4. Quick Check:

    Plot single 2D feature map slice, not full 4D tensor [OK]
Hint: Plot one 2D feature map slice, not whole 4D tensor [OK]
Common Mistakes:
  • Plotting entire feature_maps array directly
  • Ignoring batch dimension when plotting
  • Assuming get_layer error without checking data shape
5. You want to visualize feature maps from multiple convolutional layers ('conv1', 'conv2', 'conv3') in a TensorFlow model. Which approach correctly creates a model to output all these feature maps at once?
hard
A. feature_map_model = tf.keras.Model(inputs=model.input, outputs=[model.get_layer(name).output for name in ['conv1', 'conv2', 'conv3']])
B. feature_map_model = tf.keras.Sequential([model.get_layer('conv1'), model.get_layer('conv2'), model.get_layer('conv3')])
C. feature_map_model = tf.keras.Model(inputs=model.output, outputs=model.get_layer('conv3').output)
D. feature_map_model = tf.keras.Model(inputs=model.input, outputs=model.get_layer('conv3').input)

Solution

  1. Step 1: Understand multi-output model creation

    To get outputs from multiple layers, pass a list of their outputs to the Model constructor.
  2. Step 2: Evaluate options

    feature_map_model = tf.keras.Model(inputs=model.input, outputs=[model.get_layer(name).output for name in ['conv1', 'conv2', 'conv3']]) correctly creates a model with inputs as original inputs and outputs as a list of layer outputs. Others misuse Sequential or inputs/outputs.
  3. Final Answer:

    feature_map_model = tf.keras.Model(inputs=model.input, outputs=[model.get_layer(name).output for name in ['conv1', 'conv2', 'conv3']]) -> Option A
  4. Quick Check:

    Use list of outputs for multiple feature maps [OK]
Hint: Use list of layer outputs in Model to get multiple feature maps [OK]
Common Mistakes:
  • Using Sequential instead of Model for intermediate outputs
  • Passing model.output as inputs
  • Using layer inputs as outputs
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