import torch


def denormalize(tensor, mean, std):
    """Denormalize the image for given mean and standard deviation.

    Args:
        tensor: Image tensor
        mean: Dataset mean
        std: Dataset standard deviation

    Returns:
        tensor

    Raises:
        No Exception
    """
    if not tensor.ndimension() == 4:
        raise TypeError('tensor should be 4D')

    mean = torch.FloatTensor(mean).view(1, 3, 1, 1).expand_as(tensor).to(tensor.device)
    std = torch.FloatTensor(std).view(1, 3, 1, 1).expand_as(tensor).to(tensor.device)

    return tensor.mul(std).add(mean)