Files
2nd/10_Wiki/Topics/AI_and_ML/Image Parameters.md
T
Antigravity Agent f8b21af4be Wiki cleanup: error-doc removal, dedup merge, link normalization
10_Wiki/Topics 대규모 정리:
- 오류 캡처/미완성 stub 문서 227개 제거
- 교차폴더 중복 43클러스터 병합 (63파일 → redirect)
- 링크명 정규화: 깨진 링크 수정·redirect 직결·개념 매핑 ~2,400건
- 카테고리 MOC 6개 신규 생성
- Graph 섹션 미해결 related-keyword 링크 10,058건 제거

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-20 23:52:15 +09:00

199 lines
7.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
id: wiki-2026-0508-image-parameters
title: Image Parameters
category: 10_Wiki/Topics
status: verified
canonical_id: self
aliases: [Image Generation Parameters, Diffusion Parameters, Sampler Settings]
duplicate_of: none
source_trust_level: A
confidence_score: 0.9
verification_status: applied
tags: [diffusion, image-generation, stable-diffusion, sampler, cfg, seed]
raw_sources: []
last_reinforced: 2026-05-10
github_commit: pending
tech_stack:
language: python
framework: diffusers
---
# Image Parameters
## 매 한 줄
> **"매 같은 prompt 라도 sampler / steps / CFG / seed 가 그림을 결정한다"**. Diffusion-based 이미지 생성의 결과는 prompt 만큼이나 sampler 종류, sampling steps, classifier-free guidance scale, seed, scheduler 같은 운영 파라미터에 의해 좌우되며, 2026 현재 SDXL/FLUX/SD3.5/Imagen 모든 모델에서 공통적으로 적용된다.
## 매 핵심
### 매 핵심 파라미터
- **prompt / negative_prompt**: 텍스트 조건. 길이 ≠ 품질.
- **steps (sampling steps)**: 보통 20-50. FLUX-schnell 는 4 steps, Turbo/LCM 은 1-4.
- **CFG scale (guidance_scale)**: 1.5 (창의) ~ 12 (충실). FLUX 는 distilled — guidance 1 권장.
- **sampler / scheduler**: Euler, DPM++ 2M Karras, UniPC, DDIM, LCM.
- **seed**: 동일 seed + 동일 파라미터 → 재현.
- **width/height**: SDXL 1024², SD3.5 1024², FLUX 1024² 또는 1024×1536.
- **strength (img2img)**: 0 (원본) ~ 1 (전부 새로).
- **clip_skip**: 1 (기본) — anime 모델은 2 가 흔함.
- **prompt weighting**: `(word:1.3)`, `[word]` (A1111), `(word)+` (compel).
- **LoRA scale**: 0.6-0.9 일반, 1.0 강함.
### 매 sampler 비교 (2026)
- **Euler / Euler a**: 빠름, 단순.
- **DPM++ 2M Karras**: 표준 추천 — 품질/속도 균형.
- **UniPC**: 적은 steps 에서 강함.
- **DDIM**: deterministic, 재현성 좋음.
- **LCM / Turbo**: distilled, 1-4 steps.
- **Heun, DPM++ SDE**: 고품질, 느림.
### 매 응용
1. ComfyUI / A1111 / Forge UI 워크플로 작성.
2. SDK 기반 batch 생성 (diffusers).
3. ControlNet / IP-Adapter 결합.
4. 프로덕션 API (Replicate, Fal, RunPod).
## 💻 패턴
### 1. diffusers — 기본 SDXL 호출
```python
from diffusers import StableDiffusionXLPipeline
import torch
pipe = StableDiffusionXLPipeline.from_pretrained(
"stabilityai/stable-diffusion-xl-base-1.0",
torch_dtype=torch.float16, variant="fp16",
).to("cuda")
img = pipe(
prompt="a photo of a Shiba Inu, cinematic, 50mm",
negative_prompt="lowres, watermark",
num_inference_steps=30, guidance_scale=6.0,
width=1024, height=1024,
generator=torch.Generator("cuda").manual_seed(42),
).images[0]
img.save("out.png")
```
### 2. FLUX (guidance-distilled)
```python
from diffusers import FluxPipeline
pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16).to("cuda")
img = pipe(
prompt="a tiny astronaut riding a duck, studio light",
guidance_scale=3.5, # FLUX-dev: 3-5
num_inference_steps=28,
height=1024, width=1024,
generator=torch.Generator("cuda").manual_seed(0),
).images[0]
```
### 3. LCM 1-4 steps (real-time)
```python
from diffusers import AutoPipelineForText2Image, LCMScheduler
pipe = AutoPipelineForText2Image.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16).to("cuda")
img = pipe(prompt="cyberpunk cat", num_inference_steps=2, guidance_scale=0.0).images[0]
```
### 4. img2img + strength
```python
from diffusers import StableDiffusionXLImg2ImgPipeline
pipe = StableDiffusionXLImg2ImgPipeline.from_pretrained(...).to("cuda")
img = pipe(prompt=prompt, image=init, strength=0.55, guidance_scale=7.0, num_inference_steps=40).images[0]
```
### 5. prompt weighting (compel)
```python
from compel import Compel, ReturnedEmbeddingsType
compel = Compel(tokenizer=[pipe.tokenizer, pipe.tokenizer_2],
text_encoder=[pipe.text_encoder, pipe.text_encoder_2],
returned_embeddings_type=ReturnedEmbeddingsType.PENULTIMATE_HIDDEN_STATES_NON_NORMALIZED,
requires_pooled=[False, True])
prompt = "a (red:1.4) sports car, (sunset:1.2)"
conditioning, pooled = compel(prompt)
img = pipe(prompt_embeds=conditioning, pooled_prompt_embeds=pooled, num_inference_steps=30).images[0]
```
### 6. LoRA + scale
```python
pipe.load_lora_weights("path/to/anime.safetensors", adapter_name="anime")
pipe.set_adapters(["anime"], adapter_weights=[0.7])
img = pipe(prompt="anime girl, blue hair", num_inference_steps=30, guidance_scale=6.5).images[0]
```
### 7. ControlNet (구조 보존)
```python
from diffusers import StableDiffusionXLControlNetPipeline, ControlNetModel
cnet = ControlNetModel.from_pretrained("diffusers/controlnet-canny-sdxl-1.0", torch_dtype=torch.float16)
pipe = StableDiffusionXLControlNetPipeline.from_pretrained(
"stabilityai/stable-diffusion-xl-base-1.0", controlnet=cnet, torch_dtype=torch.float16,
).to("cuda")
img = pipe(prompt="oil painting", image=canny_img,
controlnet_conditioning_scale=0.7, num_inference_steps=30).images[0]
```
### 8. seed sweep (탐색)
```python
import torch, itertools
for seed, cfg in itertools.product([0,1,2,3], [4.0, 6.0, 8.0]):
g = torch.Generator("cuda").manual_seed(seed)
img = pipe(prompt=prompt, guidance_scale=cfg, generator=g).images[0]
img.save(f"seed{seed}_cfg{cfg}.png")
```
### 9. scheduler 교체
```python
from diffusers import DPMSolverMultistepScheduler
pipe.scheduler = DPMSolverMultistepScheduler.from_config(
pipe.scheduler.config, algorithm_type="dpmsolver++", use_karras_sigmas=True,
)
```
### 10. ComfyUI API workflow (JSON 단편)
```json
{
"3": { "class_type": "KSampler",
"inputs": { "seed": 42, "steps": 30, "cfg": 6.5,
"sampler_name": "dpmpp_2m_sde", "scheduler": "karras",
"denoise": 1.0, "model": ["4",0], "positive": ["6",0],
"negative": ["7",0], "latent_image": ["5",0] } }
}
```
## 매 결정 기준
| 상황 | Approach |
|---|---|
| SDXL 기본 | DPM++ 2M Karras, 30 steps, CFG 6-7 |
| FLUX-dev | Euler, 28 steps, guidance 3.5 |
| FLUX-schnell / Turbo / LCM | Euler, 1-4 steps, guidance 0 |
| 사진 사실성 | CFG 4-6, negative_prompt 충실 |
| 스타일 강조 | LoRA 0.7-0.9 + CFG 6-8 |
| 구조 고정 | ControlNet, scale 0.6-0.8 |
| 배치 탐색 | seed sweep + grid |
**기본값**: SDXL = DPM++ 2M Karras, 30 steps, CFG 6.5. FLUX-dev = Euler, 28 steps, guidance 3.5.
## 🔗 Graph
- 부모: [[Diffusion-Models]] · [[Generative-AI]]
- 변형: [[Prompt-Weighting]]
- 응용: [[ControlNet]] · [[LoRA]] · [[IP-Adapter]]
- Adjacent: [[Stable-Diffusion]] · [[FLUX]] · [[ComfyUI]]
## 🤖 LLM 활용
**언제**: 파라미터 매핑 (UI ↔ API), prompt → weighted prompt 변환, sampler 선택 가이드, batch grid 코드 생성.
**언제 X**: 모델별 quirk (예: SD3.5 의 specific shift) — 모델 카드 직접 확인.
## ❌ 안티패턴
- **CFG 무작정 12 이상**: burn-out, oversaturated.
- **steps 100+**: 30-50 이후 거의 무차이, 비용만 증가.
- **FLUX 에 CFG 7**: distilled — guidance 1-4 가 정상.
- **seed 미고정 디버깅**: 재현 불가 → 파라미터 영향 분석 불가.
- **Negative prompt 남용**: SDXL/FLUX 는 짧게, 또는 비워도 OK.
- **prompt weighting 과용**: `(word:2.0)+` → broken composition.
## 🧪 검증 / 중복
- Verified (HuggingFace diffusers docs, FLUX model card, ComfyUI wiki 2026).
- 신뢰도 A.
## 🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — sampler/CFG/LoRA/ControlNet 코드 패턴 |