0
0
TensorFlowml~10 mins

Feature map visualization in TensorFlow - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the TensorFlow library.

TensorFlow
import [1] as tf
Drag options to blanks, or click blank then click option'
Akeras
Btorch
Cnumpy
Dtensorflow
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'torch' instead of 'tensorflow' will import PyTorch, not TensorFlow.
Using 'numpy' or 'keras' alone won't give access to TensorFlow functions.
2fill in blank
medium

Complete the code to create a simple convolutional layer named 'conv_layer'.

TensorFlow
conv_layer = tf.keras.layers.Conv2D(filters=32, kernel_size=3, activation=[1])
Drag options to blanks, or click blank then click option'
A'relu'
B'sigmoid'
C'softmax'
D'tanh'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'softmax' activation in Conv2D is uncommon and usually for output layers.
Choosing 'sigmoid' or 'tanh' may slow down training for convolutional layers.
3fill in blank
hard

Fix the error in the code to get the output feature maps from the convolutional layer.

TensorFlow
feature_maps = conv_layer([1])
Drag options to blanks, or click blank then click option'
Ainput_image.numpy()
Binput_image.shape
Cinput_image
Dinput_image.data
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the shape or numpy array causes errors or unexpected behavior.
Using '.data' attribute is not valid for TensorFlow tensors.
4fill in blank
hard

Fill both blanks to plot the first 6 feature maps using matplotlib.

TensorFlow
import matplotlib.pyplot as plt
plt.figure(figsize=(12, 6))
for i in range([1]):
    plt.subplot(1, 6, i+1)
    plt.imshow(feature_maps[0, :, :, i], cmap=[2])
    plt.axis('off')
plt.show()
Drag options to blanks, or click blank then click option'
A6
B'gray'
C'viridis'
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using a range less than 6 will miss some feature maps.
Using color maps like 'viridis' may make features less clear.
5fill in blank
hard

Fill all three blanks to extract feature maps from a model layer named 'conv2d_1' for input 'img_tensor'.

TensorFlow
from tensorflow.keras.models import Model
layer_output = model.get_layer([1]).output
activation_model = Model(inputs=model.input, outputs=[2])
feature_maps = activation_model.predict([3])
Drag options to blanks, or click blank then click option'
A'conv2d_1'
Blayer_output
Cimg_tensor
D'conv2d_2'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong layer names causes errors.
Passing wrong inputs to predict causes runtime errors.