Files
2nd/10_Wiki/Topic_Programming/AI_and_ML/Pooling.md
T
Antigravity Agent 9148c358d0 docs(10_Wiki): 위키 전체 재구성 — Topic_* 폴더를 4개 카테고리로 통합 + 대규모 중복 제거
Topic_Agent/Topic_Blog/Topics/Topics_Biz/Topics_Meeting/Topics_Rag의 마크다운 지식 문서를
Topic_General/Topic_Programming/Topic_Graphic/Topic_Business 4개 카테고리로 재분류.

- 중복 제거: frontmatter의 status:duplicate/merged + duplicate_of/redirect_to 필드로
  자기 자신을 중복으로 선언한 리다이렉트 stub 1032개 제거, 완전 동일 내용 파일 472개 제거,
  동일 파일명·다른 내용 충돌 시 더 큰(완전한) 버전만 유지(162개 제거) — 총 1639개 중복 제거.
- 분류: 폴더 단위로 명확한 항목(AI_and_ML/Coding/Architecture 등 → Programming,
  Comfyui/Visual_Effects → Graphic, Topics_Biz/Topics_Meeting/사업 등 → Business,
  Poetic_Blog_Writing/창의성/Game_Design 등 → General)은 폴더 우선순위로,
  나머지 혼재 폴더(Topic_Agent/Topic_Blog/Topics 루트/Thinking & Reasoning/Other/UI_UX_Assets)는
  title/tags 키워드 스코어링으로 파일 단위 분류(불명확한 경우 General로 폴백).
  원본 폴더명은 "From_*" 서브폴더로 보존해 추적 가능성 유지.
- 최종 배치: Programming 2784 / General 1608 / Graphic 285 / Business 249 = 4926개 문서.
- 에이전트 운영 상태(.astra/.agent/.obsidian/sessions/memory/_company/docs/lessons/_shared/src)는
  지식 콘텐츠가 아니므로 재분류 대상에서 제외하고 원위치 유지.
- Topics/Topic_email(상위 보호 폴더 Topic_email과 파일명 100% 중복) 삭제 — 보호 폴더 자체는 미변경.
- 완전히 비게 된 Topic_Agent/Topic_Blog/Topics_Biz/Topics_Rag 폴더 제거.
2026-07-05 00:33:48 +09:00

5.4 KiB

id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
id title category status canonical_id aliases duplicate_of source_trust_level confidence_score verification_status tags raw_sources last_reinforced github_commit tech_stack
wiki-2026-0508-pooling Pooling 10_Wiki/Topics verified self
Max Pooling
Average Pooling
Global Pooling
none A 0.9 applied
deep-learning
cnn
pooling
downsampling
2026-05-10 pending
language framework
python pytorch

Pooling

매 한 줄

"매 spatial/sequence dimension downsample — invariance + receptive field 확대.". CNN 시대의 staple (max/avg pool), 매 modern Transformer는 거의 안 씀 (strided conv 또는 attention pooling). Global pool은 여전히 classification head 표준.

매 핵심

매 종류

  • Max Pooling: window 내 max — translation invariance, edge-preserve.
  • Average Pooling: window 평균 — smooth, all-pixel contribute.
  • Global Average Pooling (GAP): 매 entire feature map → 단일 값. ResNet/EfficientNet head.
  • Adaptive Pooling: output size fix → input size 무관 (PyTorch AdaptiveAvgPool2d).
  • Attention Pooling: weighted sum, learned weights — ViT [CLS] 또는 perceiver.
  • L_p Pooling, Stochastic Pooling, Mixed Pooling: less common, occasionally robust.

매 왜 사용

  • Downsampling: spatial size 줄여 compute / params 감소.
  • Invariance: small translation에 robust.
  • Receptive field 확대: deeper layer가 wider context 봄.
  • Overfitting 방지: parameter-free regularization 효과.

매 modern shift

  • 2020+ Transformer 시대 — 매 pool 자리에 strided conv (stage transition) 또는 patch merging (Swin) 또는 attention pooling.
  • ConvNeXt도 strided conv 사용.
  • GAP은 classification head에서 여전히 universal.

