import torch


def tensor2im(x: torch.Tensor, norm=False, dtype='float32'):
    """Convert tensor to image.

    Args:
        x(torch.Tensor): input tensor, [n, c, h, w] float32 type.
        norm(bool): if the tensor should be denormed first
        dtype(str): not used yet.

    Returns:
        an image in shape of [h, w, c].

    """
    if norm:
        x = (x + 1) / 2
    x[x > 1] = 1
    x[x < 0] = 0
    return x.detach().cpu().data[0]