stable-diffusion-image-generation
Skill này làm gì
Skill này giải thích cách tạo và chỉnh sửa ảnh bằng các mô hình Stable Diffusion. Skill dành cho người sáng tạo và lập trình viên muốn tạo hoặc thay đổi ảnh bằng code.
Khi nào nên dùng
- ✓Khi bạn muốn tạo một ảnh từ mô tả bằng văn bản.
- ✓Khi bạn muốn đổi phong cách của một bức ảnh có sẵn bằng prompt văn bản.
- ✓Khi bạn cần điền vào vùng được che của một bức ảnh hoặc mở rộng ảnh ra ngoài các cạnh.
Liên kết skill
https://github.com/Orchestra-Research/AI-Research-SKILLs/blob/main/18-multimodal/stable-diffusion/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Hãy tạo một bức tranh màu nước về ngọn hải đăng lúc hoàng hôn theo mô tả của tôi.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Bạn tải một pipeline từ thư viện Diffusers và truyền vào một prompt văn bản. Mô hình bắt đầu từ nhiễu và tinh chỉnh dần thành ảnh. Skill cũng đề cập đến image-to-image, inpainting và phong cách LoRA.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
Stable Diffusion Image Generation
Comprehensive guide to generating images with Stable Diffusion using the HuggingFace Diffusers library.
When to use Stable Diffusion
Use Stable Diffusion when:
- Generating images from text descriptions
- Performing image-to-image translation (style transfer, enhancement)
- Inpainting (filling in masked regions)
- Outpainting (extending images beyond boundaries)
- Creating variations of existing images
- Building custom image generation workflows
Key features:
- Text-to-Image: Generate images from natural language prompts
- Image-to-Image: Transform existing images with text guidance
- Inpainting: Fill masked regions with context-aware content
- ControlNet: Add spatial conditioning (edges, poses, depth)
- LoRA Support: Efficient fine-tuning and style adaptation
- Multiple Models: SD 1.5, SDXL, SD 3.0, Flux support
Use alternatives instead:
- DALL-E 3: For API-based generation without GPU
- Midjourney: For artistic, stylized outputs
- Imagen: For Google Cloud integration
- Leonardo.ai: For web-based creative workflows
Quick start
Installation
pip install diffusers transformers accelerate torch
pip install xformers # Optional: memory-efficient attention
Basic text-to-image
from diffusers import DiffusionPipeline
import torch
# Load pipeline (auto-detects model type)
pipe = DiffusionPipeline.from_pretrained(
"stable-diffusion-v1-5/stable-diffusion-v1-5",
torch_dtype=torch.float16
)
pipe.to("cuda")
# Generate image
image = pipe(
"A serene mountain landscape at sunset, highly detailed",
num_inference_steps=50,
guidance_scale=7.5
).images[0]
image.save("output.png")
Using SDXL (higher quality)
from diffusers import AutoPipelineForText2Image
import torch
pipe = AutoPipelineForText2Image.from_pretrained(
"stabilityai/stable-diffusion-xl-base-1.0",
torch_dtype=torch.float16,
variant="fp16"
)
pipe.to("cuda")
# Enable memory optimization
pipe.enable_model_cpu_offload()
image = pipe(
prompt="A futuristic city with flying cars, cinematic lighting",
height=1024,
width=1024,
num_inference_steps=30
).images[0]
Architecture overview
Three-pillar design
Diffusers is built around three core components:
Pipeline (orchestration)
├── Model (neural networks)
│ ├── UNet / Transformer (noise prediction)
│ ├── VAE (latent encoding/decoding)
│ └── Text Encoder (CLIP/T5)
└── Scheduler (denoising algorithm)
Pipeline inference flow
Text Prompt → Text Encoder → Text Embeddings
↓
Random Noise → [Denoising Loop] ← Scheduler
↓
Predicted Noise
↓
VAE Decoder → Final Image
Core concepts
Pipelines
Pipelines orchestrate complete workflows:
| Pipeline | Purpose |
|---|---|
StableDiffusionPipeline |
Text-to-image (SD 1.x/2.x) |
StableDiffusionXLPipeline |
Text-to-image (SDXL) |
StableDiffusion3Pipeline |
Text-to-image (SD 3.0) |
FluxPipeline |
Text-to-image (Flux models) |
StableDiffusionImg2ImgPipeline |
Image-to-image |
StableDiffusionInpaintPipeline |
Inpainting |
Schedulers
Schedulers control the denoising process:
| Scheduler | Steps | Quality | Use Case |
|---|---|---|---|
EulerDiscreteScheduler |
20-50 | Good | Default choice |
EulerAncestralDiscreteScheduler |
20-50 | Good | More variation |
DPMSolverMultistepScheduler |
15-25 | Excellent | Fast, high quality |
DDIMScheduler |
50-100 | Good | Deterministic |
LCMScheduler |
4-8 | Good | Very fast |
UniPCMultistepScheduler |
15-25 | Excellent | Fast convergence |
Swapping schedulers
from diffusers import DPMSolverMultistepScheduler
# Swap for faster generation
pipe.scheduler = DPMSolverMultistepScheduler.from_config(
pipe.scheduler.config
)
# Now generate with fewer steps
image = pipe(prompt, num_inference_steps=20).images[0]
Generation parameters
Key parameters
| Parameter | Default | Description |
|---|---|---|
prompt |
Required | Text description of desired image |
negative_prompt |
None | What to avoid in the image |
num_inference_steps |
50 | Denoising steps (more = better quality) |
guidance_scale |
7.5 | Prompt adherence (7-12 typical) |
height, width |
512/ |
Câu hỏi thường gặp
Tôi cần cài đặt những gì?
Chạy pip install diffusers transformers accelerate torch, và xformers là gói tùy chọn thêm.
Nó hỗ trợ những mô hình nào?
Skill liệt kê SD 1.5, SDXL, SD 3.0 và Flux.
Làm sao để thêm một phong cách cụ thể?
Skill nhắc tới hỗ trợ LoRA để thích ứng phong cách một cách hiệu quả.
Chi tiết
Mô tả gốc của tác giả
State-of-the-art text-to-image generation with Stable Diffusion models via HuggingFace Diffusers. Use when generating images from text prompts, performing image-to-image translation, inpainting, or building custom diffusion pipelines.
Độ phổ biến
- Sao GitHub
- 14k
- Vị trí xếp hạng
- #11237
- Giấy phép
- MIT
- Cập nhật
- 10/10/2026
Bình luận
- …
Thêm skill từ kho mã này
autoresearch
14kHướng dẫn agent của bạn qua một dự án nghiên cứu AI đầy đủ, từ tổng quan tài liệu đến thí nghiệm và viết báo, với một vòng lặp kiểm thử và rà soát lặp lại.
prompt-guard
14kCho phép agent của bạn quét văn bản để phát hiện prompt injection và các nỗ lực jailbreak trước khi nó đến ứng dụng AI, dùng bộ phân loại nhỏ của Meta.
pytorch-fsdp2
14kChỉ cho agent của bạn cách thêm PyTorch FSDP2 vào script huấn luyện để các mô hình lớn được chia ra nhiều GPU và lưu đúng cách.
ml-training-recipes
14kCung cấp cho agent của bạn các công thức huấn luyện mạng nơ-ron đã được kiểm chứng, gồm chọn mô hình, bộ tối ưu, learning rate và xử lý loss tăng vọt.
Skill tương tự
gifgrep
394kCho phép agent của bạn tìm thư viện GIF, xem trước kết quả, tải một GIF, và lấy một khung hình tĩnh hoặc bảng ghép nhiều khung hình.
meme-maker
394kCho phép agent của bạn chọn một mẫu meme, thêm chú thích của riêng bạn và tạo meme dưới dạng ảnh SVG hoặc PNG.
ios-icon-gen
280kGiúp agent tạo biểu tượng cho ứng dụng iOS. Dùng biểu tượng của Apple hoặc từ các nguồn khác để tạo đúng định dạng tệp.