Click4Ai

119.

Medium

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:

  • Input feature map is a 3x3 2D numpy array
  • Output feature map is a 9x9 2D array (scale factor = 3)
  • Each original value is replicated in a 3x3 block in the output
  • Values can be any real number
  • Test Cases

    Test Case 1
    Input: [[1,2,3],[4,5,6],[7,8,9]]
    Expected: [[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]]
    Test Case 2
    Input: [[0,1,0],[1,0,1],[0,1,0]]
    Expected: [[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]]
    + 3 hidden test cases