CoolFace
Modelpublic

diffusers/tools

sourceHugging Facecreativeml-openrail-mupdated 3y agoView on Hugging Face
11likes27downloads
run_local_img2img_xl.py43 linesDownload Raw Back to root
1#!/usr/bin/env python32from diffusers import StableDiffusionXLImg2ImgPipeline, EulerDiscreteScheduler, UniPCMultistepScheduler, DEISMultistepScheduler, HeunDiscreteScheduler, DPMSolverMultistepScheduler3import time4import hf_image_uploader as hiu5import numpy as np6from huggingface_hub import HfApi7import torch8import sys9 10path = sys.argv[1]11 12api = HfApi()13start_time = time.time()14pipe = StableDiffusionXLImg2ImgPipeline.from_pretrained(path, torch_dtype=torch.float16)15pipe.to("cuda")16 17 18prompt = "An astronaut riding a green horse on Mars"19 20 21init_image = torch.from_numpy(np.load("/home/patrick/images/xl_latents.npy")).to("cuda")22 23 24 25 26 27for scheduler_cls, kwargs in [28        (EulerDiscreteScheduler, {}), 29        (EulerDiscreteScheduler, {"use_karras_sigmas": True}), 30        (UniPCMultistepScheduler, {}),31        (UniPCMultistepScheduler, {"use_karras_sigmas": True}), 32        (DEISMultistepScheduler, {}),33        (DEISMultistepScheduler, {"use_karras_sigmas": True}), 34        (HeunDiscreteScheduler, {}),35        (HeunDiscreteScheduler, {"use_karras_sigmas": True}), 36        (DPMSolverMultistepScheduler, {}),37        (DPMSolverMultistepScheduler, {"use_karras_sigmas": True, "algorithm_type": "sd-dpmsolver++"}),38]:39    for num_steps in [11,12]:40        pipe.scheduler = scheduler_cls.from_config(pipe.scheduler.config, **kwargs)41        image = pipe(prompt=prompt, num_inference_steps=num_steps, image=init_image).images[0]42        hiu.upload(image, "patrickvonplaten/images")43