Upload 2 files
Browse files- README.md +128 -1
- requirements.txt +3 -1
README.md
CHANGED
|
@@ -4,9 +4,136 @@ emoji: ๐
|
|
| 4 |
colorFrom: green
|
| 5 |
colorTo: gray
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
python_version: "3.10"
|
| 11 |
suggested_hardware: cpu-basic
|
| 12 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
colorFrom: green
|
| 5 |
colorTo: gray
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 5.0.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
python_version: "3.10"
|
| 11 |
suggested_hardware: cpu-basic
|
| 12 |
---
|
| 13 |
+
|
| 14 |
+
# Image Classification Demo โ 2015 vs 2025
|
| 15 |
+
**็ปๅๅ้กใใข โ 2015 vs 2025 ๅฎ่ฃ
ๆฏ่ผ**
|
| 16 |
+
|
| 17 |
+
A Gradio app that demonstrates how dramatically machine learning implementation
|
| 18 |
+
complexity has changed over a decade โ using the same task (image โ category
|
| 19 |
+
prediction) as a benchmark.
|
| 20 |
+
|
| 21 |
+
ๅใใฟในใฏ๏ผ็ปๅ โ ใซใใดใชไบๆธฌ๏ผใไฝฟใฃใฆใ10ๅนด้ใงๆฉๆขฐๅญฆ็ฟใฎๅฎ่ฃ
ใณในใใ
|
| 22 |
+
ใใใซๅคๅใใใใๆฏ่ผใใ Gradio ใใขใขใใชใงใใ
|
| 23 |
+
|
| 24 |
+
---
|
| 25 |
+
|
| 26 |
+
## What This App Does / ใใฎใขใใชใซใคใใฆ
|
| 27 |
+
|
| 28 |
+
Upload any image and get a top-5 category prediction from a pre-trained
|
| 29 |
+
Vision Transformer (ViT). Alongside the result, the app shows the code
|
| 30 |
+
required to build the same classifier in **2015 (Theano + NumPy, ~130 lines)**
|
| 31 |
+
versus **2025 (HuggingFace Transformers, 5 lines)**.
|
| 32 |
+
|
| 33 |
+
็ปๅใใขใใใญใผใใใใจใไบๅๅญฆ็ฟๆธใฟ ViT ใซใใไธไฝ5ไปถใฎไบๆธฌ็ตๆใ่กจ็คบใใพใใ
|
| 34 |
+
ใใใใฆใ**2015ๅนด๏ผTheano + NumPyใ็ด130่ก๏ผ** ใจ **2025ๅนด๏ผHuggingFace Transformersใ5่ก๏ผ**
|
| 35 |
+
ใฎๅฎ่ฃ
ใณใผใใๅทฆๅณใซไธฆในใฆๆฏ่ผใใพใใ
|
| 36 |
+
|
| 37 |
+
---
|
| 38 |
+
|
| 39 |
+
## Implementation Comparison / ๅฎ่ฃ
ๆฏ่ผ
|
| 40 |
+
|
| 41 |
+
| Item / ้
็ฎ | 2015 (Theano + NumPy) | 2025 (HuggingFace) |
|
| 42 |
+
|---|---|---|
|
| 43 |
+
| **Lines of code** / ๅฎ่ฃ
่กๆฐ | ~130 lines | 5 lines |
|
| 44 |
+
| **Model** / ใขใใซ | Hand-written CNN / ๆๆธใ CNN | ViT-Base (pre-trained) / ไบๅๅญฆ็ฟๆธใฟ |
|
| 45 |
+
| **Preprocessing** / ๅๅฆ็ | Manual / ๆๅๅฎ่ฃ
| Automatic / ่ชๅ |
|
| 46 |
+
| **Training** / ๅญฆ็ฟ | SGD written by hand / ๆๅ่จ่ฟฐ | Not required / ไธ่ฆ |
|
| 47 |
+
| **Accuracy** / ็ฒพๅบฆ็ฎๅฎ | ~70 % (CIFAR-10) | ~81 % (ImageNet) |
|
| 48 |
+
| **Compile step** / ใณใณใใคใซ | Tens of seconds / ๆฐๅ็ง | Not required / ไธ่ฆ |
|
| 49 |
+
|
| 50 |
+
---
|
| 51 |
+
|
| 52 |
+
## File Structure / ใใกใคใซๆงๆ
|
| 53 |
+
|
| 54 |
+
```
|
| 55 |
+
.
|
| 56 |
+
โโโ app.py # Gradio app โ entry point / ใจใณใใชใใคใณใ
|
| 57 |
+
โโโ model_2025.py # 2025 implementation: HuggingFace pipeline (5 lines)
|
| 58 |
+
โ # 2025 ๅฎ่ฃ
๏ผHuggingFace pipeline๏ผ5 ่ก๏ผ
|
| 59 |
+
โโโ model_2015.py # 2015 implementation: Theano CNN (reference / ๅ็
ง็จ)
|
| 60 |
+
โโโ requirements.txt # Dependencies / ไพๅญใใใฑใผใธ
|
| 61 |
+
โโโ README.md # This file / ใใฎใใกใคใซ
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
---
|
| 65 |
+
|
| 66 |
+
## Running Locally / ใญใผใซใซใงใฎ่ตทๅ
|
| 67 |
+
|
| 68 |
+
```bash
|
| 69 |
+
# 1. Clone / ใฏใญใผใณ
|
| 70 |
+
git clone https://huggingface.co/spaces/<your-username>/image-classification-2015-vs-2025
|
| 71 |
+
cd image-classification-2015-vs-2025
|
| 72 |
+
|
| 73 |
+
# 2. Install dependencies / ไพๅญใใคใณในใใผใซ
|
| 74 |
+
pip install -r requirements.txt
|
| 75 |
+
|
| 76 |
+
# 3. Launch / ่ตทๅ
|
| 77 |
+
python app.py
|
| 78 |
+
# โ http://localhost:7860
|
| 79 |
+
```
|
| 80 |
+
|
| 81 |
+
> **Note / ๆณจๆ:** On first launch, the ViT model (~330 MB) is downloaded from
|
| 82 |
+
> Hugging Face Hub automatically and cached in `~/.cache/huggingface/`.
|
| 83 |
+
>
|
| 84 |
+
> ๅๅ่ตทๅๆใซ ViT ใขใใซ๏ผ็ด330 MB๏ผใ HuggingFace Hub ใใ่ชๅใใฆใณใญใผใใใใ
|
| 85 |
+
> `~/.cache/huggingface/` ใซใญใฃใใทใฅใใใพใใ
|
| 86 |
+
|
| 87 |
+
---
|
| 88 |
+
|
| 89 |
+
## Hardware / ๅไฝ็ฐๅข
|
| 90 |
+
|
| 91 |
+
This Space runs on **CPU Basic** (free tier โ no GPU required).
|
| 92 |
+
ViT-Base inference on CPU typically takes **2โ5 seconds** per image.
|
| 93 |
+
|
| 94 |
+
ใใฎSpaceใฏ **CPU Basic**๏ผ็กๆๆ ๏ผใงๅไฝใใพใใGPU ใฏไธ่ฆใงใใ
|
| 95 |
+
CPU ไธใงใฎ ViT-Base ๆจ่ซใฏ 1 ๆใใใ **2ใ5็ง** ็จๅบฆใงใใ
|
| 96 |
+
|
| 97 |
+
| Resource | Spec |
|
| 98 |
+
|---|---|
|
| 99 |
+
| Hardware | CPU Basic (2 vCPU / 16 GB RAM) |
|
| 100 |
+
| GPU | None / ใชใ |
|
| 101 |
+
| Storage | Ephemeral (model cached via HF Hub) |
|
| 102 |
+
|
| 103 |
+
---
|
| 104 |
+
|
| 105 |
+
## About the 2015 Implementation / 2015ๅนดๅฎ่ฃ
ใซใคใใฆ
|
| 106 |
+
|
| 107 |
+
`model_2015.py` is **reference documentation only** โ it requires Python 3.8
|
| 108 |
+
and Theano 1.0, which are no longer maintained and incompatible with Python 3.9+.
|
| 109 |
+
The file is included to illustrate the implementation burden of the era.
|
| 110 |
+
|
| 111 |
+
`model_2015.py` ใฏ **ๅ็
ง็จใใญใฅใกใณใ** ใงใใPython 3.8 ใจ Theano 1.0 ใๅฟ
่ฆใงใ
|
| 112 |
+
็พๅจใฏใกใณใใใณในใใใฆใใใ Python 3.9 ไปฅ้ใงใฏๅไฝใใพใใใ
|
| 113 |
+
ๅฝๆใฎๅฎ่ฃ
ใณในใใ็คบใ่ณๆใจใใฆๅ้ฒใใฆใใพใใ
|
| 114 |
+
|
| 115 |
+
What had to be hand-written in 2015 / 2015ๅนดๅฝๆใซๆๆธใใๅฟ
่ฆใ ใฃใใใฎ:
|
| 116 |
+
- Weight initialization for each layer / ๅๅฑคใฎ้ใฟๅๆๅ
|
| 117 |
+
- Symbolic computation graph (conv โ pool โ softmax) / ใทใณใใซใฐใฉใ
|
| 118 |
+
- Loss function, gradient computation, SGD update rules / ๆๅคฑใปๅพ้
ใปSGDๆดๆฐๅ
|
| 119 |
+
- Theano function compilation / Theano ้ขๆฐใฎใณใณใใคใซ
|
| 120 |
+
- Image preprocessing (normalization, CHW transpose) / ็ปๅๅๅฆ็
|
| 121 |
+
- Training loop with manual batch splitting / ๆๅใใใๅๅฒใปๅญฆ็ฟใซใผใ
|
| 122 |
+
- Model save / load / ใขใใซใฎไฟๅญใป่ชญใฟ่พผใฟ
|
| 123 |
+
|
| 124 |
+
---
|
| 125 |
+
|
| 126 |
+
## Tech Stack / ๆ่กในใฟใใฏ
|
| 127 |
+
|
| 128 |
+
| Library | Version | Purpose / ็จ้ |
|
| 129 |
+
|---|---|---|
|
| 130 |
+
| `transformers` | โฅ 4.40 | ViT model & pipeline |
|
| 131 |
+
| `torch` | โฅ 2.2 | Inference backend / ๆจ่ซใใใฏ๏ฟฝ๏ฟฝ๏ฟฝใณใ |
|
| 132 |
+
| `Pillow` | โฅ 10.0 | Image I/O / ็ปๅๅ
ฅๅบๅ |
|
| 133 |
+
| `gradio` | โฅ 4.36 | Web UI |
|
| 134 |
+
|
| 135 |
+
---
|
| 136 |
+
|
| 137 |
+
## License / ใฉใคใปใณใน
|
| 138 |
+
|
| 139 |
+
MIT
|
requirements.txt
CHANGED
|
@@ -10,7 +10,9 @@ torchvision>=0.17.0 # ็ปๅๅคๆใฆใผใใฃใชใใฃ
|
|
| 10 |
Pillow>=10.0.0 # ็ปๅๅ
ฅๅบๅ
|
| 11 |
|
| 12 |
# โโ UI โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 13 |
-
gradio
|
|
|
|
|
|
|
| 14 |
|
| 15 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 16 |
# 2015 ๅฎ่ฃ
๏ผๅ็
ง็จใใญใฅใกใณใใจใใฆ model_2015.py ใๅ้ฒ๏ผ
|
|
|
|
| 10 |
Pillow>=10.0.0 # ็ปๅๅ
ฅๅบๅ
|
| 11 |
|
| 12 |
# โโ UI โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 13 |
+
# gradio 5.0 ไปฅ้ใง huggingface_hub ใจใฎไบๆๆงๅ้กใ่งฃๆถใใใ
|
| 14 |
+
# gradio 4.x ใงใฏ HfFolder ใ huggingface_hub 0.24+ ใงๅ้คใใใใใใจใฉใผใซใชใ
|
| 15 |
+
gradio>=5.0.0 # Web UI ใใฌใผใ ใฏใผใฏ
|
| 16 |
|
| 17 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 18 |
# 2015 ๅฎ่ฃ
๏ผๅ็
ง็จใใญใฅใกใณใใจใใฆ model_2015.py ใๅ้ฒ๏ผ
|