Last active
December 4, 2023 21:27
-
-
Save nbonamy/c59771b394d5acc614a92a51c3adf8f4 to your computer and use it in GitHub Desktop.
StableDiffusion with intermediate save
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from diffusers import StableDiffusionPipeline | |
import torch | |
def progress(step, timestep, latents): | |
print(step, timestep, latents[0][0][0][0]) | |
with torch.no_grad(): | |
latents = 1 / 0.18215 * latents | |
image = pipe.vae.decode(latents).sample | |
image = (image / 2 + 0.5).clamp(0, 1) | |
image = image.cpu().permute(0, 2, 3, 1).float().numpy() | |
image = pipe.numpy_to_pil(image) | |
image[0].save(f"step_{step}.png") | |
# main image | |
prompt = "A fantasy landscape with mountains and a river" | |
pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4") | |
images = pipe(prompt, callback=progress, callback_steps=10).images | |
images[0].save(f"image.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment