こすたろーんエンジニアの試行錯誤部屋

作成物の備忘録を書いていきますー

【Stable Diffusion】I ran SDXL with google colab and Diffusers.

スポンサーリンク

Stability AI's image generation AI model SDXL 1.0 is now available.
Not only has the detailed description, which was a weakness of the existing generation AI,
been improved, but the image size has also been reduced to 1024 x 1024 (default).
I would like to run SDXL 1.0 with google colab this time!

contents

スポンサーリンク

1.requirement

Google Colab
Diffusers transformers
base model = stabilityai/stable-diffusion-xl-base-1.0

2.code

!pip install diffusers --upgrade
!pip install invisible_watermark transformers accelerate safetensors

from diffusers import DiffusionPipeline
import torch
base = DiffusionPipeline.from_pretrained(
    "stabilityai/stable-diffusion-xl-base-1.0",
    torch_dtype=torch.float16,
    variant="fp16",
    use_safetensors=True
)
base.to("cuda")

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.enable_model_cpu_offload()


prompt = "任意のポジティブプロンプト"

n_steps = 50
high_noise_frac = 0.8

image = base(
    prompt=prompt,
    num_inference_steps=n_steps,
    denoising_end=high_noise_frac,
    output_type="latent",
).images

image = refiner(
    prompt=prompt,
    num_inference_steps=n_steps,
    denoising_start=high_noise_frac,
    image=image,
).images[0]

image.save('output_refiner.png')
image

3.result

positive prompt

prompt = "masterpiece, ultra high res, 1girl, (photo realistic:1.2) small_breasts smile detailed beautiful skin (black eyes) cute young, looking_at_viewers windy soft_light from front miko, red hakama, miko_clothes, miko_dress,"

positive prompt

prompt="masterpiece, ultra high res, 1 girl, (photo realistic:1.2),small_breasts,cleavage,smile,detailed beautiful skin, face focus, (black eyes), cute, young, looking at viewers, (scoop neck tee:2.0), ,collarbone, ((black hair)), windy, soft light, hand between legs, from front"

スポンサーリンク

I can generate high resolution images on google colab as well.
I would like to try models that can generate animated and realistic images in the future.

refarence

note.com
huggingface.co