def img_denorm(img,
               mean=(0.485, 0.456, 0.406),
               std=(0.229, 0.224, 0.225),
               to_pil=True):
    """ De-normalization

    Args:
        img (torch.Tensor): 4D normalized image tensor (N, C, H, W)
        mean (iterable): normalized mean values.
        std (iterable): normalized std values.
        to_pil (bool): if convert to PIL format before normalization.

    Returns:
        img (torch.Tensor): raw image tensor.

    """
    for i, (m, s) in enumerate(zip(mean, std)):
        img[:, i, :, :].mul_(s).add_(m)
    if to_pil:
        img = img[:, [2, 1, 0], :, :].contiguous()
        img.mul_(255.0)
    return img