NISHIO Hirokazu[Translate]
Stable Diffusion Latent Space Visualization
last latent
output
input
init_latents


py
def image_grid(imgs, rows, cols): assert len(imgs) == rows*cols w, h = imgs[0].size grid = PIL.Image.new('L', size=(cols*w, rows*h)) grid_w, grid_h = grid.size for i, img in enumerate(imgs): grid.paste(img, box=(i%cols*w, i//cols*h, i%cols*w + w, i//cols*h + h)) return grid def save_latent(x, name): x = torch.clamp((x[0] + 1.0) / 2.0, min=0.0, max=1.0) x = x.cpu().numpy() x = x * 255. imgs = [] for i, y in enumerate(x): from PIL import Image img = Image.fromarray(y.astype(np.uint8)) imgs.append(img) image_grid(imgs, 2, 2).save(name) save_latent(init_latents, "init_latents.png")

"Engineer's way of creating knowledge" the English version of my book is now available on [Engineer's way of creating knowledge]

(C)NISHIO Hirokazu / Converted from [Scrapbox] at [Edit]