0
0
PyTorchml~10 mins

Feature map visualization in PyTorch - 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 PyTorch library.

PyTorch
import [1]
Drag options to blanks, or click blank then click option'
Atorch
Btensorflow
Cnumpy
Dmatplotlib
Attempts:
3 left
💡 Hint
Common Mistakes
Importing TensorFlow instead of PyTorch.
Importing numpy or matplotlib which are not PyTorch.
2fill in blank
medium

Complete the code to create a simple convolutional layer in PyTorch.

PyTorch
conv_layer = torch.nn.Conv2d(in_channels=1, out_channels=6, kernel_size=[1])
Drag options to blanks, or click blank then click option'
A7
B3
C1
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using kernel size 1 which is too small for feature extraction.
Using kernel size 3 or 7 which are valid but not the intended answer.
3fill in blank
hard

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

PyTorch
feature_maps = output.[1]()
Drag options to blanks, or click blank then click option'
Adetach
Bnumpy
Ctolist
Dcpu
Attempts:
3 left
💡 Hint
Common Mistakes
Using numpy() directly without detaching causes errors.
Using tolist() which is not suitable for tensor operations.
4fill in blank
hard

Fill both blanks to convert the feature maps to a NumPy array and select the first channel for visualization.

PyTorch
feature_maps_np = feature_maps.[1]().[2][0]
Drag options to blanks, or click blank then click option'
Acpu
Bnumpy
Cdetach
Dtolist
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to convert tensor on GPU directly to NumPy causes errors.
Using tolist() instead of numpy().
5fill in blank
hard

Fill all three blanks to plot the first feature map using matplotlib.

PyTorch
import matplotlib.pyplot as plt
plt.imshow(feature_maps_np[1][2]) 
plt.[3]()
Drag options to blanks, or click blank then click option'
A[0]
B.squeeze()
Cshow
Dplot
Attempts:
3 left
💡 Hint
Common Mistakes
Using plot() instead of show() to display the image.
Not squeezing the tensor before plotting causes shape errors.