|
|
|
from diffusers import DiffusionPipeline, StableDiffusionPipeline, KDPM2DiscreteScheduler, KDPM2AncestralDiscreteScheduler, HeunDiscreteScheduler, DDIMScheduler, EulerDiscreteScheduler, EulerAncestralDiscreteScheduler, PNDMScheduler, LMSDiscreteScheduler, DPMSolverMultistepScheduler |
|
import torch |
|
import os |
|
|
|
seed = 33 |
|
inference_steps = 25 |
|
|
|
|
|
|
|
|
|
pipe = StableDiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2", torch_dtype=torch.float16) |
|
|
|
pipe = pipe.to("cuda") |
|
|
|
|
|
for prompt in ["astronaut riding horse", "whale falling from sky", "magical forest", "highly photorealistic picture of johnny depp"]: |
|
for sampler in ["sample_dpm_2_ancestral", "euler_ancestral", "sample_dpm_2", "sample_heun", "lms", "ddim", "euler", "pndm", "dpm"]: |
|
|
|
|
|
|
|
|
|
folder = f"a_{'_'.join(prompt.split())}" |
|
os.makedirs(f"/home/patrick_huggingface_co/images/{folder}", exist_ok=True) |
|
|
|
|
|
|
|
|
|
|
|
if sampler == "sample_dpm_2": |
|
pipe.scheduler = KDPM2DiscreteScheduler.from_config(pipe.scheduler.config) |
|
elif sampler == "sample_dpm_2_ancestral": |
|
pipe.scheduler = KDPM2AncestralDiscreteScheduler.from_config(pipe.scheduler.config) |
|
elif sampler == "sample_heun": |
|
pipe.scheduler = HeunDiscreteScheduler.from_config(pipe.scheduler.config) |
|
elif sampler == "ddim": |
|
pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config) |
|
elif sampler == "dpm": |
|
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config) |
|
elif sampler == "euler": |
|
pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config) |
|
elif sampler == "euler_ancestral": |
|
pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config) |
|
elif sampler == "pndm": |
|
pipe.scheduler = PNDMScheduler.from_config(pipe.scheduler.config) |
|
elif sampler == "lms": |
|
pipe.scheduler = LMSDiscreteScheduler.from_config(pipe.scheduler.config) |
|
|
|
torch.manual_seed(0) |
|
image = pipe(prompt, num_inference_steps=inference_steps).images[0] |
|
|
|
image.save(f"/home/patrick_huggingface_co/images/{folder}/hf_{sampler}.png") |
|
break |
|
|