Stable Diffusion คืออะไร
Stable Diffusion AI Text-to-Image Open Source Latent Diffusion Model GPU VRAM Automatic1111 ComfyUI SDXL ControlNet Inpainting
| Feature | Stable Diffusion | DALL-E 3 | Midjourney |
|---|---|---|---|
| Price | ฟรี (Open Source) | $20/เดือน (ChatGPT Plus) | $10-60/เดือน |
| Run Local | Yes (GPU 4GB+) | No (Cloud Only) | No (Discord Only) |
| Customizable | สูงมาก (LoRA Checkpoint) | ต่ำ | ปานกลาง |
| Quality | ดี-ดีมาก (ขึ้นกับ Model) | ดีมาก | ดีมาก |
| Speed | 5-30 วินาที (GPU) | 10-30 วินาที | 30-60 วินาที |
| API | Yes (Local/Cloud) | Yes (OpenAI API) | No (Official) |
การติดตั้ง
# === Stable Diffusion Installation Guide ===
# Method 1: Automatic1111 WebUI (Recommended for beginners)
# git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
# cd stable-diffusion-webui
#
# # Download Model (SDXL or SD 1.5)
# # Place .safetensors file in models/Stable-diffusion/
# # Download from: https://civitai.com or https://huggingface.co
#
# # Linux/Mac
# ./webui.sh --xformers --api
#
# # Windows
# webui.bat --xformers --api
#
# # Open http://localhost:7860
# Method 2: ComfyUI (Node-based, advanced)
# git clone https://github.com/comfyanonymous/ComfyUI.git
# cd ComfyUI
# pip install -r requirements.txt
# python main.py
# # Open http://localhost:8188
# Method 3: Python API (Diffusers library)
# pip install diffusers transformers accelerate torch
#
# from diffusers import StableDiffusionXLPipeline
# import torch
#
# pipe = StableDiffusionXLPipeline.from_pretrained(
# "stabilityai/stable-diffusion-xl-base-1.0",
# torch_dtype=torch.float16,
# variant="fp16",
# )
# pipe = pipe.to("cuda")
#
# image = pipe(
# prompt="a beautiful sunset over mountains, 8K, photorealistic",
# negative_prompt="low quality, blurry, deformed",
# num_inference_steps=30,
# guidance_scale=7.5,
# ).images[0]
# image.save("output.png")
from dataclasses import dataclass
@dataclass
class InstallMethod:
method: str
difficulty: str
gpu_required: str
features: str
best_for: str
methods = [
InstallMethod("Automatic1111 WebUI",
"ง่าย",
"GPU VRAM 4GB+ (8GB+ แนะนำ)",
"GUI ครบ Extensions มาก Community ใหญ่",
"มือใหม่ ใช้งานทั่วไป"),
InstallMethod("ComfyUI",
"ปานกลาง",
"GPU VRAM 4GB+",
"Node-based Workflow ยืดหยุ่น VRAM Efficient",
"Advanced User Complex Workflow"),
InstallMethod("Forge (Optimized A1111)",
"ง่าย",
"GPU VRAM 4GB+ (รัน SDXL บน 6GB ได้)",
"เร็วกว่า A1111 VRAM ต่ำกว่า UI เหมือน A1111",
"GPU VRAM น้อย ต้องการ Performance"),
InstallMethod("Python Diffusers",
"สูง (เขียน Code)",
"GPU VRAM 8GB+",
"Full Control API Integration Batch Processing",
"Developer Production API"),
InstallMethod("Google Colab",
"ง่าย",
"ไม่ต้องมี GPU (ใช้ Cloud)",
"ฟรี (จำกัดเวลา) ไม่ต้อง Setup",
"ไม่มี GPU ทดลองใช้"),
]
print("=== Installation Methods ===")
for m in methods:
print(f"\n [{m.method}] Difficulty: {m.difficulty}")
print(f" GPU: {m.gpu_required}")
print(f" Features: {m.features}")
print(f" Best for: {m.best_for}")
Prompt Engineering
# === Prompt Engineering Guide ===
@dataclass
class PromptComponent:
component: str
purpose: str
examples: str
weight: str
components = [
PromptComponent("Subject",
"สิ่งที่ต้องการในภาพ (สำคัญที่สุด)",
"a beautiful girl, a mountain landscape, a futuristic city",
"สูง (ใส่ต้น Prompt)"),
PromptComponent("Quality Tags",
"คุณภาพภาพ",
"masterpiece, best quality, 8K, ultra detailed, sharp focus",
"สูง"),
PromptComponent("Style",
"สไตล์ภาพ",
"photorealistic, anime, watercolor, oil painting, digital art",
"สูง"),
PromptComponent("Lighting",
"แสงในภาพ",
"golden hour, studio lighting, dramatic, neon, soft light",
"ปานกลาง"),
PromptComponent("Camera/Composition",
"มุมกล้อง การจัดวาง",
"close-up, wide angle, bird eye, rule of thirds, bokeh",
"ปานกลาง"),
PromptComponent("Color",
"โทนสี",
"warm tones, cool blue, pastel, monochrome, vibrant",
"ต่ำ-ปานกลาง"),
PromptComponent("Negative Prompt",
"สิ่งที่ไม่ต้องการ",
"low quality, blurry, deformed, extra fingers, watermark, text",
"สำคัญมาก"),
]
@dataclass
class SamplerConfig:
parameter: str
recommended: str
effect: str
params = [
SamplerConfig("Sampling Steps", "20-30 (DPM++ 2M Karras)",
"มาก = ละเอียดขึ้น แต่ช้า, 20 พอสำหรับส่วนใหญ่"),
SamplerConfig("CFG Scale", "7-12",
"สูง = ตาม Prompt มาก, ต่ำ = Creative มาก"),
SamplerConfig("Sampler", "DPM++ 2M Karras / Euler a",
"DPM++ 2M Karras: คุณภาพดี, Euler a: เร็ว"),
SamplerConfig("Size", "512x512 (SD1.5) / 1024x1024 (SDXL)",
"ใช้ Native Resolution ของ Model"),
SamplerConfig("Seed", "-1 (Random) / Fixed Number",
"Fixed Seed = ได้ภาพเหมือนเดิม สำหรับ Iterate"),
]
print("=== Prompt Components ===")
for c in components:
print(f" [{c.component}] {c.purpose}")
print(f" Examples: {c.examples}")
print("\n=== Parameters ===")
for p in params:
print(f" [{p.parameter}] {p.recommended}")
print(f" Effect: {p.effect}")
Use Cases
# === Stable Diffusion Use Cases ===
@dataclass
class UseCase:
category: str
applications: str
model_recommended: str
tips: str
cases = [
UseCase("Art & Design",
"Concept Art, Character Design, Illustration, Environment",
"SDXL + Anime/Fantasy LoRA",
"ใช้ ControlNet สำหรับ Pose Reference"),
UseCase("Marketing",
"Ad Banner, Social Media, Product Mockup, Thumbnail",
"SDXL + Product Photography LoRA",
"ใช้ Inpainting แก้ไขส่วนที่ไม่สมบูรณ์"),
UseCase("Photography",
"Stock Photo, Portrait, Landscape, Food",
"SDXL + Realistic Vision / juggernautXL",
"ใช้ ADetailer แก้หน้า มือ อัตโนมัติ"),
UseCase("Game Development",
"Asset, Texture, Sprite, Background, UI",
"SD 1.5 + Game Asset LoRA",
"ใช้ Tiling สำหรับ Seamless Texture"),
UseCase("Architecture",
"Interior Design, Building Concept, Renovation",
"SDXL + Architecture LoRA + ControlNet",
"ใช้ ControlNet Depth สำหรับ Layout"),
UseCase("Fashion",
"Fashion Design, Pattern, Textile, Lookbook",
"SDXL + Fashion LoRA",
"ใช้ IP-Adapter สำหรับ Style Transfer"),
]
print("=== Use Cases ===")
for u in cases:
print(f"\n [{u.category}]")
print(f" Apps: {u.applications}")
print(f" Model: {u.model_recommended}")
print(f" Tips: {u.tips}")
เคล็ดลับ
- SDXL: ใช้ SDXL แทน SD 1.5 คุณภาพดีกว่ามาก
- LoRA: ใช้ LoRA ปรับ Style เฉพาะ ไม่ต้อง Train Model ใหม่
- Negative: ใส่ Negative Prompt เสมอ ลด Artifact
- ADetailer: ใช้ ADetailer แก้หน้า มือ อัตโนมัติ
- Seed: จด Seed ที่ชอบ กลับมาใช้ Iterate ได้
Stable Diffusion คืออะไร
AI สร้างภาพจากข้อความ Open Source ฟรี Latent Diffusion GPU VRAM 4GB+ Text-to-Image Inpainting ControlNet SDXL Stability AI
ติดตั้งอย่างไร
Automatic1111 git clone webui.sh ComfyUI node-based Forge optimized Diffusers Python API Colab Cloud GPU VRAM 4GB+ CUDA Python 3.10
Prompt เขียนอย่างไร
Subject Quality Style Lighting Camera Color Negative Prompt Steps 20-30 CFG 7-12 DPM++ 2M Karras Seed masterpiece best quality 8K
นำไปใช้งานอะไรได้
Art Design Marketing Photography Game Architecture Fashion Education LoRA ControlNet ADetailer Inpainting Outpainting License ตรวจสอบ
สรุป
Stable Diffusion AI Text-to-Image Open Source SDXL Automatic1111 ComfyUI Prompt Engineering LoRA ControlNet Inpainting GPU Production
