@tom Thank you for your reply!
If anyone else finds it useful, below is a function that implements what Thomas suggested in a more general way. It behaves the same way the original did (compared using a dataset of 480 x 640 images) AFAIK.
def fastCreateFeatureMap(masks, num_x_windows = 48, num_y_windows = 64):
    window_size_x = int(masks.size(0)/num_x_windows)
    window_size_y = int(masks.size(1)/num_y_windows)
    windows = masks.view(num_x_windows, window_size_x, num_y_windows, window_size_y).permute(0, 2, 1, 3).reshape(num_y_windows *num_x_windows , window_size_y * window_size_x)
    processed_windows = torch.mode(windows,dim=-1)[0]
    return processed_windows.reshape(num_x_windows,num_y_windows)