Loading problem...
In modern convolutional neural networks, spatial channel aggregation is a crucial dimension reduction technique that transforms multi-dimensional feature maps into compact, channel-wise representations. This operation computes the arithmetic mean of all spatial positions within each feature channel, effectively summarizing the spatial information into a single value per channel.
Given a 3D tensor X of shape (H, W, C) where:
The spatial channel aggregation produces a 1D output vector y of length C, where each element yₖ is computed as:
$$y_k = \frac{1}{H \times W} \sum_{i=1}^{H} \sum_{j=1}^{W} X_{i,j,k}$$
This means for each channel k, we sum all H × W spatial values and divide by the total number of spatial positions to obtain the average.
Key Properties:
Your Task: Write a Python function that performs spatial channel aggregation on a 3D feature map. The function should:
x = [[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]], [[7.0, 8.0, 9.0], [10.0, 11.0, 12.0]]][5.5, 6.5, 7.5]The input is a 2×2×3 tensor (height=2, width=2, channels=3).
Channel 0: Values are [1.0, 4.0, 7.0, 10.0] Average = (1.0 + 4.0 + 7.0 + 10.0) / 4 = 22.0 / 4 = 5.5
Channel 1: Values are [2.0, 5.0, 8.0, 11.0] Average = (2.0 + 5.0 + 8.0 + 11.0) / 4 = 26.0 / 4 = 6.5
Channel 2: Values are [3.0, 6.0, 9.0, 12.0] Average = (3.0 + 6.0 + 9.0 + 12.0) / 4 = 30.0 / 4 = 7.5
The output is the 1D vector [5.5, 6.5, 7.5].
x = [[[1.0, 2.0], [3.0, 4.0]], [[5.0, 6.0], [7.0, 8.0]]][4.0, 5.0]The input is a 2×2×2 tensor (height=2, width=2, channels=2).
Channel 0: Values are [1.0, 3.0, 5.0, 7.0] Average = (1.0 + 3.0 + 5.0 + 7.0) / 4 = 16.0 / 4 = 4.0
Channel 1: Values are [2.0, 4.0, 6.0, 8.0] Average = (2.0 + 4.0 + 6.0 + 8.0) / 4 = 20.0 / 4 = 5.0
The output is [4.0, 5.0].
x = [[[10.0], [20.0]], [[30.0], [40.0]]][25.0]The input is a 2×2×1 tensor (height=2, width=2, channels=1).
Channel 0: All spatial values are [10.0, 20.0, 30.0, 40.0] Average = (10.0 + 20.0 + 30.0 + 40.0) / 4 = 100.0 / 4 = 25.0
With only one channel, the output is a single-element list [25.0].
Constraints