import torch


def pad_tensor(img, target_size):
    """Pad an tensor up to the target size.
    :param img: (N, C, H, W)
    :param target_size: (H, W)
    :returns padded_img: (N, C, target_size[0], target_size[1])
    """
    (N, C, H, W) = img.size()
    (t_H, t_W) = target_size

    padded_img = torch.zeros(N, C, t_H, t_W)
    padded_img[:, :, :H, :W] = img

    return padded_img