ai

Stable Diffusion Colab — สร้างภาพ AI ฟรีบน Google

Stable Diffusion Colab — สร้างภาพ AI ฟรีบน Google

Stable Diffusion บน Colab

Stable Diffusion Colab — สร้างภาพ AI ฟรีบน Google

Stable Diffusion Google Colab Text-to-Image AUTOMATIC1111 ComfyUI Diffusers SDXL LoRA ControlNet Prompt GPU T4 A100 Free

เนื้อหาเกี่ยวข้อง — ทำความเข้าใจ Prometheus Alertmanager SSL TLS Certificate — คู่มือฉบับสมบูรณ์ 2026

PlatformGPUVRAMราคาSession
Colab FreeT415GBฟรีจำกัด ~2-4 ชม.
Colab ProT4/V100/A10015-40GB$10/เดือน24 ชม.
Colab Pro+A10040GB$50/เดือน24 ชม. + Background
RunPodRTX 3090/409024GB$0.2-0.7/ชม.ไม่จำกัด
Vast.aiหลากหลาย8-80GB$0.1-0.5/ชม.ไม่จำกัด
Local PCRTX 3060+12GB+ค่าไฟไม่จำกัด

Colab Setup & Pipeline

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



# Cell 1: Install Dependencies

# !pip install diffusers transformers accelerate safetensors

# !pip install xformers  # Memory optimization



# Cell 2: Load Model

# from diffusers import StableDiffusionXLPipeline

# import torch

#

# pipe = StableDiffusionXLPipeline.from_pretrained(

#     "stabilityai/stable-diffusion-xl-base-1.0",

#     torch_dtype=torch.float16,

#     variant="fp16",

#     use_safetensors=True

# )

# pipe = pipe.to("cuda")

# pipe.enable_xformers_memory_efficient_attention()

#

# # Cell 3: Generate Image

# prompt = "masterpiece, best quality, 1girl, long hair, blue eyes"

# negative = "worst quality, low quality, blurry, deformed"

# image = pipe(prompt, negative_prompt=negative,

#              num_inference_steps=30, guidance_scale=7.5).images[0]

# image.save("output.png")



from dataclasses import dataclass



@dataclass

class ColabSetup:

    step: str

    code: str

    time: str

    note: str



steps = [

    ColabSetup("Install Dependencies",

        "pip install diffusers transformers accelerate xformers",

        "2-3 นาที",

        "ติดตั้งครั้งเดียวต่อ Session"),

    ColabSetup("Download Model",

        "StableDiffusionXLPipeline.from_pretrained()",

        "5-10 นาที (SDXL ~6.5GB)",

        "Cache ใน /root/.cache ถ้า Session เดิม"),

    ColabSetup("Load to GPU",

        "pipe.to('cuda') + enable_xformers",

        "10-30 วินาที",

        "ใช้ float16 ลด VRAM 50%"),

    ColabSetup("Generate Image",

        "pipe(prompt, steps=30, cfg=7.5)",

        "10-30 วินาที (T4) 3-10 วินาที (A100)",

        "SDXL 1024x1024 ต้อง T4+ VRAM 15GB+"),

    ColabSetup("Save & Download",

        "image.save() + files.download()",

        "ทันที",

        "หรือ Upload ไป Google Drive"),

]



print("=== Colab Setup Steps ===")

for s in steps:

    print(f"  [{s.step}]")

    print(f"    Code: {s.code}")

    print(f"    Time: {s.time}")

    print(f"    Note: {s.note}")

Prompt Engineering

Stable Diffusion Colab — สร้างภาพ AI ฟรีบน Google
# === Prompt Templates ===



@dataclass

class PromptTemplate:

    style: str

    positive: str

    negative: str

    cfg: float

    steps: int

    sampler: str



