Download RESULTS.md from shyo2/cnn0: direct link, hf CLI and curl.
- Browser
- Download file 3.5 kB
-
https://huggingface.co/shyo2/cnn0/resolve/main/RESULTS.md
- Command line
-
hf download hf://shyo2/cnn0/RESULTS.md
-
curl -L -o RESULTS.md https://huggingface.co/shyo2/cnn0/resolve/main/RESULTS.md
a0 โ ์์ CNN vs Residual CNN ์คํ ์ ๋ฆฌ
MNIST ๋ฐ์ดํฐ์ ์ผ๋ก ์์ CNN์ ๊น์ด ํ์ฅ ํ๊ณ(degradation ๋ฌธ์ )๋ฅผ ํ์ธํ๊ณ , residual connection์ด ์ด๋ฅผ ํด๊ฒฐํ๋์ง ๊ฒ์ฆํ ์คํ ๊ธฐ๋ก.
์คํ ํ๊ฒฝ
- GPU: NVIDIA GeForce RTX 5070 Ti (16GB)
- PyTorch 2.11.0+cu128, torchvision 0.26.0
- ๋ฐ์ดํฐ์ : MNIST (60k train / 10k test)
- ๊ณตํต ํ์ดํผํ๋ผ๋ฏธํฐ: Adam (lr=1e-3), CosineAnnealingLR, batch=128, epochs=15
depth= ๋ธ๋ก ์. ๊ฐ ๋ธ๋ก์ Conv-BN-ReLU ร2๋ก ๊ตฌ์ฑ๋์ด ์ค์ conv ๋ ์ด์ด ์๋1 + 2รdepth- ์ฑ๋ ์ 64 ๊ณ ์ , stem์์ stride 2๋ก 28ร28 โ 14ร14 ๋ค์ด์ํ ํ ๋์ผ ํด์๋ ์ ์ง
- global average pooling + linear classifier
๋ชจ๋ธ ๊ตฌ์กฐ
PlainBlock: Conv โ BN โ ReLU โ Conv โ BN โ ReLU
ResBlock: Conv โ BN โ ReLU โ Conv โ BN โ ( + input ) โ ReLU
--no-bn ์ต์
์ผ๋ก BatchNorm์ Identity๋ก ๊ต์ฒด ๊ฐ๋ฅ (๊ณ ์ ์ degradation ์คํ ์ฌํ์ฉ).
๊ฒฐ๊ณผ
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% |
๊ด์ฐฐ ๊ฒฐ๊ณผ
1. BN์ด ์์ผ๋ฉด MNIST์์๋ ํฌํ๋จ
๋ชจ๋ ์ค์ ์ด ~99.5% ๊ทผ์ฒ์ ๋๋ฌํด ์ต์ข ์ ํ๋ ์ฐจ์ด๋ ๋ ธ์ด์ฆ ์์ค. ๋ค๋ง depth๊ฐ ๊น์ด์ง์๋ก ์ด๊ธฐ ์๋ ด์ด ๋๋ ค์ง๋ ๊ฒฝํฅ์ด ์ผ๊ด๋๊ฒ ๊ด์ฐฐ๋จ:
- depth5 epoch1: loss=0.23, train_acc=95.2%
- depth20 epoch1: loss=0.61, train_acc=79.7%
- depth40 epoch1: loss=1.60, train_acc=37.9%
๋์ผ ์กฐ๊ฑด์ residual ๋ชจ๋ธ์ ๊น์ด์ ๋ฌด๊ดํ๊ฒ epoch1๋ถํฐ ~96% train_acc๋ก ๋น ๋ฅด๊ฒ ์๋ ด.
2. depth40 plain ๋ชจ๋ธ์ ํ์ต ๋ถ์์
epoch 11์์ loss๊ฐ 0.031 โ 0.478๋ก ๊ธ๋ฑํ๋ฉฐ train_acc๊ฐ 99.2% โ 84.1%๋ก ๋ถ๊ดด. ์ดํ ์ฌ์๋ ดํ์ผ๋ ์ต์ข 98.1%๋ก ๋ค๋ฅธ ๋ชจ๋ธ ๋๋น ๋ช ํํ ๋ฎ์. residual ๋ชจ๋ธ์ ๋์ผ ๊น์ด์์ ๋๊น์ง ์์ ์ .
3. BN ์ ๊ฑฐ ์ degradation์ด ๊ทน๋ช ํ๊ฒ ๋๋ฌ๋จ
plain CNN (depth20/40, no-BN): 15 epoch ๋ด๋ด loss=2.30, val_acc=11.35%๋ก ์์ ์ ์ง. ๋๋ค ์์ค(10%)๊ณผ ๋์ผ โ ๋คํธ์ํฌ๊ฐ ์ฌ์ค์ ํ์ต๋์ง ์์.
residual CNN (depth20/40, no-BN): 99.4% ๋ฌ์ฑ. BN ์์ด๋ ๊น์ด์ ๋ฌด๊ดํ๊ฒ ์ ์ ํ์ต.
โ residual connection์ด gradient์ identity path๋ฅผ ์ ๊ณตํด ๊น์ ๋คํธ์ํฌ์์๋ ์ ํธ ์ ํ์ ์ต์ ํ๊ฐ ๊ฐ๋ฅํ๊ฒ ํจ์ ํ์ธ.
์ฌํ ๋ฐฉ๋ฒ
# ์: depth20 plain, BN ์์
./.venv/Scripts/python src/train.py --depth 20 --no-bn --epochs 15
# ์: depth20 residual, BN ์์
./.venv/Scripts/python src/train.py --depth 20 --residual --no-bn --epochs 15
# ๊ทธ๋ํ ์์ฑ
./.venv/Scripts/python src/plot_results.py
๊ฒฐ๊ณผ๋ runs/depthN[_res][_nobn]/ ์ history.json(epoch๋ณ ์งํ)๊ณผ model.pt๋ก ์ ์ฅ.
์๊ฐํ ๊ฒฐ๊ณผ๋ results/ ์ PNG๋ก ์ ์ฅ.
๊ฒฐ๋ก
- ์์ CNN์ ๊น์ด๋ฅผ ๋๋ ค๋ ์ฑ๋ฅ์ด ๋ณด์ฅ๋์ง ์์ผ๋ฉฐ, BN ์ ๋ฌด์ ๋ฐ๋ผ ๋ถ์์ /๋ถ๊ดด๊ฐ ๋ฐ์
- residual connection์ ๋์ผ ๊น์ด์์ ์์ ์ ์ด๊ณ ๋น ๋ฅธ ์๋ ด์ ๊ฐ๋ฅํ๊ฒ ํจ
- "๊น๊ฒ ์๋ ๊ฒ" ์์ฒด๋ณด๋ค "์ ํธ๊ฐ ์ ํ๋ฅด๋ ๊ตฌ์กฐ"๊ฐ ๋ ์ค์ํ๋ค๋ ๊ฒ์ ์คํ์ผ๋ก ํ์ธ