File size: 4,756 Bytes
3ab8901 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
"""
A handy utility for verifying SDXL image generation locally.
To set up, first run a local cog server using:
cog run -p 5000 python -m cog.server.http
Then, in a separate terminal, generate samples
python samples.py
"""
import base64
import os
import sys
import requests
def gen(output_fn, **kwargs):
if os.path.exists(output_fn):
return
print("Generating", output_fn)
url = "http://localhost:5000/predictions"
response = requests.post(url, json={"input": kwargs})
data = response.json()
try:
datauri = data["output"][0]
base64_encoded_data = datauri.split(",")[1]
data = base64.b64decode(base64_encoded_data)
except:
print("Error!")
print("input:", kwargs)
print(data["logs"])
sys.exit(1)
with open(output_fn, "wb") as f:
f.write(data)
def main():
SCHEDULERS = [
"DDIM",
"DPMSolverMultistep",
"HeunDiscrete",
"KarrasDPM",
"K_EULER_ANCESTRAL",
"K_EULER",
"PNDM",
]
gen(
f"sample.txt2img.png",
prompt="A studio portrait photo of a cat",
num_inference_steps=25,
guidance_scale=7,
negative_prompt="ugly, soft, blurry, out of focus, low quality, garish, distorted, disfigured",
seed=1000,
width=1024,
height=1024,
)
for refiner in ["base_image_refiner", "expert_ensemble_refiner", "no_refiner"]:
gen(
f"sample.img2img.{refiner}.png",
prompt="a photo of an astronaut riding a horse on mars",
image="https://huggingface.co/datasets/patrickvonplaten/images/resolve/main/aa_xl/000000009.png",
prompt_strength=0.8,
num_inference_steps=25,
refine=refiner,
guidance_scale=7,
negative_prompt="ugly, soft, blurry, out of focus, low quality, garish, distorted, disfigured",
seed=42,
)
gen(
f"sample.inpaint.{refiner}.png",
prompt="A majestic tiger sitting on a bench",
image="https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png",
mask="https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png",
prompt_strength=0.8,
num_inference_steps=25,
refine=refiner,
guidance_scale=7,
negative_prompt="ugly, soft, blurry, out of focus, low quality, garish, distorted, disfigured",
seed=42,
)
for split in range(0, 10):
split = split / 10.0
gen(
f"sample.expert_ensemble_refiner.{split}.txt2img.png",
prompt="A studio portrait photo of a cat",
num_inference_steps=25,
guidance_scale=7,
refine="expert_ensemble_refiner",
high_noise_frac=split,
negative_prompt="ugly, soft, blurry, out of focus, low quality, garish, distorted, disfigured",
seed=1000,
width=1024,
height=1024,
)
gen(
f"sample.refine.txt2img.png",
prompt="A studio portrait photo of a cat",
num_inference_steps=25,
guidance_scale=7,
refine="base_image_refiner",
negative_prompt="ugly, soft, blurry, out of focus, low quality, garish, distorted, disfigured",
seed=1000,
width=1024,
height=1024,
)
gen(
f"sample.refine.10.txt2img.png",
prompt="A studio portrait photo of a cat",
num_inference_steps=25,
guidance_scale=7,
refine="base_image_refiner",
refine_steps=10,
negative_prompt="ugly, soft, blurry, out of focus, low quality, garish, distorted, disfigured",
seed=1000,
width=1024,
height=1024,
)
gen(
"samples.2.txt2img.png",
prompt="A studio portrait photo of a cat",
num_inference_steps=25,
guidance_scale=7,
negative_prompt="ugly, soft, blurry, out of focus, low quality, garish, distorted, disfigured",
scheduler="KarrasDPM",
num_outputs=2,
seed=1000,
width=1024,
height=1024,
)
for s in SCHEDULERS:
gen(
f"sample.{s}.txt2img.png",
prompt="A studio portrait photo of a cat",
num_inference_steps=25,
guidance_scale=7,
negative_prompt="ugly, soft, blurry, out of focus, low quality, garish, distorted, disfigured",
scheduler=s,
seed=1000,
width=1024,
height=1024,
)
if __name__ == "__main__":
main()
|