File size: 2,515 Bytes
f38aa9b ee3b201 f38aa9b ee3b201 f38aa9b ee3b201 f38aa9b ee3b201 f38aa9b ee3b201 f38aa9b ee3b201 f38aa9b ee3b201 f38aa9b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | ---
license: mit
tags:
- image-classification
- mnist
- cnn
- resnet
- pytorch
- experiment
pipeline_tag: image-classification
---
# 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](RESULTS.md), ๋ฐ์ดํฐ ์ถ์ฒ๋ [DATA.md](DATA.md) ์ฐธ์กฐ.
## How to use
```python
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
```bash
# ์: 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 ์๋ ๋ค์ด๋ก๋)
```
## ์ฌํ ํ๊ฒฝ
```bash
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)
|