ai

Stable Diffusion Google Colab — รัน AI

Stable Diffusion Google Colab — รัน AI

Stable Diffusion on Colab

Stable Diffusion Google Colab — รัน AI

Stable Diffusion Google Colab AI สร้างภาพ Text-to-Image T4 GPU WebUI AUTOMATIC1111 ComfyUI Prompt Model LoRA ฟรี

เนื้อหาเกี่ยวข้อง — อ่านต่อ: Stable Diffusion ComfyUI Citizen Developer

VersionResolutionVRAMQualityColab Free
SD 1.5512x5124-6GBดี (+ LoRA Model)รองรับ (T4)
SDXL 1.01024x10248-12GBดีมากรองรับ (T4 ช้า)
SD 3.01024x102412-16GB+ดีที่สุดไม่แนะนำ (VRAM ไม่พอ)

Colab Setup

# === Stable Diffusion on Google Colab ===

# Cell 1: Check GPU
# !nvidia-smi

# Cell 2: Install Dependencies
# !pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
# !pip install diffusers transformers accelerate safetensors xformers

# Cell 3: Download & Run AUTOMATIC1111 WebUI
# !git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui
# %cd stable-diffusion-webui
#
# # Download Model (Realistic Vision V5.1)
# !wget -O models/Stable-diffusion/realisticVision_v51.safetensors \
#   "https://civitai.com/api/download/models/130072"
#
# # Download LoRA (Detail Tweaker)
# !wget -O models/Lora/add_detail.safetensors \
#   "https://civitai.com/api/download/models/62833"
#
# # Launch WebUI
# !python launch.py --share --xformers --enable-insecure-extension-access

# Cell 4: Alternative - ComfyUI
# !git clone https://github.com/comfyanonymous/ComfyUI
# %cd ComfyUI
# !pip install -r requirements.txt
# !python main.py --listen 0.0.0.0 --port 8188

from dataclasses import dataclass

@dataclass
class ColabSetup:
    step: str
    command: str
    time: str
    note: str

steps = [
    ColabSetup("Check GPU",
        "!nvidia-smi",
        "5 วินาที",
        "ต้องได้ T4 (16GB) หรือ A100 (Pro)"),
    ColabSetup("Install Dependencies",
        "!pip install torch diffusers transformers xformers",
        "2-3 นาที",
        "ใช้ cu118 สำหรับ CUDA 11.8"),
    ColabSetup("Clone WebUI",
        "!git clone AUTOMATIC1111/stable-diffusion-webui",
        "1 นาที",
        "หรือใช้ ComfyUI สำหรับ Node-based"),
    ColabSetup("Download Model",
        "!wget -O models/Stable-diffusion/model.safetensors URL",
        "3-10 นาที (ตามขนาด)",
        "Realistic Vision 2.5GB | SDXL 6.5GB"),
    ColabSetup("Launch WebUI",
        "!python launch.py --share --xformers",
        "3-5 นาที (ครั้งแรก)",
        "--share สร้าง Public URL เข้าผ่าน Browser"),
]

print("=== Colab Setup Steps ===")
for s in steps:
    print(f"  [{s.step}] Time: {s.time}")
    print(f"    Command: {s.command}")
    print(f"    Note: {s.note}")

Prompt Guide

Stable Diffusion Google Colab — รัน AI
# === Prompt Engineering for Stable Diffusion ===

@dataclass
class PromptExample:
    category: str
    positive: str
    negative: str
    settings: str
    model: str

