cnn0 / README.md
shyo2's picture
Devin
Add HF model card with metadata and results tables
f38aa9b
|
Raw History Blame Contribute Delete
2.52 kB
---
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)