[Stable Diffusion] Stable Diffusion 3.5 Text to Image 이미지 생성

2024. 11. 28. 23:07·IT/AI
반응형

[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)
  • ORM 사용에 관한 에이전트 토론 들어보기
  • Prompt Engineering Guide: Prompting Techniques
  • Prompt Engineering Guide: LLM Arguments
상쾌한기분
상쾌한기분
  • 상쾌한기분
    상쾌한기분
    상쾌한기분
  • 전체
    오늘
    어제
    • 분류 전체보기 (250)
      • Python (44)
        • Python (26)
        • Django (6)
        • Flask (4)
        • Open Source (6)
      • Kotlin & Java (5)
        • Spring (2)
        • 프로젝트 (1)
      • Go (11)
      • Database (24)
        • MySQL (21)
        • Redis (3)
      • Infrastructure (2)
        • CDC (4)
        • Kafka (5)
        • Prometheus (2)
        • Fluentd (11)
        • Docker (1)
        • Airflow (2)
        • VPN (2)
      • IT (25)
        • AI (9)
        • Langchain (8)
        • Web (18)
        • Git (8)
        • 리팩토링 (9)
        • Micro Service Architecture (8)
        • Clean Code (16)
        • Design Pattern (0)
        • 수학 (1)
        • 알고리즘 (14)
      • OS (14)
        • Centos (10)
        • Ubuntu (3)
        • Mac (1)
      • Search Engine (2)
        • ElasticSearch (1)
        • Lucene Solr (1)
      • PHP (2)
        • Laravel (1)
        • Codeigniter (1)
  • 블로그 메뉴

    • Github 방문
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    MYSQL
    fluentd
    prompt
    LLM
    Golang
    티스토리챌린지
    파이썬
    백준
    Redis
    go
    ollama
    git
    Langchain
    python
    docker
    오블완
    performance
    http
    CDC
    Kafka
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
상쾌한기분
[Stable Diffusion] Stable Diffusion 3.5 Text to Image 이미지 생성
상단으로

티스토리툴바