๐ก ํ ์ค ์์ฝ#
๋คํธ์ํฌ๊ฐ ๊น์ด์ง ๋ ๋ฐ์ํ๋ ์ต์ ํ ์ ํ(Degradation Problem) ํ์์ Identity Shortcut Connection ๊ธฐ๋ฐ ์์ฐจ ํ์ต $\mathcal{F}(\mathbf{x}) + \mathbf{x}$ ๊ตฌ์กฐ๋ก ์๋ฒฝํ ํด์ํ์ฌ 152์ธต ์ด์์ ๊ทน๋จ์ ์ฌ์ธต ์ ๊ฒฝ๋ง์ ์์ ์ ์ผ๋ก ํ๋ จ์ํค๊ณ ILSVRC 2015 1์๋ฅผ ๋ฌ์ฑํ๋ค.
๐ ๊ฐ์ ๋ฐ ํต์ฌ ๊ธฐ์ฌ (Key Contributions)#
- ์ ์: Kaiming He, Xiangyu Zhang, Shaoqing Ren, Jian Sun (Microsoft Research)
- ๋ฐํ๋ ๋: 2015 (arXiv:1512.03385, CVPR 2016)
- ์ฃผ์ ๊ธฐ์ฌ์ :
- ์์ฐจ ํ์ต (Residual Learning) ์ ๋ฆฝ: ๋ ์ด์ด๊ฐ ๋งคํ ํจ์ $\mathcal{H}(\mathbf{x})$๋ฅผ ์ง์ ๋งคํํ์ง ์๊ณ ์์ฐจ ํจ์ $\mathcal{F}(\mathbf{x}) = \mathcal{H}(\mathbf{x}) - \mathbf{x}$๋ง ๋ชจ๋ํฐ๋งํ๋๋ก ์์ ์ฌ์ ์ํ.
- Identity Shortcut Connection: ์ฐ์ฐ๋ ๋ฐ ์ถ๊ฐ ํ๋ผ๋ฏธํฐ๊ฐ 0์ธ ์คํต ์ปค๋ฅ์ ์ผ๋ก ์ญ์ ํ ๊ธฐ์ธ๊ธฐ๊ฐ ๊ทธ๋ผ๋์ธํธ ์์ค(Vanishing Gradient) ์์ด ์ ๊ณ์ธต์ผ๋ก ์งํต ์ ๋ฌ.
- Bottleneck ๊ตฌ์กฐ ์ ์: $1 \times 1 \to 3 \times 3 \to 1 \times 1$ ์ปจ๋ณผ๋ฃจ์ ๋ธ๋ก์ผ๋ก ์ฐ์ฐ ์ฐจ์์ ์ถ์ ํ ๋ณต์ํ์ฌ 50์ธต~152์ธต ๊น์ด์ ์ปดํจํ ํจ์จ ๊ทน๋ํ.
- ILSVRC & COCO 2015 ์ ๋ถ๋ฌธ ์๊ถ: Top-5 ์ค๋ฅ์จ 3.57% ๋ฌ์ฑ์ผ๋ก ๋ถ๋ฅ, ํ์ง, ์ธ๊ทธ๋ฉํ ์ด์ ๋ถ์ผ ๋ฐฑ๋ณธ์ ๊ธ๋ก๋ฒ ํ์ค ๋ฑ๊ทน.
๐ฏ ๊ด๋ จ ์ฐ๊ตฌ ํ๋ฆ ๋ฐ ๊ธฐ์กด ํ๊ณ (Related Work & Motivation)#
๊ด๋ จ ์ฐ๊ตฌ ํ๋ฆ#
- Plain CNN (VGG, GoogLeNet): ๋ ์ด์ด๋ฅผ 20์ธต ์ด์ ์์ ๊ฒฝ์ฐ ๊ณผ์ ํฉ์ด ์๋์๋ ๋ถ๊ตฌํ๊ณ ํ๋ จ ์ค์ฐจ(Training Error)์ ๊ฒ์ฆ ์ค์ฐจ๊ฐ ๋์์ ํญ์ฆํ๋ Degradation ํ์ ๋ฐ์.
- Highway Networks: Shortcut์ ๋ฐ์ดํฐ ์์กด์ Gating ํ๋ผ๋ฏธํฐ๋ฅผ ์ถ๊ฐํ์ฌ ๊ฒ์ดํธ๊ฐ ๋ซํ ๋ ์์ฐจ ํ์ต ์์ค.
- ResNet: ์๋ฌด๋ฐ ํ๋ผ๋ฏธํฐ๊ฐ ์๋ ์์ Identity Shortcut์ ์ ์งํ์ฌ ์๋ฐฑ ๋ ์ด์ด ๋จ์กฐ ์ฑ๋ฅ ํฅ์.
๐ ๋ชฉ์ฐจ#
- Chapter 1: Basic Residual Block & Identity Shortcut ์์
- Chapter 2: Projection Shortcut ($1 \times 1$ Conv) ์์
- Chapter 3: Bottleneck Block ($1 \times 1 \to 3 \times 3 \to 1 \times 1$) ์ฐ์ฐ
- Chapter 4: Global Average Pooling (GAP) & ๋ฐฑ๋ณธ ์ ๊ฒฝ๋ง
- Chapter 5: ์ฃผ์ ์คํ ๋ฐ ๊ฒฐ๊ณผ
- Chapter 6: ๊ฒฐ๋ก ๋ฐ ์์ฌ์
๐ ๏ธ Chapter 1: Basic Residual Block & Identity Shortcut ์์#
1. ์์ฝ#
๋ชฉํ ๋งคํ $\mathcal{H}(\mathbf{x})$๋ฅผ $\mathcal{F}(\mathbf{x}) + \mathbf{x}$๋ก ๋ถํดํ์ฌ ์์ฐจ $\mathcal{F}(\mathbf{x})$๋ง ํ์ตํ๋๋ก ๊ตฌ์ฑํฉ๋๋ค.
2. ์์ ๋ฐ ํ์ด์ฌ ์ฝ๋ ์ค๋ช #
$$\mathbf{y} = \mathcal{F}(\mathbf{x}, \{W_i\}) + \mathbf{x}$$$$\mathcal{F}(\mathbf{x}, \{W_i\}) = W_2 \cdot \text{ReLU}\big( \text{BN}(W_1 \mathbf{x}) \big)$$- $\mathbf{x}, \mathbf{y}$: ์์ฐจ ๋ธ๋ก์ ์ ์ถ๋ ฅ ํ ์
- $\mathcal{F}$: 2๊ฐ์ $3 \times 3$ Conv + BN + ReLU ๋ ์ด์ด๊ฐ ํ์ตํ๋ ์์ฐจ ํจ์
import torch
import torch.nn as nn
class BasicResidualBlock(nn.Module):
"""
ResNet-18 / ResNet-34์ฉ ๊ธฐ๋ณธ ์์ฐจ ๋ธ๋ก (Basic Block)
"""
def __init__(self, in_channels: int, out_channels: int, stride: int = 1):
super().__init__()
self.conv1 = nn.Conv2d(in_channels, out_channels, kernel_size=3, stride=stride, padding=1, bias=False)
self.bn1 = nn.BatchNorm2d(out_channels)
self.conv2 = nn.Conv2d(out_channels, out_channels, kernel_size=3, stride=1, padding=1, bias=False)
self.bn2 = nn.BatchNorm2d(out_channels)
self.relu = nn.ReLU(inplace=True)
def forward(self, x: torch.Tensor) -> torch.Tensor:
identity = x # Identity Shortcut Connection
out = self.conv1(x)
out = self.bn1(out)
out = self.relu(out)
out = self.conv2(out)
out = self.bn2(out)
# F(x) + x
out += identity
return self.relu(out)
# --- ์ฌ์ฉ ์์ ---
block = BasicResidualBlock(in_channels=64, out_channels=64)
x_in = torch.randn(2, 64, 56, 56)
print("Basic Residual Block ์ถ๋ ฅ Shape:", block(x_in).shape)๐ ๏ธ Chapter 2: Projection Shortcut ($1 \times 1$ Conv) ์์#
1. ์์ฝ#
์คํธ๋ผ์ด๋ ์ ์ฉ์ด๋ ์ฑ๋ ์ ๋ณ๊ฒฝ์ผ๋ก ์ธํด ์ ๋ ฅ $\mathbf{x}$์ ์์ฐจ $\mathcal{F}(\mathbf{x})$์ ์ฐจ์์ด ๋ค๋ฅผ ๋, $1 \times 1$ Conv $W_s$๋ฅผ ๊ณฑํด ์ฐจ์์ ๋ง์ถฅ๋๋ค.
2. ์์ ๋ฐ ํ์ด์ฌ ์ฝ๋ ์ค๋ช #
$$\mathbf{y} = \mathcal{F}(\mathbf{x}, \{W_i\}) + W_s \mathbf{x}$$import torch
import torch.nn as nn
class ProjectionResidualBlock(nn.Module):
"""
์ฐจ์/ํด์๋๊ฐ ๋ณ๊ฒฝ๋ ๋ Projection Shortcut (W_s)์ ํฌํจํ๋ ์์ฐจ ๋ธ๋ก
"""
def __init__(self, in_channels: int, out_channels: int, stride: int = 2):
super().__init__()
self.conv1 = nn.Conv2d(in_channels, out_channels, kernel_size=3, stride=stride, padding=1, bias=False)
self.bn1 = nn.BatchNorm2d(out_channels)
self.conv2 = nn.Conv2d(out_channels, out_channels, kernel_size=3, stride=1, padding=1, bias=False)
self.bn2 = nn.BatchNorm2d(out_channels)
# W_s 1x1 Conv Projection Shortcut
self.shortcut = nn.Sequential(
nn.Conv2d(in_channels, out_channels, kernel_size=1, stride=stride, bias=False),
nn.BatchNorm2d(out_channels)
)
self.relu = nn.ReLU(inplace=True)
def forward(self, x: torch.Tensor) -> torch.Tensor:
identity = self.shortcut(x) # W_s * x
out = self.conv1(x)
out = self.bn1(out)
out = self.relu(out)
out = self.conv2(out)
out = self.bn2(out)
out += identity
return self.relu(out)
# --- ์ฌ์ฉ ์์ ---
proj_block = ProjectionResidualBlock(in_channels=64, out_channels=128, stride=2)
x_in = torch.randn(2, 64, 56, 56)
print("Projection Residual Block ์ถ๋ ฅ Shape:", proj_block(x_in).shape)๐ ๏ธ Chapter 3: Bottleneck Block ($1 \times 1 \to 3 \times 3 \to 1 \times 1$) ์ฐ์ฐ#
1. ์์ฝ#
ResNet-50/101/152 ๋ฑ ๊น์ ์ํคํ ์ฒ์ ์ฐ์ฐ ๋น์ฉ์ ์ค์ด๊ธฐ ์ํด $1 \times 1$ Conv๋ก ์ฑ๋ ์ถ์ ํ $3 \times 3$ Conv ์ฐ์ฐ์ ์ํํ๊ณ ๋ค์ $1 \times 1$ Conv๋ก 4๋ฐฐ ํ์ถฉํฉ๋๋ค.
2. ์์ ๋ฐ ํ์ด์ฌ ์ฝ๋ ์ค๋ช #
$$\mathcal{F}_{\text{bottleneck}}(\mathbf{x}) = W_3 \cdot \text{ReLU}\Big( \text{BN}\big( W_2 \cdot \text{ReLU}( \text{BN}(W_1 \mathbf{x}) ) \big) \Big)$$$$\mathbf{y} = \text{ReLU}\big( \mathcal{F}_{\text{bottleneck}}(\mathbf{x}) + W_s \mathbf{x} \big)$$import torch
import torch.nn as nn
class BottleneckBlock(nn.Module):
"""
ResNet-50 / 101 / 152์ฉ ๋ณ๋ชฉ (Bottleneck) ์์ฐจ ๋ธ๋ก
"""
expansion: int = 4
def __init__(self, in_channels: int, base_channels: int, stride: int = 1):
super().__init__()
out_channels = base_channels * self.expansion
# 1x1 Conv (์ฐจ์ ์ถ์)
self.conv1 = nn.Conv2d(in_channels, base_channels, kernel_size=1, bias=False)
self.bn1 = nn.BatchNorm2d(base_channels)
# 3x3 Conv (ํน์ง ์ถ์ถ)
self.conv2 = nn.Conv2d(base_channels, base_channels, kernel_size=3, stride=stride, padding=1, bias=False)
self.bn2 = nn.BatchNorm2d(base_channels)
# 1x1 Conv (์ฐจ์ 4๋ฐฐ ๋ณต์)
self.conv3 = nn.Conv2d(base_channels, out_channels, kernel_size=1, bias=False)
self.bn3 = nn.BatchNorm2d(out_channels)
self.relu = nn.ReLU(inplace=True)
if stride != 1 or in_channels != out_channels:
self.shortcut = nn.Sequential(
nn.Conv2d(in_channels, out_channels, kernel_size=1, stride=stride, bias=False),
nn.BatchNorm2d(out_channels)
)
else:
self.shortcut = nn.Identity()
def forward(self, x: torch.Tensor) -> torch.Tensor:
identity = self.shortcut(x)
out = self.relu(self.bn1(self.conv1(x)))
out = self.relu(self.bn2(self.conv2(out)))
out = self.bn3(self.conv3(out))
out += identity
return self.relu(out)
# --- ์ฌ์ฉ ์์ ---
bottleneck = BottleneckBlock(in_channels=256, base_channels=64, stride=1)
x_in = torch.randn(2, 256, 56, 56)
print("Bottleneck Block ์ถ๋ ฅ Shape:", bottleneck(x_in).shape)๐ ๏ธ Chapter 4: Global Average Pooling (GAP) & ๋ฐฑ๋ณธ ์ ๊ฒฝ๋ง#
1. ์์ฝ#
๊ณต๊ฐ ํด์๋ $(H \times W)$ ์ ์ฒด๋ฅผ ํ๊ท ์ผ๋ก ์์ถํ๋ Global Average Pooling์ ํตํด ํ๋ผ๋ฏธํฐ๋ฅผ ํ๊ธฐ์ ์ผ๋ก ์ค์ด๊ณ ๋ถ๋ฅ๊ธฐ๋ก ์ ํํฉ๋๋ค.
2. ์์ ๋ฐ ํ์ด์ฌ ์ฝ๋ ์ค๋ช #
$$\mathbf{y}_{\text{gap}} = \frac{1}{H \times W} \sum_{h=1}^H \sum_{w=1}^W \mathbf{f}(h, w) \in \mathbb{R}^C$$import torch
import torch.nn as nn
class ResNet50BackboneClassifier(nn.Module):
"""
ResNet-50 ๊ตฌ์กฐ์ GAP ๋ฐ ์ ํ ๋ถ๋ฅ ํค๋ ํ์ดํ๋ผ์ธ
"""
def __init__(self, num_classes: int = 1000):
super().__init__()
self.gap = nn.AdaptiveAvgPool2d((1, 1))
self.fc = nn.Linear(2048, num_classes)
def forward(self, last_stage_feature: torch.Tensor) -> torch.Tensor:
"""
last_stage_feature: (B, 2048, H, W)
"""
pooled = self.gap(last_stage_feature) # (B, 2048, 1, 1)
flat = torch.flatten(pooled, 1) # (B, 2048)
logits = self.fc(flat) # (B, Num_classes)
return logits
# --- ์ฌ์ฉ ์์ ---
backbone_head = ResNet50BackboneClassifier(num_classes=1000)
feat_in = torch.randn(2, 2048, 7, 7)
print("ResNet GAP ๋ถ๋ฅ Logits Shape:", backbone_head(feat_in).shape)๐ ์ฃผ์ ์คํ ๋ฐ ๊ฒฐ๊ณผ (Experiments & Results)#
1. ImageNet-1K ๊ฒ์ฆ ์ธํธ ๋ฆฌ๋๋ณด๋ ์ฑ๋ฅ ๋น๊ต#
| ์๊ณ ๋ฆฌ์ฆ (Method) | ์ ๊ฒฝ๋ง ๊น์ด (Depth) | Top-1 ์ค๋ฅ์จ โ | Top-5 ์ค๋ฅ์จ โ | ํน์ง |
|---|---|---|---|---|
| VGG-16 | 16-Layers | 28.07% | 9.33% | ํ๋ผ๋ฏธํฐ 138M (๋น๋ํจ) |
| Plain-34 | 34-Layers | 28.54% | 10.02% | Degradation ์ต์ ํ ์คํจ |
| ResNet-34 | 34-Layers | 24.52% | 7.46% | 34์ธต ์ ์ ์ต์ ํ ์ฑ๊ณต |
| ResNet-152 (Ours) | 152-Layers | 21.43% | 5.71% (SOTA) | ILSVRC 2015 1์ ์๊ถ |
- ๊ฒฐ๊ณผ: ์์ฐจ ํ์ต ๊ตฌ์กฐ ๋์ ์ผ๋ก 152์ธต๊น์ง ๋คํธ์ํฌ ๊น์ด๋ฅผ ๋๋ ค๋ **Top-5 ์ค์ฐจ์จ 3.57%**๋ก ์๋์ SOTA ๊ฐฑ์ .
๐ก ๊ฒฐ๋ก ๋ฐ ์์ฌ์ (Conclusion & Insights)#
1. ๊ฒฐ๋ก #
ResNet์ ์์ฐจ ํ์ต(Residual Learning)์ด๋ผ๋ ํ์ ์ ์์ด๋์ด๋ก ๋ฅ๋ฌ๋ ์ญ์ฌ์ ๊ฐ์ฅ ์๋ํ ์ปดํจํฐ ๋น์ ๋ฐฑ๋ณธ ์ํคํ ์ฒ๋ฅผ ์ ๋ฆฝํ์ต๋๋ค.
2. ํ๊ณ์ ๋ฐ ์์ฌ์ด ์ #
- 1202์ธต ์คํ์์ ๋ณด๋ฏ ๊ณผ๋ํ๊ฒ ๊น์ ๋คํธ์ํฌ๋ ์์ ๋ฐ์ดํฐ์ ์์ ๊ณผ์ ํฉ๋ ์ ์์ด, “๊น์ด๊ฐ ํญ์ ์ ๋ฆฌํ๋ค"๋ ๊ฒฐ๋ก ์ ๋ฐ์ดํฐ ๊ท๋ชจ์ ์์กด์ ์ด๋ค.
- Identity mapping์ด ์ ์ต์ ํ์ ์ ๋ฆฌํ์ง์ ๋ํ ์ด๋ก ์ ์ค๋ช ์ ์คํ์ ๊ด์ฐฐ(์์ฐจ ๋ฐ์์ด ์๋ค)์ ๊ทธ์น๋ฉฐ, ์ดํ ์ฐ๊ตฌ(์: Identity Mappings in Deep Residual Networks)์์ ๋ ์ ๊ตํ๊ฒ ๋ถ์๋จ.
- Bottleneck ์ค๊ณ์ ์ฑ๋ ์ถ์ยท๋ณต์ ๋น์จ ๋ฑ ์ธ๋ถ ํ์ดํผํ๋ผ๋ฏธํฐ ์ ํ ๊ทผ๊ฑฐ๊ฐ ์ถฉ๋ถํ ์ค๋ช ๋์ง ์์ ์ ์ ์์ฝ๋ค.
์ฐธ๊ณ ์๋ฃ#
๊ด๋ จ ๋ ผ๋ฌธ: Attention Is All You Need, ViT, DETR