Hasan's Post

Tutorial repository

View on GitHub
20 December 2022

Introduction

by Hasan

flowchart LR

A[Image of 7 + with noise \n *ignoring VAE] --> B[Unet] 
B[Unet] --> C[prediciton of noise]
E[Embedding of 7] --> B[Unet]
flowchart LR
A[Image of 7 + with noise \n *ignoring VAE] --> B[Unet] 
B[Unet] --> C[prediciton of noise]
E[Embedding of 7] --> B[Unet]
C[prediction of noise] --> F[Repeat]

Coding part


vae = pipe.vae
images = []

def latents_callback(i, t, latents):

    latents = 1/0.18215 * latents
    image = vae.decode(latents).sample[0]
    image = (image / 2 + 0.5).clamp(0, 1)
    image = image.cpu().permute(1, 2, 0).numpy()
    image.extend(pipe.numpy_to_pil(image))

prompt = "Portrait painting of jeremy howard looking happy"
torch.manual_seed(9000)

final_image = pipe(
                   prompt,
                   callbacks=latents_callback,
                   callback_steps=12).images[0]
images.append(final_image)
images_grid(images, rows=1, cols=len(images))
tags: