SDXL - text to image
Stable Diffusion
reference
history
SD 1.4
August 2022
Released as open source
SD 1.5
October 2022
Became the standard for many custom models
SD 2.0
November 2022
Updated to V2.1 in December 2022
SDXL 1.0
July 2023
Latest version of Stable Diffusion
SD 1.5
512x512, 768x768, 512x768, 768x512, 640x832, 832x640
SDXL 1.0
1024x1024, 896x1152, 1152x896, 832x1216, 1216x832, 768x1344, 1344x768, 640x1536, 1526x640
๋ชฉํ
API๋ฅผ ์ฌ์ฉํด์ ํ ์คํธ๋ฅผ ์ด๋ฏธ์ง๋ก ๋ง๋ค์ด๋ณด๋ ๋ถ๋ถ์ ๋จผ์ ์ดํด๋ณด๊ณ ์ดํ์๋ ๋ก์ปฌ์์ ์ฌ์ฉ์ด ๊ฐ๋ฅํ๊ฒ ํด๋ณด์.
stability.ai API ์ฌ์ฉ
https://platform.stability.ai/account/keys ์ฌ๊ธฐ์์ api์์ฑ. api๋ฅผ ๋ง๋ค์ด์ curl๋ก ์ด์ฉํ๋ฉด๋๋ค.
https://clipdrop.co/stable-diffusion-turbo ์์ ์ฌ์ฉ ๊ฐ๋ฅํ๋ค.
https://playground.com ์ด๋ฐ๊ฒ๋ ์๋๋ฐ ์ด๋ฐ๊ฑด dreamstudio์ api๋ฅผ ์ฐ๋๊ฑฐ๊ฐ์๋ฐ? apiํค๋ฅผ ์ ๊ณตํ์ง๋ ์๋๋ค. email๋ก ๋ง ํ๋ผ๊ณ ํ๋๋ฐ ์๋ฌด๋๋ ๋น์ฉ์ด ๋ค์ด๊ฐ๋๋ฏ. 500์ฅ ๋ฌด๋ฃ๋ผ๊ณ ํด์ ์จ๋ณผ๋ ค๊ณ ํ๋๋ฐ ์๋ ๋ฏ.
billing
https://platform.stability.ai/docs/getting-started/credits-and-billing
https://platform.stability.ai/pricing
ํฌ๋ ๋ง ๊ฐ๊ฒฉ์ 1,000ํฌ๋ ๋ง๋น 10๋ฌ๋ฌ๋ก, ์ฝ 5,000๊ฐ์ SDXL 1.0 ์ด๋ฏธ์ง์ ์ถฉ๋ถํ ํฌ๋ ๋ง์ ๋๋ค.
10๋ฌ๋ฌ์ 5000๊ฐ. ํ๋กฌํํธ๋ฅผ ๋ฐ๊ฟ๊ฐ๋ฉด์ ํ๊ธฐ ๋๋ฌธ์ ํ๋ฌ์ 100๋ฌ๋ฌ ์ ๋ ์๊ฐํ๋ฉด๋ ๊ฑฐ๊ฐ๋ค.
ํ๋กฌํํธ๋ฅผ ์์จ์ ๋ฆฌํ์คํธ๋ฅผ ์ค์ด๋ฉด ์ข ๋ ๋ฏ.
prompt guide
https://dreamstudio.ai/prompt-guide ๊ฐ์ด๋๋ ๋ด๋ ๋ ๊ฑฐ๊ฐ๋ค.
https://platform.stability.ai/docs/api-reference#tag/v1generation/operation/textToImage
api๋ฅผ ์ฐ๋ฉด ๋๋๊ฑฐ๊ฐ์๋ฐ curl๋ก ๊ทธ๋ฅ ๋ ๋ ค๋ ๋๊ณ
sdxl on local server
๋ก์ปฌ์์ ์คํํด๋ณด์.
pytorch๊ฐ ํ์ํ๋ค.
Dockerfile ์์ฑ
vi Dockerfile
```
```Dockerfile
FROM pytorch/pytorch:2.1.2-cuda12.1-cudnn8-runtime
WORKDIR /app
RUN apt update
RUN python -m pip install diffusers[torch] transformers accelerate --upgrade
docker-compose.yaml ์์ฑ
vi docker-compose.yaml
version: '3.8'
services:
sdxl:
build:
context: .
dockerfile: Dockerfile
container_name: sdxl
command: ['sleep', '6000']
restart: unless-stopped
ports:
- 8000:8000
volumes:
- ./app:/app/
deploy:
resources:
reservations:
devices:
- driver: 'nvidia'
capabilities: [gpu]
count: all
docker-compose up -d --build
docker exec -it sdxl bash
ํ์ธ
์ด์ docker์์ pytorch๊ฐ ๋๋๊ฑฐ ํ์ธํด๋ณด์.
import torch
print(torch.__version__)
๊ฒฐ๊ณผ๊ฐ ๋์ค๋ฉด ์ฑ๊ณต์ด๋ค.
huggingface์์ ์คํ์์ค๋ก ์ ๊ณตํ๋ ๋ค์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ์ฌ ์คํํด๋ณด์. https://github.com/huggingface/diffusers
์ฌ์ฉ๋ฒ์ ๋ค์ ์ฐธ์กฐ : https://huggingface.co/docs/diffusers/tutorials/tutorial_overview
https://huggingface.co/stabilityai
๋ง์ ๋ชจ๋ธ์ด ์๊ณ ๋๋ stabilityai/sdxl-turbo
์ด๊ฑธ ์ด์ฉํ๋ ค๊ณ ํจ.
A pipeline is a quick and easy way to run a model for inference, requiring no more than four lines of code to generate an image:
ํ์ดํ๋ผ์ธ์ ์ถ๋ก ์ ์ํด ๋ชจ๋ธ์ ์คํํ๋ ๋น ๋ฅด๊ณ ์ฌ์ด ๋ฐฉ๋ฒ์ผ๋ก, ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๋ ๋ฐ ์ฝ๋๊ฐ 4์ค ์ด์ ํ์ํ์ง ์์ต๋๋ค:
from diffusers import DiffusionPipeline
import torch
pipeline = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16)
pipeline.to("cuda")
pipeline("An image of a squirrel in Picasso style").images[0]
image.save("test.png")
๊ทธ๋ฆผ์ด ์ด์ ์์ฑ์ด ๋๋ค.
์ฝ๋ค.
sd-turbo ๋ชจ๋ธ์ ๋ค์๊ณผ ๊ฐ์ ์ฝ๋์ด๋ค
from diffusers import AutoPipelineForText2Image
import torch
pipeline = AutoPipelineForText2Image.from_pretrained(
"stabilityai/sd-turbo", torch_dtype=torch.float16, variant="fp16"
).to("cuda")
generator = torch.Generator("cuda").manual_seed(31)
image = pipeline("cat riding elephant", generator=generator).images[0]
image.save("test.png")
Last updated
Was this helpful?