Premium problem68. Global Average Pooling

Easy Locked

Turn x of shape (B, C, H, W) into (B, C) by averaging each channel over its spatial dimensions. No Python loops.

Input

tensor([[[[ 0.,  1.],
          [ 2.,  3.]],

         ...,

         [[ 8.,  9.],
          [10., 11.]]],


        [[[12., 13.],
          [14., 15.]],

         ...,

         [[20., 21.],
          [22., 23.]]]])

Output

tensor([[ 1.5000,  5.5000,  9.5000],
        [13.5000, 17.5000, 21.5000]])

Premium problem

This one's part of Premium. Unlock the full PyTorch track plus every other premium problem on the site.

Implement solve(...)