def center_crop(layer, max_height, max_width):
    """ Crops a given to a certain size by removing equal margins all around."""
    _, _, h, w = layer.size()
    xy1 = (w - max_width) // 2
    xy2 = (h - max_height) // 2
    return layer[:, :, xy2 : (xy2 + max_height), xy1 : (xy1 + max_width)]