prompts = [
    PromptExample("Realistic Portrait",
        "masterpiece, best quality, photorealistic, 1girl, beautiful face, blue eyes, long brown hair, soft smile, natural lighting, shallow depth of field, 85mm lens, golden hour",
        "worst quality, low quality, blurry, deformed, ugly, extra fingers, bad anatomy, watermark, text",
        "Steps: 30 | CFG: 7 | Sampler: DPM++ 2M Karras | 512x768",
        "Realistic Vision V5.1 + Detail Tweaker LoRA"),
    PromptExample("Anime Character",
        "masterpiece, best quality, 1girl, anime, cute, blue hair, twintails, school uniform, cherry blossoms, spring, bright colors, detailed eyes",
        "worst quality, low quality, blurry, deformed, bad anatomy, extra limbs",
        "Steps: 25 | CFG: 8 | Sampler: Euler a | 512x768",
        "Anything V5 หรือ CounterfeitXL"),
    PromptExample("Landscape",
        "masterpiece, best quality, beautiful landscape, mountain valley, river, sunset, dramatic clouds, autumn colors, cinematic, wide angle, 4k, photorealistic",
        "worst quality, low quality, blurry, watermark, text, people",
        "Steps: 30 | CFG: 7 | Sampler: DPM++ 2M Karras | 768x512",
        "Realistic Vision หรือ Juggernaut XL"),
    PromptExample("Product Photo",
        "product photography, minimalist wireless earbuds, studio lighting, white background, soft shadows, macro detail, professional, commercial, 8k",
        "worst quality, low quality, blurry, text, watermark, background clutter",
        "Steps: 35 | CFG: 7 | Sampler: DPM++ 2M Karras | 512x512",
        "Realistic Vision + Detail Tweaker"),
]

print("=== Prompt Examples ===")
for p in prompts:
    print(f"\n  [{p.category}] Model: {p.model}")
    print(f"    Positive: {p.positive[:80]}...")
    print(f"    Negative: {p.negative[:60]}...")
    print(f"    Settings: {p.settings}")

Models & LoRA

# === Recommended Models ===

@dataclass
class SDModel:
    name: str
    version: str
    size: str
    style: str
    source: str

models = [
    SDModel("Realistic Vision V5.1",
        "SD 1.5",
        "2.5GB",
        "Photorealistic คน ธรรมชาติ สมจริง",
        "CivitAI civitai.com/models/4201"),
    SDModel("Anything V5",
        "SD 1.5",
        "2.1GB",
        "Anime ทั่วไป Community ใหญ่ LoRA เยอะ",
        "CivitAI civitai.com/models/9409"),
    SDModel("DreamShaper V8",
        "SD 1.5",
        "2.1GB",
        "หลากหลาย Fantasy Artistic Photo",
        "CivitAI civitai.com/models/4384"),
    SDModel("Juggernaut XL",
        "SDXL",
        "6.5GB",
        "Photorealistic SDXL ดีที่สุด 1024x1024",
        "CivitAI civitai.com/models/133005"),
    SDModel("CounterfeitXL",
        "SDXL",
        "6.5GB",
        "Anime SDXL คุณภาพสูง 1024x1024",
        "CivitAI civitai.com/models/129681"),
]

print("=== Recommended Models ===")
for m in models:
    print(f"  [{m.name}] {m.version} | Size: {m.size}")
    print(f"    Style: {m.style}")
    print(f"    Source: {m.source}")

เคล็ดลับ

  • xformers: ใช้ --xformers ลด VRAM เพิ่ม Speed 20-30%
  • Negative Prompt: ใส่ Negative Prompt ทุกครั้ง ลด Artifacts
  • Google Drive: Mount Drive เก็บ Model ไม่ต้องโหลดใหม่ทุก Session
  • Seed: จด Seed ของภาพที่ชอบ ใช้ปรับ Prompt ต่อ
  • LoRA: ใช้ LoRA ปรับ Style ไม่ต้องเปลี่ยน Model ทั้งตัว

Stable Diffusion คืออะไร

Open Source AI สร้างภาพ Stability AI Text-to-Image SD 1.5 SDXL SD 3.0 LoRA ControlNet Inpainting GPU VRAM ฟรี

แนะนำเพิ่มเติม — สัญญาณเทรดรายวัน XM Signal

เนื้อหาเกี่ยวข้อง — ดูเพิ่มเติมเรื่อง Prometheus Federation

เนื้อหาเกี่ยวข้อง — สแกนจ่ายผ่านบัตรเครดิตกสิกร

XM Legend · เทรดเดอร์ & ผู้สอน Forex 13 ปี

ผู้ก่อตั้ง SiamCafe ตั้งแต่ปี 1997 · เทรดเดอร์สาย Forex มากกว่า 13 ปี ได้รับการยกย่องเป็น XM Legend · แบ่งปันความรู้ Forex, ไอที, AI และการเทรด จากประสบการณ์จริงในตลาดจริง