Feature Map Visualization
Feature map visualization is a technique for inspecting what a CNN has learned by upscaling the activation maps (feature maps) produced by convolutional layers. This is done using **nearest-neighbor interpolation**, where each pixel in the original feature map is replicated to fill a larger region in the output, creating a blocky upscaled version.
Algorithm (Nearest-Neighbor Upscaling by factor k):
For each element input[i, j]:
output[i*k : (i+1)*k, j*k : (j+1)*k] = input[i, j]
Output dimensions:
output_height = input_height * k
output_width = input_width * k
Example:
Input (3x3), scale factor = 3:
[[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
Output (9x9):
[[1,1,1, 2,2,2, 3,3,3],
[1,1,1, 2,2,2, 3,3,3],
[1,1,1, 2,2,2, 3,3,3],
[4,4,4, 5,5,5, 6,6,6],
[4,4,4, 5,5,5, 6,6,6],
[4,4,4, 5,5,5, 6,6,6],
[7,7,7, 8,8,8, 9,9,9],
[7,7,7, 8,8,8, 9,9,9],
[7,7,7, 8,8,8, 9,9,9]]
Visualizing feature maps helps understand which spatial regions and patterns activate different filters in the network. Early layers typically detect edges and textures, while deeper layers capture more abstract and complex patterns.
Constraints:
Test Cases
[[1,2,3],[4,5,6],[7,8,9]][[1,1,1,2,2,2,3,3,3],[1,1,1,2,2,2,3,3,3],[1,1,1,2,2,2,3,3,3],[4,4,4,5,5,5,6,6,6],[4,4,4,5,5,5,6,6,6],[4,4,4,5,5,5,6,6,6],[7,7,7,8,8,8,9,9,9],[7,7,7,8,8,8,9,9,9],[7,7,7,8,8,8,9,9,9]][[0,1,0],[1,0,1],[0,1,0]][[0,0,0,1,1,1,0,0,0],[0,0,0,1,1,1,0,0,0],[0,0,0,1,1,1,0,0,0],[1,1,1,0,0,0,1,1,1],[1,1,1,0,0,0,1,1,1],[1,1,1,0,0,0,1,1,1],[0,0,0,1,1,1,0,0,0],[0,0,0,1,1,1,0,0,0],[0,0,0,1,1,1,0,0,0]]