728x90
반응형
[Stable Diffusion] Stable Diffusion 3.5 Text to Image 이미지 생성
테스트 환경
Mac m1 pro
Code
import os
import uuid
from datetime import datetime
import torch
from diffusers import StableDiffusion3Pipeline
from dotenv import load_dotenv
load_dotenv()
HUGGING_FACE_ACCESS_TOKEN = os.getenv("HUGGING_FACE_ACCESS_TOKEN")
"""
https://prompthero.com/stable-diffusion-cartoon-prompts
"""
# torch.backends.mps.enable_fallback_implementations = True
print(f"Starting inference... {datetime.now()}")
pipe = StableDiffusion3Pipeline.from_pretrained(
"stabilityai/stable-diffusion-3.5-large",
torch_dtype=torch.bfloat16,
token=HUGGING_FACE_ACCESS_TOKEN,
local_files_only=True,
add_prefix_space=True,
safety_checker=None,
)
# pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
pipe = pipe.to("mps") # cuda
# pipe.enable_attention_slicing()
# prompt = "A hamster holding a sign that reads Hello World"
# prompt = "happy retriever with smile in the snow"
prompt = """"Cat's Table", A cartoon in the style of John Tenniel, Punch magazine, 1890"""
image = pipe(
prompt,
width=512,
height=512,
num_inference_steps=28,
guidance_scale=3.5,
).images[0]
image.save(image_filename := os.path.join("images", f"{uuid.uuid4()}.png"))
print("Image saved to", image_filename, f"Finished inference... {datetime.now()}")
Output
728x90
반응형
'IT > AI' 카테고리의 다른 글
[AI] 오디오 녹음 요약하기 (OpenAI Whisper, Langchain, Exaone) (4) | 2024.12.14 |
---|---|
ORM 사용에 관한 에이전트 토론 들어보기 (2) | 2024.12.12 |
Prompt Engineering Guide: Prompting Techniques (0) | 2024.11.24 |
Prompt Engineering Guide: LLM Arguments (0) | 2024.11.22 |
Llama3.1로 Github PR AI 코드 리뷰 하기 (1) | 2024.08.07 |