templates = [

    PromptTemplate("Anime Character",

        "masterpiece, best quality, 1girl, long silver hair, "

        "blue eyes, school uniform, cherry blossom, spring, "

        "detailed background, soft lighting, anime style",

        "worst quality, low quality, blurry, deformed, "

        "extra fingers, bad anatomy, watermark, text",

        7.5, 30, "DPM++ 2M Karras"),

    PromptTemplate("Photorealistic Portrait",

        "RAW photo, masterpiece, best quality, ultra detailed, "

        "1woman, 25yo, beautiful face, natural skin, "

        "studio lighting, shallow depth of field, 85mm lens, "

        "bokeh, photorealistic",

        "painting, drawing, anime, cartoon, deformed, "

        "airbrushed, overexposed, blurry",

        9.0, 40, "DPM++ SDE Karras"),

    PromptTemplate("Landscape Fantasy",

        "masterpiece, epic fantasy landscape, floating islands, "

        "waterfalls, magical forest, glowing crystals, "

        "dramatic sky, golden hour, volumetric lighting, "

        "matte painting style, ultra detailed",

        "low quality, blurry, text, watermark, "

        "modern buildings, cars, people",

        8.0, 35, "Euler a"),

    PromptTemplate("Product Photo",

        "professional product photography, white sneaker, "

        "clean white background, studio lighting, "

        "high resolution, commercial, minimalist, "

        "sharp focus, 8k uhd",

        "shadow, dirty, damaged, text, watermark, "

        "blurry, low quality",

        10.0, 40, "DDIM"),

]



print("=== Prompt Templates ===")

for t in templates:

    print(f"\n  [{t.style}]")

    print(f"    Positive: {t.positive[:80]}...")

    print(f"    Negative: {t.negative[:60]}...")

    print(f"    CFG: {t.cfg} | Steps: {t.steps} | Sampler: {t.sampler}")

Model & ControlNet

# === Models & Extensions ===



@dataclass

class SDModel:

    name: str

    type_: str

    size: str

    style: str

    source: str



models = [

    SDModel("SDXL Base 1.0",

        "Checkpoint (Official)",

        "6.5GB",

        "General Purpose High Quality 1024x1024",

        "Hugging Face stabilityai/stable-diffusion-xl-base-1.0"),

    SDModel("Realistic Vision V6",

        "Checkpoint (Community)",

        "2GB (SD 1.5)",

        "Photorealistic เหมือนจริงมาก",

        "CivitAI"),

    SDModel("Anything V5",

        "Checkpoint (Community)",

        "2GB (SD 1.5)",

        "Anime สวยงาม สีสดใส",

        "CivitAI"),

    SDModel("Detail Tweaker LoRA",

        "LoRA",

        "144MB",

        "เพิ่มรายละเอียด ใช้กับ Checkpoint ไหนก็ได้",

        "CivitAI"),

    SDModel("ControlNet Canny",

        "ControlNet",

        "1.4GB",

        "ควบคุม Output ตามขอบภาพ Edge Detection",

        "Hugging Face lllyasviel/ControlNet"),

    SDModel("ControlNet OpenPose",

        "ControlNet",

        "1.4GB",

        "ควบคุม Pose ท่าทางคน",

        "Hugging Face lllyasviel/ControlNet"),

]



print("=== SD Models ===")

for m in models:

    print(f"  [{m.name}] Type: {m.type_} | Size: {m.size}")

    print(f"    Style: {m.style}")

    print(f"    Source: {m.source}")

เคล็ดลับ

  • xformers: เปิด xformers ลด VRAM 30-40%
  • float16: ใช้ torch_dtype=float16 เสมอ
  • SDXL: ต้อง VRAM 15GB+ ใช้ Colab T4 ได้
  • Prompt: เริ่มจาก Template แล้วปรับ ดีกว่าเขียนเอง
  • Seed: ใช้ Seed เดิมสำหรับ Reproducible Result

Stable Diffusion คืออะไร

Open Source Text-to-Image AI Latent Diffusion SD 1.5 SDXL SD 3.0 FLUX img2img Inpainting ControlNet LoRA GPU Upscaling

แนะนำเพิ่มเติม — หนังสือเทรดที่ SiamCafeBook

เนื้อหาเกี่ยวข้อง — แนะนำให้อ่าน โน้ตบุ๊ค Apple — คู่มือฉบับสมบูรณ์ 2026

เนื้อหาเกี่ยวข้อง — ทำความเข้าใจ Stablecoin คืออะไร — คู่มือ Crypto ฉบับสมบูรณ์

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

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