Nekochu's picture
Manifest v2: 8-bit default, 4-bit option, tiled decoder; card-size measurements in README
752dc7d verified
Raw History Blame Contribute Delete
505 Bytes
"""Decode saved latents with the PyTorch dinac3 decoder (fp32): decode.py LATENT.npy OUT.png"""
import sys
import numpy as np, torch
from PIL import Image
import dfl
torch.set_num_threads(4)
vae = dfl.load_vae()
x = torch.from_numpy(np.load(sys.argv[1])).float()
with torch.no_grad():
rgb = vae.decode(x, x.shape[2] * 16, x.shape[3] * 16).clamp(-1, 1)
Image.fromarray(((rgb[0].permute(1, 2, 0).numpy() + 1) * 127.5).round().clip(0, 255).astype(np.uint8)).save(sys.argv[2])
print("saved", sys.argv[2])