Complete the code to import the TensorFlow library.
import [1] as tf
We use import tensorflow as tf to access TensorFlow functions easily.
Complete the code to create a simple convolutional layer named 'conv_layer'.
conv_layer = tf.keras.layers.Conv2D(filters=32, kernel_size=3, activation=[1])
The 'relu' activation is commonly used in convolutional layers for feature extraction.
Fix the error in the code to get the output feature maps from the convolutional layer.
feature_maps = conv_layer([1])We pass the actual input tensor input_image to the layer to get feature maps.
Fill both blanks to plot the first 6 feature maps using matplotlib.
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()
We plot 6 feature maps and use 'gray' colormap for clear visualization.
Fill all three blanks to extract feature maps from a model layer named 'conv2d_1' for input 'img_tensor'.
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])
We get the output of 'conv2d_1' layer, create a model for activations, and predict on 'img_tensor'.