Msk7000 commited on
Commit
f791040
ยท
verified ยท
1 Parent(s): 6a931d6

Upload 2 files

Browse files
Files changed (2) hide show
  1. README.md +128 -1
  2. requirements.txt +3 -1
README.md CHANGED
@@ -4,9 +4,136 @@ emoji: ๐Ÿ”
4
  colorFrom: green
5
  colorTo: gray
6
  sdk: gradio
7
- sdk_version: 4.36.0
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>=4.36.0 # Web UI ใƒ•ใƒฌใƒผใƒ ใƒฏใƒผใ‚ฏ
 
 
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 ใ‚’ๅŽ้Œฒ๏ผ‰