|
from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler, AutoencoderKL |
|
import torch |
|
import os |
|
|
|
|
|
|
|
guidance_scale=7 |
|
steps=20 |
|
width=1024 |
|
height=1024 |
|
base_model_id_str = "SDXL-xmasize-Lora-Images" |
|
prompt_prefix = "" |
|
prompt_suffix = " xmasize, Very detailed, clean, high quality, sharp image" |
|
neg_prompt = "text, watermark, grainy, blurry, unfocused, nsfw, naked, nude, noisy image, deformed, distorted, pixelated" |
|
|
|
base = None |
|
refiner = None |
|
|
|
|
|
|
|
def load(): |
|
global base, refiner |
|
|
|
vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16) |
|
base = DiffusionPipeline.from_pretrained( |
|
"stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True |
|
) |
|
base.to("cuda") |
|
base.load_lora_weights("Norod78/SDXL-xmasize-Lora") |
|
base.enable_xformers_memory_efficient_attention() |
|
refiner = DiffusionPipeline.from_pretrained( |
|
"stabilityai/stable-diffusion-xl-refiner-1.0", |
|
text_encoder_2=base.text_encoder_2, |
|
vae=base.vae, |
|
torch_dtype=torch.float16, |
|
use_safetensors=True, |
|
variant="fp16", |
|
) |
|
refiner.to("cuda") |
|
refiner.enable_xformers_memory_efficient_attention() |
|
|
|
def generate(prompt, file_prefix ,samples = 2, seed = 7777): |
|
global base, refiner |
|
|
|
torch.manual_seed(seed) |
|
prompt = prompt_prefix + prompt |
|
prompt += prompt_suffix |
|
base_model_latents = base([prompt] * samples, |
|
negative_prompt = [neg_prompt] * samples, |
|
num_inference_steps=steps, |
|
guidance_scale=guidance_scale, |
|
height=height, width=width, |
|
output_type="latent")["images"] |
|
torch.manual_seed(seed) |
|
refiner_model_images = refiner([prompt] * samples, |
|
negative_prompt = [neg_prompt] * samples, |
|
num_inference_steps=steps, |
|
image=base_model_latents)["images"] |
|
for idx, image in enumerate(refiner_model_images): |
|
image.save(f"{base_model_id_str}/{file_prefix}-{idx}-{seed}--{width}x{height}--{guidance_scale}--{base_model_id_str}.jpg") |
|
|
|
def main(): |
|
load() |
|
|
|
os.mkdir(base_model_id_str) |
|
|
|
generate("A livingroom", "01_LivingRoom") |
|
generate("A nice town", "02_NiceTown") |
|
generate("A scene in \"The Minions\" movie", "03_MinionsMovie") |
|
generate("Wonderwoman", "04_Wonderwoman") |
|
generate("Marge Simpson", "05_MargeSimpson") |
|
generate("A beautiful woman", "06_BeautifulWoman") |
|
generate("A magical landscape", "07_MagicalLandscape") |
|
generate("Cute dog", "08_CuteDog") |
|
generate("An oil on canvas portrait of Snoop Dogg, Mark Ryden", "09_SnoopDog") |
|
generate("A flemish baroque painting of Kermit from the muppet show", "10_KermitFlemishBaroque") |
|
generate("Gal Gadot in Avatar", "11_GalGadotAvatar") |
|
generate("Ninja turtles, Naoto Hattori", "12_TMNT") |
|
generate("A socially awkward potato", "13_AwkwardPotato") |
|
generate("Pikachu as Rick and morty, Eric Wallis", "14_PikachuRnM") |
|
generate("The girl with pearl earing", "15_PearlEaring") |
|
generate("American Gothic ", "16_AmericanGothic") |
|
generate("Miss. Piggy as the Mona Lisa", "17_MsPiggyMonaLisa") |
|
generate("Rick Sanchez from the TV show \"Rick and Morty\"", "18_RickSanchez") |
|
generate("A paiting of Southpark with rainbow", "19_Southpark") |
|
generate("An oil painting of Phineas and Pherb hamering on a new machine, Eric Wallis", "20_PhineasPherb") |
|
generate("Bender, Saturno Butto", "21_Bender") |
|
generate("A psychedelic image of Bojack Horseman", "22_Bojack") |
|
generate("A movie poster for Gravity Falls Cthulhu stories", "23_GravityFalls") |
|
generate("A vibrant oil painting portrait of She-Ra", "24_Shira", 2, 512) |
|
|
|
if __name__ == '__main__': |
|
main() |