[G1-Sync] Manual knowledge update
This commit is contained in:
@@ -2,72 +2,170 @@
|
||||
id: wiki-2026-0508-부정-프롬프트와-가중치를-활용한-시각적-아티팩트-artif
|
||||
title: 부정 프롬프트와 가중치를 활용한 시각적 아티팩트(Artifact) 디버깅 및 제어
|
||||
category: 10_Wiki/Topics
|
||||
status: needs_review
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: []
|
||||
aliases: [Negative Prompt, Prompt Weighting, Artifact Debugging]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.92
|
||||
tags: [uncategorized]
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [diffusion, prompt-engineering, sdxl, flux, image-gen]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-08
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
inferred_by: Claude Opus 4.7 (auto-normalize 2026-05-08)
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: diffusers
|
||||
---
|
||||
|
||||
# [[부정 프롬프트와 가중치를 활용한 시각적 아티팩트(Artifact) 디버깅 및 제어|부정 프롬프트와 가중치를 활용한 시각적 아티팩트(Artifact) 디버깅 및 제어]]
|
||||
# 부정 프롬프트와 가중치를 활용한 시각적 아티팩트(Artifact) 디버깅 및 제어
|
||||
|
||||
## 📌 한 줄 통찰 (The Karpathy Summary)
|
||||
부정 프롬프트(Negative Prompt)와 가중치(Weight)는 AI 이미지 생성 과정에서 발생하는 시각적 아티팩트와 원치 않는 요소를 효과적으로 통제하고 디버깅하는 핵심 프롬프트 엔지니어링 기법이다. 부정 프롬프트는 모델이 피해야 할 요소(예: 변형된 손가락, 워터마크, 저화질)를 명시적으로 차단하여 렌더링 품질을 높이고 재작업(Reroll) 횟수를 줄이는 역할을 한다. 가중치는 괄호와 수치 기호를 활용해 특정 키워드의 영향력을 조절함으로써 긍정적 혹은 부정적 지시어의 강도를 세밀하게 조정할 수 있게 해, 창작자가 생성 모델의 편향을 억제하고 의도한 시각적 결과물을 안정적이고 정밀하게 도출할 수 있도록 돕는다.
|
||||
## 매 한 줄
|
||||
> **"매 artifact 매 unwanted concept 의 누출"**. Diffusion model 의 산출물 의 extra fingers, melted face, watermark 의 매 negative prompt + token weighting 의 conditional vector 조정 의 억제. 매 2026 의 FLUX 매 negative prompt 의존도 ↓ — guidance distillation 으로 quality 자체 ↑.
|
||||
|
||||
## 📖 구조화된 지식 (Synthesized Content)
|
||||
* **부정 프롬프트의 역할과 원리**
|
||||
부정 프롬프트는 모델이 생성 과정에서 피해야 할 시각적 방향과 경계를 정의하는 역할을 한다 [1-3]. 이는 단순히 완성된 이미지에 필터를 씌우는 것이 아니라, 생성 중인 확산(Diffusion) 과정을 원치 않는 개념으로부터 밀어내는 방식으로 작동한다 [1]. 주로 워터마크, 변형된 손가락(extra fingers), 저해상도(lowres), 일치하지 않는 눈 등 반복적으로 발생하는 시각적 결함(아티팩트)이나 모델의 편향을 방지하고 깔끔한 출력을 얻기 위해 필수적으로 사용된다 [1, 3-6].
|
||||
## 매 핵심
|
||||
|
||||
* **시각적 아티팩트 디버깅 전략**
|
||||
범용적인 '나쁜 품질(bad quality)'과 같은 모호한 단어의 나열보다는, 이미지에서 실제로 반복해서 발생하는 결함을 구체적으로 진단하고 이를 명시적인 명사나 시각적 특성으로 번역하여 차단하는 것이 효과적이다 [7, 8]. 예를 들어 '나쁜 손'보다는 '여섯 개의 손가락', '융합된 손가락'과 같이 구체적으로 명시해야 하며, 문제가 해결되면 불필요한 부정 프롬프트는 제거하여 모델이 혼란을 겪는 것을 방지해야 한다 [8, 9].
|
||||
### 매 메커니즘
|
||||
- Classifier-Free Guidance (CFG): `noise = uncond + scale * (cond - uncond)`.
|
||||
- Negative prompt 의 `uncond` 의 대체 — 매 "이쪽 으로 가지 마" vector.
|
||||
- Token weighting (`(token:1.3)`) 매 cross-attention 의 token embedding scale.
|
||||
|
||||
* **가중치(Weights)를 통한 세밀한 제어**
|
||||
프롬프트의 특정 단어나 구문의 중요도를 높이거나 낮추기 위해 가중치를 활용할 수 있다 [3, 10]. 스테이블 디퓨전(Stable Diffusion) 등에서는 `(keyword:factor)` 형태의 문법을 사용해 중요도를 숫자로 지정하며, `()`를 사용하면 1.1배 강조, `[]`를 사용하면 0.9배 약화시키는 식으로 세밀하게 조정할 수 있다 [3, 10-12]. 기호 `+`나 `-`를 단어 뒤에 붙여 강도를 조절하는 방식도 지원된다 [10]. 가중치는 부정 프롬프트에도 동일하게 적용 가능하여, 지속적으로 발생하는 결함을 더욱 강력하게 차단할 때 유용하다(예: `(blurry:1.5)`, `(deformed:1.2)`) [13, 14].
|
||||
### 매 흔한 artifact
|
||||
- **Anatomy**: extra fingers, deformed hands, asymmetric eyes.
|
||||
- **Composition**: cropped head, floating limbs, tangent edges.
|
||||
- **Quality**: blur, jpeg artifact, low resolution, oversaturation.
|
||||
- **Concept leak**: text/watermark, signature, logo.
|
||||
|
||||
* **모델별 한계 및 주의사항**
|
||||
스테이블 디퓨전 모델은 부정 프롬프트와 가중치 제어를 정밀하게 지원하여 이를 널리 활용할 수 있다 [11, 12, 14]. 반면 DALL-E 3와 같은 모델은 'not', 'no', 'without'과 같은 부정어(Negations)를 제대로 처리하지 못해 오히려 배제하려던 요소를 생성해버리는 부작용이 있으므로, 가급적 긍정적인 형태의 속성 묘사를 사용하는 것이 권장된다 [15-17]. 또한, 무분별하게 너무 높은 가중치를 부여하거나 과도하게 긴 부정 프롬프트를 나열하면 모델의 개념에 혼동을 주어 심각한 아티팩트를 유발하거나 의도한 원래의 스타일까지 망칠 수 있으므로 주의해야 한다 [18-20].
|
||||
### 매 응용
|
||||
1. SDXL/SD3 매 negative prompt 의 default workflow 에 포함.
|
||||
2. FLUX/SD3.5 매 prompt weighting 의존도 ↓ — guidance distilled.
|
||||
3. Inpainting fix — masked region 만 negative prompt 의 적용.
|
||||
|
||||
## 🔗 지식 연결 (Graph)
|
||||
- **Related Topics:** [[프롬프트 가중치 (Prompt Weights)|프롬프트 가중치(Prompt Weights)]], [[스테이블 디퓨전 (Stable Diffusion)|스테이블 디퓨전(Stable Diffusion)]], CFG Scale(Classifier-Free Guidance)
|
||||
- **Projects/Contexts:** 고품질 인물 및 애니메이션 이미지 생성 디버깅, API 및 개발자 워크플로우에서의 프롬프트 최적화
|
||||
- **Contradictions/Notes:** 스테이블 디퓨전(Stable Diffusion) 모델에서는 부정 프롬프트가 필수적이고 매우 강력한 제어 도구로 기능하지만, DALL-E 3 모델에서는 부정어 명령을 이해하지 못해 오히려 피하려던 요소를 포함시키는 오류를 범하므로 모델에 따라 프롬프트 제어 방식에 큰 모순점과 접근 방식의 차이가 존재한다 [15, 17, 21].
|
||||
## 💻 패턴
|
||||
|
||||
---
|
||||
*Last updated: 2026-04-30*
|
||||
### diffusers — negative prompt 기본
|
||||
```python
|
||||
from diffusers import StableDiffusionXLPipeline
|
||||
import torch
|
||||
|
||||
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
|
||||
pipe = StableDiffusionXLPipeline.from_pretrained(
|
||||
"stabilityai/stable-diffusion-xl-base-1.0",
|
||||
torch_dtype=torch.float16
|
||||
).to("cuda")
|
||||
|
||||
**언제 이 지식을 쓰는가:**
|
||||
- *(TODO)*
|
||||
img = pipe(
|
||||
prompt="portrait of a woman, studio light, sharp focus, 50mm lens",
|
||||
negative_prompt=(
|
||||
"deformed, extra fingers, mutated hands, asymmetric eyes, "
|
||||
"lowres, jpeg artifacts, watermark, signature, text, blurry"
|
||||
),
|
||||
guidance_scale=7.0,
|
||||
num_inference_steps=30,
|
||||
).images[0]
|
||||
```
|
||||
|
||||
**언제 쓰면 안 되는가:**
|
||||
- *(TODO)*
|
||||
### compel — token weighting (SDXL)
|
||||
```python
|
||||
from compel import Compel, ReturnedEmbeddingsType
|
||||
|
||||
## 🧪 검증 상태 (Validation)
|
||||
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],
|
||||
)
|
||||
|
||||
- **정보 상태:** needs_review
|
||||
- **출처 신뢰도:** A
|
||||
- **검토 이유:** *(P-Reinforce Phase 1 자동 정규화. 본문 검증 필요.)*
|
||||
prompt = "a (majestic:1.3) lion, (golden mane:1.2), (cinematic:0.8)"
|
||||
neg = "(cartoon:1.4), (anime:1.4), (3d render:1.2)"
|
||||
|
||||
## 🧬 중복 검사 (Duplicate Check)
|
||||
embeds, pooled = compel(prompt)
|
||||
neg_embeds, neg_pooled = compel(neg)
|
||||
|
||||
- **기존 유사 문서:** *(TODO: 인덱서 클러스터 리포트 참조)*
|
||||
- **처리 방식:** UPDATE (자동 정규화)
|
||||
- **처리 이유:** Phase 1 정규화 — 옛 템플릿/누락 필드 보강.
|
||||
img = pipe(
|
||||
prompt_embeds=embeds, pooled_prompt_embeds=pooled,
|
||||
negative_prompt_embeds=neg_embeds, negative_pooled_prompt_embeds=neg_pooled,
|
||||
).images[0]
|
||||
```
|
||||
|
||||
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
|
||||
### A1111 syntax (community standard)
|
||||
```text
|
||||
# 매 강조 — (token:weight)
|
||||
masterpiece, (intricate details:1.2), (sharp focus:1.1)
|
||||
|
||||
- **과거 데이터와의 충돌:** 없음
|
||||
- **정책 변화:** 없음
|
||||
# Negative
|
||||
(worst quality:1.4), (low quality:1.4), (extra digits:1.3),
|
||||
(bad hands:1.3), watermark, text
|
||||
```
|
||||
|
||||
## 🕓 변경 이력 (Changelog)
|
||||
### FLUX — minimal negative
|
||||
```python
|
||||
# FLUX.1 [dev] 매 distilled — CFG ≈ 1, negative prompt 효과 ↓
|
||||
from diffusers import FluxPipeline
|
||||
|
||||
| 날짜 | 변경 내용 | 처리 방식 | 신뢰도 |
|
||||
|------|-----------|-----------|--------|
|
||||
| 2026-05-08 | P-Reinforce Phase 1 정규화 (frontmatter + 헤더 표준화) | UPDATE | A |
|
||||
pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16).to("cuda")
|
||||
img = pipe(
|
||||
prompt="cinematic portrait, golden hour, shallow DOF",
|
||||
guidance_scale=3.5, # FLUX-specific
|
||||
num_inference_steps=28,
|
||||
).images[0]
|
||||
# 매 negative prompt 매 관습 의 대신 — positive prompt 의 specificity 의 의존
|
||||
```
|
||||
|
||||
### Region-specific negative (regional prompter)
|
||||
```python
|
||||
# 매 ComfyUI / Forge — mask 별 negative
|
||||
region_prompts = [
|
||||
{"mask": face_mask, "neg": "deformed, extra eye, asymmetric"},
|
||||
{"mask": hand_mask, "neg": "extra fingers, fused fingers, mutated"},
|
||||
]
|
||||
```
|
||||
|
||||
### Artifact debug — A/B isolate
|
||||
```python
|
||||
# 매 baseline (no negative)
|
||||
img_base = pipe(prompt=p, negative_prompt="", seed=42).images[0]
|
||||
|
||||
# 매 add one term at a time
|
||||
for term in ["deformed", "extra fingers", "lowres", "watermark"]:
|
||||
img = pipe(prompt=p, negative_prompt=term, seed=42).images[0]
|
||||
img.save(f"debug_{term}.png")
|
||||
# 매 비교 의 어떤 term 의 효과 의 식별
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Hand artifact | `(bad hands:1.3), extra fingers, fused fingers` |
|
||||
| Watermark/text | `watermark, signature, text, logo` (high weight) |
|
||||
| Style leak (cartoon) | `(cartoon:1.4), (anime:1.4)` |
|
||||
| FLUX/SD3.5 사용 | negative prompt 의 minimal — positive 의 specificity ↑ |
|
||||
| Inpaint 의 fix | mask region 의 local negative |
|
||||
|
||||
**기본값**: SDXL → standard negative bundle + weighting; FLUX → positive prompt 의 specificity.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[AI 이미지 생성 (AI Image Generation)]] · [[Diffusion Models]]
|
||||
- 변형: [[Classifier-Free Guidance]] · [[Prompt Weighting]]
|
||||
- 응용: [[AI 이미지 품질 최적화 및 디버깅 (Image Quality Optimization & Debugging)]] · [[미드저니 및 스테이블 디퓨전의 부분 편집 기법]]
|
||||
- Adjacent: [[ControlNet]] · [[IP-Adapter]] · [[Regional Prompter]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: anatomy/composition artifact 추적, prompt A/B isolate, style leak 차단.
|
||||
**언제 X**: FLUX-class distilled model — negative prompt 효과 ↓, positive specificity 의 의존.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Negative prompt 200-token wall**: token budget 낭비, 효과 saturate.
|
||||
- **High weight (>1.5)**: 매 collapse — output 의 distort.
|
||||
- **Generic "ugly, bad"**: 매 의미 없음 — concrete artifact name 의 사용.
|
||||
- **FLUX 의 SDXL-style negative**: 매 non-effect — guidance distilled.
|
||||
- **Seed 변경 의 비교**: 매 무의미 — same seed 만 isolate.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Diffusers docs, compel library, AUTOMATIC1111 wiki, FLUX.1 model card 2024-2026).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — negative prompt + weighting, FLUX 차이 |
|
||||
|
||||
Reference in New Issue
Block a user