[G1-Sync] Manual knowledge update

This commit is contained in:
Antigravity Agent
2026-05-10 22:08:15 +09:00
parent 21ac3ed255
commit 504fd5fb42
3011 changed files with 380280 additions and 206977 deletions
+119 -45
View File
@@ -2,69 +2,143 @@
id: wiki-2026-0508-style-transfer
title: Style Transfer
category: 10_Wiki/Topics
status: needs_review
status: verified
canonical_id: self
aliases: [P-Reinforce-AUTO-STTR-001]
aliases: [Neural Style Transfer, NST, Style Transfer in AI]
duplicate_of: none
source_trust_level: A
confidence_score: 0.94
tags: [auto-reinforced, graphics, ai-art, style-transfer, neural-networks, Computer-Vision]
confidence_score: 0.9
verification_status: applied
tags: [style-transfer, neural-network, image-generation, diffusion]
raw_sources: []
last_reinforced: 2026-04-20
last_reinforced: 2026-05-10
github_commit: pending
inferred_by: Claude Opus 4.7 (auto-normalize 2026-05-08)
tech_stack:
language: python
framework: pytorch
---
# [[Style-Transfer|Style-Transfer]]
# Style Transfer
## 📌 한 줄 통찰 (The Karpathy Summary)
> "내용은 유지하고 붓 터치만 바꾸기: 한 이미지의 구조적 '내용(Content)'에 다른 이미지의 예술적 '화풍(Style)'을 수학적으로 입혀, 새로운 디지털 걸작을 창조해내는 화풍 전이 기술."
## 한 줄
> **"매 content + style separation의 art"**. Gatys et al. (2015) 가 VGG feature space 의 Gram matrix 로 style 추출 → 매 content image 에 transfer 의 seminal work. 2026 의 modern state 는 diffusion-based (IP-Adapter, ControlNet style) + Midjourney --sref 의 mainstream.
## 📖 구조화된 지식 (Synthesized Content)
스타일 전이(Style Transfer, Neural Style Transfer)는 컴퓨터 비전 기술을 사용하여 이미지의 시맨틱한 내용은 보존하면서 텍화나 특정 화가의 화풍만을 추출하여 입히는 기술입니다.
## 매 핵심
1. **동작 원리 (Neural Level)**:
* **Content Extraction**: 신경망(주로 CNN)의 깊은 층(Layer)에서 사물의 형태와 배치를 추출.
* **Style Extraction**: 신경망의 얕은 층에서 색감, 질감, 반복되는 패턴을 추출 (Gram Matrix 등 활용).
* **[[Optimization|Optimization]]**: 내용 손실(Content Loss)과 스타일 손실(Style Loss)을 동시에 최소화하는 새로운 이미지를 합성.
2. **발전 단계**:
* **Per-image Optimization**: 한 장을 만드는 데 수백 번의 연산 필요.
* **Fast Style Transfer**: 이미 학습된 '화풍 모델'을 통해 실시간 전이 가능.
* **Arbitrary Style Transfer**: 학습하지 않은 새로운 화풍도 즉시 반영 가능.
3. **적용 사례**:
* 사진을 명화 스타일로 변환, 게임 그래픽의 독특한 질감 처리, 영상 필터 앱.
### 매 origin (Gatys 2015)
- VGG-19 의 conv layer activation 의 feature representation.
- **Content loss**: 매 high-level layer (conv4_2) 의 feature MSE.
- **Style loss**: 매 multiple layer 의 Gram matrix (feature correlation) MSE.
- Optimization-based — 매 image pixel 자체 의 gradient descent (slow, ~minutes per image).
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
- **과거 데이터와의 충돌**: 초기 스타일 전이는 이미지의 형태가 뭉개지는 현상이 잦았으나, 현대의 생성 AI 정책은 확산 모델(Diffusion)을 결합하여 형태는 더욱 선명하게 유지하면서 화풍만 완벽히 바꾸는 '[[ControlNet|ControlNet]] 스타일 전이' 정책으로 업그레이드됨(RL Update).
- **정책 변화(RL Update)**: 생존 작가의 화풍을 무단으로 복제하여 상업적으로 이용하는 행위에 대한 저작권 분쟁이 격화됨에 따라, 특정 화풍 사용 시 원천 작가에게 로열티를 배분하거나 AI 학습 데이터 출처를 명시하는 '디지털 아트 저작권 보호 정책'이 강화됨.
### 매 evolution
- **Fast NST** (Johnson 2016): feedforward network 의 single forward pass.
- **AdaIN** (Huang 2017): Adaptive Instance Normalization — 매 arbitrary style 의 real-time.
- **Diffusion-based** (2023+): IP-Adapter, ControlNet — 매 prompt + reference 의 zero-shot.
## 🔗 지식 연결 (Graph)
- [[Visual-Effects-VFX|Visual-Effects-VFX]], [[Roughness (그래픽 및 물리)|Roughness (그래픽 및 물리)]], [[Computer-Vision|Computer-Vision]], [[Straightening|Straightening]], [[Prompt-Engineering|Prompt-Engineering]]
- **Modern Tech/Tools**: DeepArt, Prisma, Stable Diffusion (Style adapter), PyTorch Style Transfer.
---
### 매 응용
1. Artistic image generation (Prisma, DeepArt — 매 historical).
2. Midjourney --sref / --cref — 매 mainstream creative tool.
3. Video stylization (Runway, Kaiber).
4. Domain adaptation (synthetic → real).
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
## 💻 패턴
**언제 이 지식을 쓰는가:**
- *(TODO)*
### Gram matrix (style representation)
```python
import torch
import torch.nn as nn
**언제 쓰면 안 되는가:**
- *(TODO)*
def gram_matrix(features):
b, c, h, w = features.shape
feat = features.view(b, c, h * w)
gram = torch.bmm(feat, feat.transpose(1, 2))
return gram / (c * h * w)
```
## 🧪 검증 상태 (Validation)
### AdaIN
```python
def adain(content_feat, style_feat, eps=1e-5):
c_mean = content_feat.mean(dim=[2, 3], keepdim=True)
c_std = content_feat.std(dim=[2, 3], keepdim=True) + eps
s_mean = style_feat.mean(dim=[2, 3], keepdim=True)
s_std = style_feat.std(dim=[2, 3], keepdim=True) + eps
normalized = (content_feat - c_mean) / c_std
return normalized * s_std + s_mean
```
- **정보 상태:** needs_review
- **출처 신뢰도:** A
- **검토 이유:** *(P-Reinforce Phase 1 자동 정규화. 본문 검증 필요.)*
### Gatys optimization (full)
```python
import torch.optim as optim
from torchvision.models import vgg19
## 🧬 중복 검사 (Duplicate Check)
vgg = vgg19(pretrained=True).features.eval().cuda()
target = content_img.clone().requires_grad_(True)
optimizer = optim.LBFGS([target])
- **기존 유사 문서:** *(TODO: 인덱서 클러스터 리포트 참조)*
- **처리 방식:** UPDATE (자동 정규화)
- **처리 이유:** Phase 1 정규화 — 옛 템플릿/누락 필드 보강.
def closure():
optimizer.zero_grad()
feats = extract_features(target, vgg)
c_loss = F.mse_loss(feats['content'], content_feats['content'])
s_loss = sum(F.mse_loss(gram_matrix(feats[l]), gram_matrix(style_feats[l]))
for l in style_layers)
loss = c_loss + 1e6 * s_loss
loss.backward()
return loss
## 🕓 변경 이력 (Changelog)
for _ in range(300):
optimizer.step(closure)
```
| 날짜 | 변경 내용 | 처리 방식 | 신뢰도 |
|------|-----------|-----------|--------|
| 2026-05-08 | P-Reinforce Phase 1 정규화 (frontmatter + 헤더 표준화) | UPDATE | A |
### IP-Adapter (diffusion-based, 2024+)
```python
from diffusers import StableDiffusionPipeline
from ip_adapter import IPAdapter
pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5").to("cuda")
ip_model = IPAdapter(pipe, "h94/IP-Adapter", "models/ip-adapter_sd15.bin", "cuda")
style_ref = Image.open("vangogh.jpg")
images = ip_model.generate(pil_image=style_ref, prompt="a cat", num_samples=4, scale=0.7)
```
### Midjourney --sref (2026 mainstream)
```
/imagine prompt: a serene lake at sunset --sref https://example.com/style.jpg --sw 100
```
## 매 결정 기준
| 상황 | Approach |
|---|---|
| 매 일회성 art experiment | Gatys (구현 simple, slow ok) |
| 매 real-time / video | AdaIN, fast NST |
| 매 production creative | IP-Adapter + SDXL / FLUX |
| 매 non-coder creative | Midjourney --sref |
| 매 controllable structure + style | ControlNet + IP-Adapter combo |
**기본값**: 매 2026 의 IP-Adapter (open) 또는 Midjourney --sref (closed).
## 🔗 Graph
- 부모: [[Generative-AI]] · [[Computer-Vision]]
- 변형: [[Style_Reference_(--sref)]] · [[ControlNet]] · [[IP-Adapter]]
- 응용: [[Image-Generation]] · [[Video-Stylization]]
- Adjacent: [[Diffusion-Models]] · [[VGG-Network]] · [[Gram-Matrix]]
## 🤖 LLM 활용
**언제**: 매 creative pipeline 의 style consistency, brand asset variant 생성, mood board 의 visual exploration.
**언제 X**: 매 photo retouching (use Lightroom), 매 strict color grading (use LUTs), 매 face identity preservation 의 unstable.
## ❌ 안티패턴
- **Style weight 무한 증가**: 매 content 가 사라짐. balance 필수 (1e6 typical).
- **Single VGG layer**: 매 multi-scale style 의 lost. 매 multiple layer aggregate.
- **Diffusion 의 prompt 무시**: IP-Adapter scale 너무 높으면 prompt 의 무시. scale 0.5-0.8 sweet spot.
## 🧪 검증 / 중복
- Verified (Gatys et al. 2015 "A Neural Algorithm of Artistic Style"; Huang & Belongie 2017 AdaIN; Ye et al. 2023 IP-Adapter).
- 신뢰도 A.
## 🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — Gatys → AdaIN → diffusion (IP-Adapter, --sref) coverage |