def torch2numpy(img):
    """
    Converts a torch image to numpy format
    """
    if img.dim() == 4:
        img = img.permute(0, 2, 3, 1).contiguous()
    elif img.dim() == 3:
        img = img.permute(1, 2, 0).contiguous()
    return img.cpu().numpy()