💻 패턴

Max / Avg pool 기본

import torch.nn as nn
maxp = nn.MaxPool2d(kernel_size=2, stride=2)   # H,W /2
avgp = nn.AvgPool2d(kernel_size=2, stride=2)

Global Average Pooling (classification head)

import torch.nn as nn
class Head(nn.Module):
    def __init__(self, c, n_cls):
        super().__init__()
        self.gap = nn.AdaptiveAvgPool2d(1)
        self.fc  = nn.Linear(c, n_cls)
    def forward(self, x):           # x: (B, C, H, W)
        x = self.gap(x).flatten(1)  # (B, C)
        return self.fc(x)

Adaptive pool (variable input size)

import torch, torch.nn as nn
pool = nn.AdaptiveAvgPool2d((7, 7))  # 항상 7x7 output
x = torch.randn(2, 64, 33, 41)       # 임의 spatial
y = pool(x)  # (2, 64, 7, 7)

Attention Pooling (ViT [CLS])

import torch, torch.nn as nn
class AttnPool(nn.Module):
    def __init__(self, d, heads=8):
        super().__init__()
        self.q = nn.Parameter(torch.randn(1, 1, d))
        self.attn = nn.MultiheadAttention(d, heads, batch_first=True)
    def forward(self, x):  # x: (B, N, D)
        B = x.size(0)
        q = self.q.expand(B, -1, -1)
        out, _ = self.attn(q, x, x)
        return out.squeeze(1)  # (B, D)

Patch Merging (Swin Transformer)

import torch, torch.nn as nn
class PatchMerging(nn.Module):
    def __init__(self, dim):
        super().__init__()
        self.norm = nn.LayerNorm(4*dim)
        self.reduction = nn.Linear(4*dim, 2*dim, bias=False)
    def forward(self, x):  # x: (B, H, W, C)
        x0 = x[:, 0::2, 0::2, :]; x1 = x[:, 1::2, 0::2, :]
        x2 = x[:, 0::2, 1::2, :]; x3 = x[:, 1::2, 1::2, :]
        x = torch.cat([x0,x1,x2,x3], -1)
        return self.reduction(self.norm(x))

1D pool (sequence / audio)

import torch.nn as nn
pool1d = nn.MaxPool1d(kernel_size=4, stride=4)  # (B, C, T) -> (B, C, T/4)
gap1d  = nn.AdaptiveAvgPool1d(1)

Set/Graph pooling (mean/max/sum)

import torch
def set_mean(x, mask):  # x:(B,N,D), mask:(B,N)
    m = mask.unsqueeze(-1).float()
    return (x*m).sum(1) / m.sum(1).clamp(min=1)

매 결정 기준

상황 Approach
Classification final feature Global Avg Pooling
Variable input image AdaptiveAvgPool2d
Edge-preserve detection Max Pool 또는 strided conv
Transformer stage transition Patch merging / strided conv
Set/sequence aggregation Attention pool
Audio waveform 1D max/avg pool 또는 strided conv

기본값: feature map → GAP, downsample → strided conv (modern).

🔗 Graph

🤖 LLM 활용

언제: CNN backbone에서 spatial reduce, classification head GAP, set/graph aggregation. 언제 X: dense prediction (segmentation, detection)에서 매 정보 손실 — skip connection 결합 또는 dilated conv 고려.

안티패턴

  • Pool then upsample for segmentation without skip: 매 detail 손실. U-Net skip 사용.
  • MaxPool everywhere in modern arch: 매 strided conv가 매 학습 가능 — 거의 dominant.
  • Flatten without GAP: classification head fully-connected로 들어가면 매 huge params + overfit.
  • Pool over tokens with [CLS] available: attention pool 또는 [CLS] readout 매 better.

🧪 검증 / 중복

  • Verified (PyTorch docs nn.MaxPool2d, AdaptiveAvgPool, Swin Transformer paper, ConvNeXt paper).
  • 신뢰도 A.

🕓 Changelog

날짜 변경
2026-05-08 Phase 1
2026-05-10 Manual cleanup — pooling types + modern shift to strided conv / attention pool