SiamCafe.net Blog
Technology

stable diffusion google colab

stable diffusion google colab
stable diffusion google colab | SiamCafe Blog
2026-04-08· อ. บอม — SiamCafe.net· 8,214 คำ

Stable Diffusion on Colab

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

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

# === 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}")

เคล็ดลับ

Stable Diffusion คืออะไร

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

ติดตั้งบน Colab อย่างไร

Google Colab T4 GPU pip install AUTOMATIC1111 ComfyUI git clone wget Model safetensors launch.py --share --xformers Drive

Prompt เขียนอย่างไร

Quality Tags Subject Details Style Negative masterpiece best quality CFG Steps Sampler DPM++ Seed LoRA Weight Realistic Anime

Model แนะนำมีอะไร

Realistic Vision Anything DreamShaper Juggernaut XL CounterfeitXL CivitAI Hugging Face safetensors LoRA Detail Tweaker SD 1.5 SDXL

สรุป

Stable Diffusion Google Colab T4 GPU AUTOMATIC1111 ComfyUI Prompt Model LoRA CivitAI Realistic Anime SDXL xformers ฟรี Cloud

📖 บทความที่เกี่ยวข้อง

Stable Diffusion ComfyUI Message Queue Designอ่านบทความ → Stable Diffusion ComfyUI Certification Pathอ่านบทความ → google colab stable diffusionอ่านบทความ → Stable Diffusion ComfyUI DNS Managementอ่านบทความ → Stable Diffusion ComfyUI Observability Stackอ่านบทความ →

📚 ดูบทความทั้งหมด →