Forked from abhishekkrthakur/inference_sdxl_dreambooth.py
Created
September 1, 2023 02:57
-
-
Save enod/6a59d636d620807f43e691ce4ac77717 to your computer and use it in GitHub Desktop.
this is a reference for stable diffusion xl dreambooth tutorial: https://www.youtube.com/watch?v=gF078Lhnr94&ab_channel=AbhishekThakur
This file contains hidden or 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 DiffusionPipeline, StableDiffusionXLImg2ImgPipeline | |
| import torch | |
| model = "stabilityai/stable-diffusion-xl-base-1.0" | |
| pipe = DiffusionPipeline.from_pretrained( | |
| model, | |
| torch_dtype=torch.float16, | |
| ) | |
| pipe.to("cuda") | |
| pipe.load_lora_weights("model/", weight_name="pytorch_lora_weights.safetensors") | |
| refiner = StableDiffusionXLImg2ImgPipeline.from_pretrained( | |
| "stabilityai/stable-diffusion-xl-refiner-1.0", | |
| torch_dtype=torch.float16, | |
| ) | |
| refiner.to("cuda") | |
| prompt = "a portrait of sks dog, pixar, cartoon, 3d, headshots, fantasy, 4k, uhd" | |
| for seed in range(10): | |
| generator = torch.Generator("cuda").manual_seed(seed) | |
| image = pipe(prompt=prompt, generator=generator, num_inference_steps=25) | |
| image = image.images[0] | |
| image.save(f"images/{seed}.png") | |
| image = refiner(prompt=prompt, generator=generator, image=image) | |
| image = image.images[0] | |
| image.save(f"images_refined/{seed}.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment