a0 β€” 순수 CNN vs Residual CNN (MNIST)

깊이λ₯Ό 늘린 순수 CNN의 ν•œκ³„(degradation 문제)λ₯Ό ν™•μΈν•˜κ³ , residual connection이 이λ₯Ό ν•΄κ²°ν•˜λŠ”μ§€ κ²€μ¦ν•œ μ‹€ν—˜ ν”„λ‘œμ νŠΈ. PyTorch둜 μ²˜μŒλΆ€ν„° κ΅¬ν˜„.

Model Description

  • Task: MNIST 손글씨 숫자 λΆ„λ₯˜ (28Γ—28, 10 classes)
  • Architecture: 채널 64 κ³ μ •μ˜ conv μŠ€νƒ. depth = 블둝 수(블둝당 conv 2개)
    • PlainBlock: Conv β†’ BN β†’ ReLU β†’ Conv β†’ BN β†’ ReLU
    • ResBlock: μœ„ ꡬ쑰 + skip connection (out + x)
  • ν•™μŠ΅: Adam (lr=1e-3) + CosineAnnealingLR, batch=128, 15 epochs
  • κ°€μ€‘μΉ˜λŠ” runs/depthN[_res][_nobn]/model.pt (PyTorch state_dict)에 μ €μž₯

Results

BatchNorm 있음 β€” best val accuracy

depth (blocks) plain CNN + residual
5 99.70% β€”
10 99.62% 99.58%
15 99.60% 99.52%
20 99.58% 99.66%
40 98.89% (λΆˆμ•ˆμ •) 99.56%

BatchNorm μ—†μŒ β€” best val accuracy

depth (blocks) plain CNN + residual
20 11.35% (λΆ•κ΄΄) 99.39%
40 11.35% (λΆ•κ΄΄) 99.40%

μžμ„Έν•œ 뢄석은 RESULTS.md, 데이터 μΆœμ²˜λŠ” DATA.md μ°Έμ‘°.

How to use

import torch
from src.model import CNN

model = CNN(depth=20, use_residual=True, bn=False)
model.load_state_dict(torch.load("runs/depth20_res_nobn/model.pt", weights_only=True))
model.eval()

Training details

# 예: depth20 plain CNN, BN μ—†μŒ
python src/train.py --depth 20 --no-bn --epochs 15

# 예: depth20 residual CNN, BN μ—†μŒ
python src/train.py --depth 20 --residual --no-bn --epochs 15

μ£Όμš” μ˜΅μ…˜: --depth(블둝 수), --residual, --no-bn, --channels, --epochs, --batch-size, --lr

ꡬ쑰

src/
  model.py           # PlainBlock / ResBlock / CNN λΉŒλ”
  train.py           # MNIST ν•™μŠ΅ 슀크립트
  plot_results.py    # runs/ 의 history.json β†’ 비ꡐ κ·Έλž˜ν”„ 생성
runs/                # μ‹€ν—˜λ³„ history.json + model.pt κ°€μ€‘μΉ˜
results/             # μ‹œκ°ν™” PNG
data/                # MNIST (git μ œμ™Έ, torchvision μžλ™ λ‹€μš΄λ‘œλ“œ)

μž¬ν˜„ ν™˜κ²½

python -m venv .venv
.venv/Scripts/pip install torch torchvision --index-url https://download.pytorch.org/whl/cu128

ν…ŒμŠ€νŠΈ ν™˜κ²½: PyTorch 2.11.0+cu128, NVIDIA RTX 5070 Ti (CUDA 12.8)

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support