import torch


def maxpool_2d(image, f=2, s=2):
    """
    Downsample 'image' using kernel size 'f' and stride 's'
    """
    N, C, Hin, Win = image.size()
    
    Hout = int((Hin - f)/s + 1)
    Wout = int((Win - f)/s + 1)
    
    out = torch.zeros(N, C, Hout, Wout)
    for b in range(N):
        for c in range(C):
            curr_y = out_y = 0
            while curr_y + f <= Hin:
                curr_x = out_x = 0
                while curr_x + f <= Win:
                    out[b, c, out_y, out_x] = torch.max(image[b, c, curr_y:curr_y+f, curr_x:curr_x+f])
                    curr_x += s
                    out_x += 1
                curr_y += s
                out_y += 1
    return out