examples/research_projects/vqgan-clip/img_processing.py/custom_to_pil
def custom_to_pil(x, process=True, mode="RGB"):
    x = x.detach().cpu()
    if process:
        x = post_process_tensor(x)
    x = x.numpy()
    if process:
        x = (255 * x).astype(np.uint8)
    x = Image.fromarray(x)
    if not x.mode == mode:
        x = x.convert(mode)
    return x