examples/pytorch/semantic-segmentation/run_semantic_segmentation.py/pad_if_smaller
def pad_if_smaller(img, size, fill=0):
    size = (size, size) if isinstance(size, int) else size
    original_width, original_height = img.size
    pad_height = size[1] - original_height if original_height < size[1] else 0
    pad_width = size[0] - original_width if original_width < size[0] else 0
    img = functional.pad(img, (0, 0, pad_width, pad_height), fill=fill)
    return img