Msk7000 commited on
Commit
a60082f
ยท
verified ยท
1 Parent(s): 20f1e50

Upload 6 files

Browse files
Files changed (6) hide show
  1. README.md +109 -10
  2. __pycache__/model_2025.cpython-313.pyc +0 -0
  3. app.py +238 -0
  4. model_2015.py +165 -0
  5. model_2025.py +27 -0
  6. requirements.txt +22 -0
README.md CHANGED
@@ -1,13 +1,112 @@
 
 
 
 
 
 
 
1
  ---
2
- title: Image Clf App Implementation Comparison
3
- emoji: ๐Ÿƒ
4
- colorFrom: yellow
5
- colorTo: green
6
- sdk: gradio
7
- sdk_version: 6.15.2
8
- python_version: '3.13'
9
- app_file: app.py
10
- pinned: false
 
 
 
 
 
 
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ็”ปๅƒๅˆ†้กžใƒ‡ใƒข โ€” 2015 vs 2025 ๅฎŸ่ฃ…ๆฏ”่ผƒ
2
+
3
+ ๅŒใ˜ๆฉŸ่ƒฝ๏ผˆ็”ปๅƒ โ†’ ใ‚ซใƒ†ใ‚ดใƒชไบˆๆธฌ๏ผ‰ใ‚’ **2 ไธ–ไปฃใฎๅฎŸ่ฃ…**ใงไธฆในใฆ่ฆ‹ๆฏ”ในใ‚‹ใŸใ‚ใฎๆ•™ๆใƒปใƒ‡ใƒขใ‚ขใƒ—ใƒชใงใ™ใ€‚
4
+
5
+ ๆŽจ่ซ–ใฏ 2025 ๅฎŸ่ฃ…๏ผˆHuggingFace ViT๏ผ‰ใŒๆ‹…ใ„ใ€2015 ๅฎŸ่ฃ…๏ผˆTheano CNN๏ผ‰ใฏ
6
+ ๅฎŸ่ฃ…ใ‚ณใƒผใƒ‰ใ‚’ๅ‚็…ง่กจ็คบใ—ใพใ™ใ€‚
7
+
8
  ---
9
+
10
+ ## ๅฎŸ่ฃ…ๆฏ”่ผƒใ‚ตใƒžใƒชใƒผ
11
+
12
+ | ้ …็›ฎ | 2015๏ผˆTheano + NumPy๏ผ‰ | 2025๏ผˆHuggingFace Transformers๏ผ‰ |
13
+ |---|---|---|
14
+ | **ๅฎŸ่ฃ…่กŒๆ•ฐ** | ็ด„ 130 ่กŒ | 5 ่กŒ |
15
+ | **ใƒขใƒ‡ใƒซ** | ๆ‰‹ๆ›ธใ CNN | ViT-Base๏ผˆไบ‹ๅ‰ๅญฆ็ฟ’ๆธˆ๏ผ‰ |
16
+ | **ๅ‰ๅ‡ฆ็†** | ๆ‰‹ๅ‹•ๅฎŸ่ฃ…๏ผˆๆญฃ่ฆๅŒ–ใƒปCHWๅค‰ๆ›๏ผ‰ | ่‡ชๅ‹• |
17
+ | **ๅญฆ็ฟ’** | SGDใƒปใƒซใƒผใƒ—ใƒปๅ‹พ้…่จˆ็ฎ—ใ‚’ๆ‰‹ๅ‹•่จ˜่ฟฐ | ไธ่ฆ๏ผˆFine-tuning ใฏๅˆฅ้€”๏ผ‰ |
18
+ | **็ฒพๅบฆ็›ฎๅฎ‰** | ~70 % (CIFAR-10) | ~81 % (ImageNet) |
19
+ | **ใ‚ณใƒณใƒ‘ใ‚คใƒซ** | Theano ใ‚ฐใƒฉใƒ•ๆœ€้ฉๅŒ–๏ผˆๆ•ฐๅ็ง’๏ผ‰ | ไธ่ฆ |
20
+ | **Python ๅฏพๅฟœ** | Python 3.8 ไปฅไธ‹ | Python 3.10ใ€œ3.12 |
21
+
22
+ > ็ด„ **26 ๅ€**ใฎใ‚ณใƒผใƒ‰้‡ใฎๅทฎใงใ€ๅŒใ˜ๆŽจ่ซ–ๆฉŸ่ƒฝใ‚’ๅฎŸ็พใงใใ‚‹ใ‚ˆใ†ใซใชใ‚Šใพใ—ใŸใ€‚
23
+
24
  ---
25
 
26
+ ## ใƒ•ใ‚กใ‚คใƒซๆง‹ๆˆ
27
+
28
+ ```
29
+ imgclf_app/
30
+ โ”œโ”€โ”€ app.py # Gradio Web ใ‚ขใƒ—ใƒช๏ผˆใ‚จใƒณใƒˆใƒชใƒใ‚คใƒณใƒˆ๏ผ‰
31
+ โ”œโ”€โ”€ model_2025.py # 2025 ๅฎŸ่ฃ…๏ผšHuggingFace pipeline๏ผˆ5 ่กŒ๏ผ‰
32
+ โ”œโ”€โ”€ model_2015.py # 2015 ๅฎŸ่ฃ…๏ผšTheano CNN๏ผˆๅ‚็…ง็”จใƒ‰ใ‚ญใƒฅใƒกใƒณใƒˆ๏ผ‰
33
+ โ”œโ”€โ”€ requirements.txt # ไพๅญ˜ใƒ‘ใƒƒใ‚ฑใƒผใ‚ธ
34
+ โ””โ”€โ”€ README.md # ใ“ใฎใƒ•ใ‚กใ‚คใƒซ
35
+ ```
36
+
37
+ ---
38
+
39
+ ## ใ‚ปใƒƒใƒˆใ‚ขใƒƒใƒ—
40
+
41
+ ### 1. ใƒชใƒใ‚ธใƒˆใƒชใ‚’ๅ–ๅพ—
42
+
43
+ ```bash
44
+ git clone <this-repo>
45
+ cd imgclf_app
46
+ ```
47
+
48
+ ### 2. ไปฎๆƒณ็’ฐๅขƒใ‚’ไฝœๆˆใ—ใฆไพๅญ˜ใ‚’ใ‚คใƒณใ‚นใƒˆใƒผใƒซ
49
+
50
+ ```bash
51
+ python -m venv .venv
52
+ source .venv/bin/activate # Windows: .venv\Scripts\activate
53
+ pip install -r requirements.txt
54
+ ```
55
+
56
+ > **GPU ใ‚’ไฝฟใ†ๅ ดๅˆ**๏ผˆไปปๆ„๏ผ‰๏ผš`torch` ใ‚’ CUDA ็‰ˆใซๅทฎใ—ๆ›ฟใˆใ‚‹ใจๆŽจ่ซ–ใŒ้ซ˜้€Ÿใซใชใ‚Šใพใ™ใ€‚
57
+ > ```bash
58
+ > pip install torch torchvision --index-url https://download.pytorch.org/whl/cu121
59
+ > ```
60
+
61
+ ### 3. ่ตทๅ‹•
62
+
63
+ ```bash
64
+ python app.py
65
+ ```
66
+
67
+ ใƒ–ใƒฉใ‚ฆใ‚ถใง `http://localhost:7860` ใ‚’้–‹ใใพใ™ใ€‚
68
+ ๅˆๅ›ž่ตทๅ‹•ๆ™‚ใซ HuggingFace Hub ใ‹ใ‚‰ ViT ใƒขใƒ‡ใƒซ๏ผˆ็ด„ 330 MB๏ผ‰ใŒใƒ€ใ‚ฆใƒณใƒญใƒผใƒ‰ใ•ใ‚Œใพใ™ใ€‚
69
+
70
+ ---
71
+
72
+ ## ไฝฟใ„ๆ–น
73
+
74
+ 1. ๅทฆๅดใฎ็”ปๅƒใ‚ขใƒƒใƒ—ใƒญใƒผใƒ‰ใ‚จใƒชใ‚ขใซ็”ปๅƒใ‚’ใƒ‰ใƒญใƒƒใƒ—๏ผˆใพใŸใฏ้ธๆŠž๏ผ‰
75
+ 2. **โ–ถ ๅˆ†้กžใ‚’ๅฎŸ่กŒ** ใ‚’ใ‚ฏใƒชใƒƒใ‚ฏ๏ผˆใพใŸใฏ็”ปๅƒๅค‰ๆ›ดใง่‡ชๅ‹•ๅฎŸ่กŒ๏ผ‰
76
+ 3. ไบˆๆธฌ็ตๆžœ๏ผˆใ‚ซใƒ†ใ‚ดใƒชๅใจใ‚นใ‚ณใ‚ขไธŠไฝ 5 ไปถ๏ผ‰ใŒ่กจ็คบใ•ใ‚Œใ‚‹
77
+ 4. ๅณๅดใง 2015 / 2025 ใฎใ‚ณใƒผใƒ‰ใ‚’ไธฆในใฆ็ขบ่ช
78
+
79
+ ---
80
+
81
+ ## 2015 ๅฎŸ่ฃ…๏ผˆ`model_2015.py`๏ผ‰ใซใคใ„ใฆ
82
+
83
+ `model_2015.py` ใฏ **Python 3.8 + Theano 1.0** ็’ฐๅขƒใงใฎใฟๅ‹•ไฝœใ—ใพใ™ใ€‚
84
+ ็พๅœจใฏ Theano ใฎ้–‹็™บใŒๅœๆญขใ•ใ‚ŒใฆใŠใ‚Šใ€Python 3.9 ไปฅ้™ใงใฏๅ‹•ไฝœใ—ใพใ›ใ‚“ใ€‚
85
+ ใ“ใฎใƒ•ใ‚กใ‚คใƒซใฏ**ๅฎŸ่ฃ…ใ‚ณใ‚นใƒˆใฎๆฏ”่ผƒใƒปๆ•™่‚ฒ็›ฎ็š„**ใฎใƒ‰ใ‚ญใƒฅใƒกใƒณใƒˆใจใ—ใฆๅŽ้Œฒใ—ใฆใ„ใพใ™ใ€‚
86
+
87
+ 2015 ๅนดๅฝ“ๆ™‚ใฏไปฅไธ‹ใ‚’ใ™ในใฆๆ‰‹ๆ›ธใใงๅฎŸ่ฃ…ใ™ใ‚‹ๅฟ…่ฆใŒใ‚ใ‚Šใพใ—ใŸใ€‚
88
+
89
+ - ้‡ใฟใฎๅˆๆœŸๅŒ–๏ผˆๅ„ๅฑคใฎ `W`, `b`๏ผ‰
90
+ - ใ‚ทใƒณใƒœใƒซใ‚ฐใƒฉใƒ•๏ผˆ`conv2d` โ†’ `pool` โ†’ `flatten` โ†’ `softmax`๏ผ‰
91
+ - ๆๅคฑ้–ขๆ•ฐใƒปๅ‹พ้…่จˆ็ฎ—ใƒปSGD ๆ›ดๆ–ฐๅ‰‡
92
+ - Theano ้–ขๆ•ฐใฎใ‚ณใƒณใƒ‘ใ‚คใƒซ
93
+ - ็”ปๅƒๅ‰ๅ‡ฆ็†๏ผˆๆญฃ่ฆๅŒ–ใƒปๆฌกๅ…ƒๅค‰ๆ›๏ผ‰
94
+ - ๅญฆ็ฟ’ใƒซใƒผใƒ—๏ผˆใƒใƒƒใƒๅˆ†ๅ‰ฒใƒปepoch ็ฎก็†๏ผ‰
95
+ - ใƒขใƒ‡ใƒซใฎไฟๅญ˜ใƒป่ชญใฟ่พผใฟ
96
+
97
+ ---
98
+
99
+ ## ๆŠ€่ก“ใ‚นใ‚ฟใƒƒใ‚ฏ
100
+
101
+ | ใƒฉใ‚คใƒ–ใƒฉใƒช | ใƒใƒผใ‚ธใƒงใƒณ | ็”จ้€” |
102
+ |---|---|---|
103
+ | `transformers` | โ‰ฅ 4.40 | ViT ใƒขใƒ‡ใƒซใƒปpipeline |
104
+ | `torch` | โ‰ฅ 2.2 | ๆŽจ่ซ–ใƒใƒƒใ‚ฏใ‚จใƒณใƒ‰ |
105
+ | `Pillow` | โ‰ฅ 10.0 | ็”ปๅƒๅ…ฅๅ‡บๅŠ› |
106
+ | `gradio` | โ‰ฅ 4.36 | Web UI |
107
+
108
+ ---
109
+
110
+ ## ใƒฉใ‚คใ‚ปใƒณใ‚น
111
+
112
+ MIT
__pycache__/model_2025.cpython-313.pyc ADDED
Binary file (943 Bytes). View file
 
app.py ADDED
@@ -0,0 +1,238 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Image Classification Demo โ€” 2015 vs 2025 Implementation Comparison
3
+ ็”ปๅƒๅˆ†้กžใƒ‡ใƒขใ‚ขใƒ—ใƒช โ€” 2015 vs 2025 ๅฎŸ่ฃ…ๆฏ”่ผƒ
4
+ ====================================================
5
+ Compares the same feature (image โ†’ category prediction) across two generations.
6
+ ๅŒใ˜ๆฉŸ่ƒฝ๏ผˆ็”ปๅƒ โ†’ ใ‚ซใƒ†ใ‚ดใƒชไบˆๆธฌ๏ผ‰ใ‚’ 2 ไธ–ไปฃใฎๅฎŸ่ฃ…ใงไธฆในใฆ่กจ็คบใ™ใ‚‹ใ€‚
7
+
8
+ Inference is handled by the 2025 implementation (HuggingFace ViT).
9
+ ๆŽจ่ซ–ใฏ 2025 ๅฎŸ่ฃ…๏ผˆHuggingFace ViT๏ผ‰ใŒๆ‹…ใ„ใ€
10
+ The 2015 implementation (Theano CNN) is shown as reference code.
11
+ 2015 ๅฎŸ่ฃ…๏ผˆTheano CNN๏ผ‰ใฏๅฎŸ่ฃ…ใ‚ณใƒผใƒ‰ใ‚’ๅ‚็…ง่กจ็คบใ™ใ‚‹ใ€‚
12
+
13
+ Usage / ่ตทๅ‹•ๆ–นๆณ•:
14
+ python app.py
15
+ """
16
+
17
+ import textwrap
18
+
19
+ import gradio as gr
20
+ from model_2025 import classify as classify_2025
21
+
22
+ # โ”€โ”€ Code snippets for display / ่กจ็คบ็”จใ‚ณใƒผใƒ‰ใ‚นใƒ‹ใƒšใƒƒใƒˆ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
23
+
24
+ CODE_2015 = textwrap.dedent("""\
25
+ # 2015 Implementation โ€” Theano + NumPy (excerpt, ~130 lines)
26
+ # 2015 ๅฎŸ่ฃ… โ€” Theano + NumPy๏ผˆๆŠœ็ฒ‹ใƒป็ด„ 130 ่กŒ๏ผ‰
27
+
28
+ # โถ Manually Initialize the Weights
29
+ # ้‡ใฟใ‚’ๆ‰‹ๅ‹•ใงๅˆๆœŸๅŒ–
30
+ W0 = theano.shared(np.random.normal(0, 0.01, (32,3,5,5)), 'W0')
31
+ W1 = theano.shared(np.random.normal(0, 0.01, (64,32,5,5)), 'W1')
32
+ W2 = theano.shared(np.random.normal(0, 0.01, (1600,512)), 'W2')
33
+ W3 = theano.shared(np.random.normal(0, 0.01, (512,10)), 'W3')
34
+ # ... b0, b1, b2, b3 defined in the same way / ๅŒๆง˜ใซๅฎš็พฉ ...
35
+
36
+ # โท Hand-write the Symbolic Computation Graph
37
+ # ใ‚ทใƒณใƒœใƒซใ‚ฐใƒฉใƒ•ใ‚’ๆ‰‹ๆ›ธใ
38
+ x = T.tensor4('x')
39
+ conv0 = T.tanh(pool.pool_2d(
40
+ conv2d(x, W0, filter_shape=(32,3,5,5))
41
+ + b0.dimshuffle('x',0,'x','x'),
42
+ ws=(2,2), ignore_border=True))
43
+ conv1 = T.tanh(pool.pool_2d(
44
+ conv2d(conv0, W1, filter_shape=(64,32,5,5))
45
+ + b1.dimshuffle('x',0,'x','x'),
46
+ ws=(2,2), ignore_border=True))
47
+ flat = conv1.flatten(2)
48
+ fc = T.tanh(T.dot(flat, W2) + b2)
49
+ out = T.nnet.softmax(T.dot(fc, W3) + b3)
50
+
51
+ # โธ Manually Define Loss, Gradients, and SGD Update Rules
52
+ # ๆๅคฑใƒปๅ‹พ้…ใƒปSGD ๆ›ดๆ–ฐๅ‰‡ใ‚’ๆ‰‹ๅ‹•ๅฎš็พฉ
53
+ loss = -T.mean(T.log(out)[T.arange(y.shape[0]), y])
54
+ grads = T.grad(loss, [W0,b0,W1,b1,W2,b2,W3,b3])
55
+ updates = [(p, p - 0.01*g) for p, g in zip(params, grads)]
56
+
57
+ # โน Compile Theano Functions (takes tens of seconds)
58
+ # Theano ้–ขๆ•ฐใ‚’ใ‚ณใƒณใƒ‘ใ‚คใƒซ๏ผˆๆ•ฐๅ็ง’ใ‹ใ‹ใ‚‹๏ผ‰
59
+ train_fn = theano.function([x, y], loss, updates=updates)
60
+ pred_fn = theano.function([x], T.argmax(out, axis=1))
61
+
62
+ # โบ Manually Implement Preprocessing
63
+ # ๅ‰ๅ‡ฆ็†ใ‚’ๆ‰‹ๅ‹•ๅฎŸ่ฃ…
64
+ def preprocess(path):
65
+ img = Image.open(path).convert('RGB').resize((32,32))
66
+ arr = (np.array(img)/255.0 - MEAN) / STD
67
+ return arr.transpose(2,0,1)[np.newaxis]
68
+
69
+ # โป Manually Implement the Training Loop
70
+ # ๅญฆ็ฟ’ใƒซใƒผใƒ—ใ‚’ๆ‰‹ๅ‹•ๅฎŸ่ฃ…
71
+ for epoch in range(200):
72
+ for batch in range(n // 50):
73
+ train_fn(X[batch], y[batch])
74
+
75
+ # โผ Run Inference / ๆŽจ่ซ–
76
+ idx = pred_fn(preprocess('cat.jpg'))[0]
77
+ return LABELS[idx]
78
+ """)
79
+
80
+ CODE_2025 = textwrap.dedent("""\
81
+ # 2025 Implementation โ€” HuggingFace Transformers (just 5 lines)
82
+ # 2025 ๅฎŸ่ฃ… โ€” HuggingFace Transformers๏ผˆๅฎŸ่ณช 5 ่กŒ๏ผ‰
83
+
84
+ from transformers import pipeline
85
+
86
+ # โถ Load a Pre-trained Model
87
+ # ไบ‹ๅ‰ๅญฆ็ฟ’ๆธˆใฟใƒขใƒ‡ใƒซใ‚’ใƒญใƒผใƒ‰
88
+ classifier = pipeline(
89
+ "image-classification",
90
+ model="google/vit-base-patch16-224",
91
+ )
92
+
93
+ # โท Run Inference (preprocessing & postprocessing are automatic)
94
+ # ๆŽจ่ซ–๏ผˆๅ‰ๅ‡ฆ็†ใƒปๅพŒๅ‡ฆ็†ใ™ในใฆ่‡ชๅ‹•๏ผ‰
95
+ result = classifier("cat.jpg", top_k=5)
96
+ # โ†’ [{'label': 'tabby cat', 'score': 0.923}, ...]
97
+ """)
98
+
99
+ # โ”€โ”€ Comparison table / ๆฏ”่ผƒ่กจ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
100
+
101
+ COMPARISON_MD = """\
102
+ | Item<br><small style="color:#999">้ …็›ฎ</small> | 2015 (Theano) | 2025 (HuggingFace) |
103
+ |---|---|---|
104
+ | **Lines of code**<br><small style="color:#999">ๅฎŸ่ฃ…่กŒๆ•ฐ</small> | ~130 lines | 5 lines |
105
+ | **Model**<br><small style="color:#999">ใƒขใƒ‡ใƒซ</small> | Hand-written CNN<br><small style="color:#999">ๆ‰‹ๆ›ธใ CNN</small> | ViT-Base (pre-trained)<br><small style="color:#999">ViT-Base๏ผˆไบ‹ๅ‰ๅญฆ็ฟ’ๆธˆ๏ผ‰</small> |
106
+ | **Preprocessing**<br><small style="color:#999">ๅ‰ๅ‡ฆ็†</small> | Manual<br><small style="color:#999">ๆ‰‹ๅ‹•ๅฎŸ่ฃ…</small> | Automatic<br><small style="color:#999">่‡ชๅ‹•</small> |
107
+ | **Training**<br><small style="color:#999">ๅญฆ็ฟ’</small> | SGD written by hand<br><small style="color:#999">SGD ๆ‰‹ๅ‹•่จ˜่ฟฐ</small> | Not required (fine-tuning is separate)<br><small style="color:#999">ไธ่ฆ๏ผˆFine-tuning ใฏๅˆฅ้€”๏ผ‰</small> |
108
+ | **Accuracy (approx.)**<br><small style="color:#999">็ฒพๅบฆ็›ฎๅฎ‰</small> | ~70 % (CIFAR-10) | ~81 % (ImageNet) |
109
+ | **Theano compile step**<br><small style="color:#999">ใ‚ณใƒณใƒ‘ใ‚คใƒซ</small> | Tens of seconds<br><small style="color:#999">ๆ•ฐๅ็ง’</small> | Not required<br><small style="color:#999">ไธ่ฆ</small> |
110
+ """
111
+
112
+ # โ”€โ”€ Inference function / ๆŽจ่ซ–้–ขๆ•ฐ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
113
+
114
+ def run_inference(image):
115
+ """Classify the uploaded image with ViT and return top-5 scores.
116
+ ใ‚ขใƒƒใƒ—ใƒญใƒผใƒ‰็”ปๅƒใ‚’ ViT ใงๅˆ†้กžใ—ใ€ใ‚นใ‚ณใ‚ขไธŠไฝ 5 ไปถใ‚’่ฟ”ใ™ใ€‚"""
117
+ if image is None:
118
+ return {}, CODE_2015, CODE_2025
119
+
120
+ results = classify_2025(image)
121
+ label_scores = {r["label"]: float(r["score"]) for r in results}
122
+ return label_scores, CODE_2015, CODE_2025
123
+
124
+
125
+ # โ”€โ”€ UI / UI ๅฎš็พฉ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
126
+
127
+ CSS = """
128
+ .code-2015 textarea { border-left: 3px solid #888780 !important; }
129
+ .code-2025 textarea { border-left: 3px solid #1D9E75 !important; }
130
+ .bilingual-label .label-wrap span {
131
+ display: block;
132
+ }
133
+ """
134
+
135
+ def _bi(en, ja):
136
+ """Return bilingual Markdown: English normal, Japanese small gray below."""
137
+ return f"{en}<br><small style='color:#999'>{ja}</small>"
138
+
139
+
140
+ with gr.Blocks(
141
+ title="Image Classification: 2015 vs 2025",
142
+ css=CSS,
143
+ theme=gr.themes.Default(
144
+ font=["BIZ UDPGothic", "Noto Sans JP", "sans-serif"],
145
+ primary_hue=gr.themes.colors.emerald,
146
+ ),
147
+ ) as demo:
148
+
149
+ gr.Markdown(
150
+ """
151
+ # Image Classification Demo โ€” 2015 vs 2025
152
+ <small style="color:#999">็”ปๅƒๅˆ†้กžใƒ‡ใƒข โ€” 2015 vs 2025 ๅฎŸ่ฃ…ๆฏ”่ผƒ</small>
153
+
154
+ **The same feature (image โ†’ category prediction) compared across two generations of implementation.**
155
+ <br><small style="color:#999">ๅŒใ˜ๆฉŸ่ƒฝ๏ผˆ็”ปๅƒ โ†’ ใ‚ซใƒ†ใ‚ดใƒชไบˆๆธฌ๏ผ‰ใ‚’ 2 ไธ–ไปฃใฎๅฎŸ่ฃ…ใงๆฏ”่ผƒใ™ใ‚‹ใ€‚</small>
156
+
157
+ Inference is handled by the 2025 implementation (ViT).
158
+ <br><small style="color:#999">ๆŽจ่ซ–ใฏ 2025 ๅฎŸ่ฃ…๏ผˆViT๏ผ‰ใŒๆ‹…ใ„ใพใ™ใ€‚</small>
159
+ """
160
+ )
161
+
162
+ with gr.Row():
163
+ # โ”€โ”€ Left column: upload + result โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
164
+ with gr.Column(scale=1):
165
+ img_input = gr.Image(
166
+ type="pil",
167
+ label="Upload an Image / ็”ปๅƒใ‚’ใ‚ขใƒƒใƒ—ใƒญใƒผใƒ‰",
168
+ height=280,
169
+ )
170
+ run_btn = gr.Button(
171
+ "โ–ถ Run Classification / ๅˆ†้กžใ‚’ๅฎŸ่กŒ",
172
+ variant="primary",
173
+ )
174
+ results_output = gr.Label(
175
+ num_top_classes=5,
176
+ label="Prediction Results (2025 implementation) / ไบˆๆธฌ็ตๆžœ๏ผˆ2025 ๅฎŸ่ฃ…๏ผ‰",
177
+ )
178
+
179
+ # โ”€โ”€ Right column: code comparison โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
180
+ with gr.Column(scale=2):
181
+ gr.Markdown(
182
+ """
183
+ ### Code Implementation Comparison
184
+ <small style="color:#999">ๅฎŸ่ฃ…ใ‚ณใƒผใƒ‰ใฎๆฏ”่ผƒ</small>
185
+
186
+ > Difference in lines of code required to implement the same inference feature.
187
+ > <small style="color:#999">ๅŒใ˜ๆŽจ่ซ–ๆฉŸ่ƒฝใ‚’ๅฎŸ่ฃ…ใ™ใ‚‹ใฎใซๅฟ…่ฆใชใ‚ณใƒผใƒ‰้‡ใฎๅทฎ</small>
188
+ """
189
+ )
190
+ with gr.Row():
191
+ with gr.Column():
192
+ gr.Markdown(
193
+ "**๐Ÿ•ฐ๏ธ 2015 Implementation โ€” Theano + NumPy (~130 lines)**"
194
+ "<br><small style='color:#999'>2015 ๅฎŸ่ฃ… โ€” Theano + NumPy๏ผˆ็ด„ 130 ่กŒ๏ผ‰</small>"
195
+ )
196
+ code_2015_box = gr.Code(
197
+ value=CODE_2015,
198
+ language="python",
199
+ label="",
200
+ lines=30,
201
+ interactive=False,
202
+ elem_classes=["code-2015"],
203
+ )
204
+ with gr.Column():
205
+ gr.Markdown(
206
+ "**โœ… 2025 Implementation โ€” HuggingFace Transformers (5 lines)**"
207
+ "<br><small style='color:#999'>2025 ๅฎŸ่ฃ… โ€” HuggingFace Transformers๏ผˆ5 ่กŒ๏ผ‰</small>"
208
+ )
209
+ code_2025_box = gr.Code(
210
+ value=CODE_2025,
211
+ language="python",
212
+ label="",
213
+ lines=30,
214
+ interactive=False,
215
+ elem_classes=["code-2025"],
216
+ )
217
+
218
+ gr.Markdown("---")
219
+ gr.Markdown(
220
+ "### Implementation Comparison Summary\n"
221
+ "<small style='color:#999'>ๅฎŸ่ฃ…ๆฏ”่ผƒใ‚ตใƒžใƒชใƒผ</small>"
222
+ )
223
+ gr.Markdown(COMPARISON_MD)
224
+
225
+ # Event binding / ใ‚คใƒ™ใƒณใƒˆ๏ฟฝ๏ฟฝใ‚คใƒณใƒ‰
226
+ run_btn.click(
227
+ fn=run_inference,
228
+ inputs=[img_input],
229
+ outputs=[results_output, code_2015_box, code_2025_box],
230
+ )
231
+ img_input.change(
232
+ fn=run_inference,
233
+ inputs=[img_input],
234
+ outputs=[results_output, code_2015_box, code_2025_box],
235
+ )
236
+
237
+ if __name__ == "__main__":
238
+ demo.launch()
model_2015.py ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ 2015 ๅฎŸ่ฃ…๏ผˆๅ‚็…ง็”จ๏ผ‰โ€” Theano + NumPy ใซใ‚ˆใ‚‹ๆ‰‹ๆ›ธใ CNN
3
+ ็พๅœจใฎ Theano ใฏ Python 3.12 ไปฅ้™ใงใฏๅ‹•ไฝœใ—ใชใ„ใŸใ‚ใ€
4
+ ใ“ใฎใƒ•ใ‚กใ‚คใƒซใฏใ‚ขใƒผใ‚ญใƒ†ใ‚ฏใƒใƒฃ่จ˜้Œฒใƒปๆฏ”่ผƒ็”จ้€”ใฎใƒ‰ใ‚ญใƒฅใƒกใƒณใƒˆใจใ—ใฆไฟๅญ˜ใ™ใ‚‹ใ€‚
5
+ ๅฎŸ้š›ใฎๆŽจ่ซ–ใฏ model_2025.py ใง่กŒใ†ใ€‚
6
+ """
7
+
8
+ # ---------------------------------------------------------------------------
9
+ # โ€ป ไปฅไธ‹ใฎใ‚ณใƒผใƒ‰ใฏ Python 3.8 / Theano 1.0 ็’ฐๅขƒใงใฎๅ‹•ไฝœใ‚’ๅ‰ๆใจใ™ใ‚‹
10
+ # ---------------------------------------------------------------------------
11
+
12
+ import numpy as np
13
+
14
+ try:
15
+ import theano
16
+ import theano.tensor as T
17
+ from theano.tensor.nnet import conv2d
18
+ from theano.tensor.signal import pool
19
+ THEANO_AVAILABLE = True
20
+ except ImportError:
21
+ THEANO_AVAILABLE = False
22
+
23
+ from PIL import Image
24
+ import pickle
25
+
26
+ # ใƒใ‚คใƒ‘ใƒผใƒ‘ใƒฉใƒกใƒผใ‚ฟ
27
+ LEARNING_RATE = 0.01
28
+ N_EPOCHS = 200
29
+ BATCH_SIZE = 50
30
+ N_CLASSES = 10
31
+
32
+ LABELS = [
33
+ "airplane", "automobile", "bird", "cat", "deer",
34
+ "dog", "frog", "horse", "ship", "truck",
35
+ ]
36
+
37
+ MEAN = np.array([0.485, 0.456, 0.406], dtype=np.float32)
38
+ STD = np.array([0.229, 0.224, 0.225], dtype=np.float32)
39
+
40
+
41
+ # โ”€โ”€ ใƒฆใƒผใƒ†ใ‚ฃใƒชใƒ†ใ‚ฃ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
42
+
43
+ def _shared_w(shape, name):
44
+ return theano.shared(
45
+ np.random.normal(0, 0.01, shape).astype(np.float32),
46
+ name=name,
47
+ )
48
+
49
+ def _shared_b(n, name):
50
+ return theano.shared(np.zeros(n, dtype=np.float32), name=name)
51
+
52
+
53
+ # โ”€โ”€ ใƒขใƒ‡ใƒซๆง‹็ฏ‰ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
54
+
55
+ def build_model():
56
+ if not THEANO_AVAILABLE:
57
+ raise RuntimeError(
58
+ "Theano ใŒใ‚คใƒณใ‚นใƒˆใƒผใƒซใ•ใ‚Œใฆใ„ใพใ›ใ‚“ใ€‚"
59
+ "Python 3.8 + Theano 1.0 ใฎ็’ฐๅขƒใŒๅฟ…่ฆใงใ™ใ€‚"
60
+ )
61
+
62
+ # ้‡ใฟใƒ‘ใƒฉใƒกใƒผใ‚ฟ
63
+ W0 = _shared_w((32, 3, 5, 5), "W0") # Conv 1
64
+ b0 = _shared_b(32, "b0")
65
+ W1 = _shared_w((64, 32, 5, 5), "W1") # Conv 2
66
+ b1 = _shared_b(64, "b1")
67
+ W2 = _shared_w((64 * 5 * 5, 512), "W2") # FC 1
68
+ b2 = _shared_b(512, "b2")
69
+ W3 = _shared_w((512, N_CLASSES), "W3") # ๅ‡บๅŠ›
70
+ b3 = _shared_b(N_CLASSES, "b3")
71
+
72
+ params = [W0, b0, W1, b1, W2, b2, W3, b3]
73
+
74
+ # ใ‚ทใƒณใƒœใƒซๅค‰ๆ•ฐ
75
+ x = T.tensor4("x")
76
+ y = T.ivector("y")
77
+
78
+ # ใƒ•ใ‚ฉใƒฏใƒผใƒ‰ใƒ‘ใ‚น๏ผˆๆ‰‹ๅ‹•ๅฎŸ่ฃ…๏ผ‰
79
+ conv0 = T.tanh(
80
+ pool.pool_2d(
81
+ conv2d(x, W0,
82
+ input_shape=(BATCH_SIZE, 3, 32, 32),
83
+ filter_shape=(32, 3, 5, 5))
84
+ + b0.dimshuffle("x", 0, "x", "x"),
85
+ ws=(2, 2), ignore_border=True,
86
+ )
87
+ )
88
+ conv1 = T.tanh(
89
+ pool.pool_2d(
90
+ conv2d(conv0, W1, filter_shape=(64, 32, 5, 5))
91
+ + b1.dimshuffle("x", 0, "x", "x"),
92
+ ws=(2, 2), ignore_border=True,
93
+ )
94
+ )
95
+ flat = conv1.flatten(2)
96
+ fc = T.tanh(T.dot(flat, W2) + b2)
97
+ out = T.nnet.softmax(T.dot(fc, W3) + b3)
98
+
99
+ # ๆๅคฑใƒปๅ‹พ้…ใƒปSGD ๆ›ดๆ–ฐๅ‰‡
100
+ loss = -T.mean(T.log(out)[T.arange(y.shape[0]), y])
101
+ pred = T.argmax(out, axis=1)
102
+ err = T.mean(T.neq(pred, y))
103
+ grads = T.grad(loss, params)
104
+ updates = [(p, p - LEARNING_RATE * g) for p, g in zip(params, grads)]
105
+
106
+ # Theano ้–ขๆ•ฐใฎใ‚ณใƒณใƒ‘ใ‚คใƒซ๏ผˆGPUใ‚ฐใƒฉใƒ•ๆœ€้ฉๅŒ–ใŒ่ตฐใ‚‹ใŸใ‚ๆ•ฐๅ็ง’ใ‹ใ‹ใ‚‹๏ผ‰
107
+ train_fn = theano.function([x, y], [loss, err], updates=updates)
108
+ pred_fn = theano.function([x], pred)
109
+
110
+ return params, train_fn, pred_fn
111
+
112
+
113
+ # โ”€โ”€ ๅ‰ๅ‡ฆ็† โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
114
+
115
+ def preprocess(image) -> np.ndarray:
116
+ """PIL.Image ใพใŸใฏ ใƒ‘ใ‚นใ‚’ๅ—ใ‘ๅ–ใ‚Šใ€(1, 3, 32, 32) ใฎ float32 ้…ๅˆ—ใ‚’่ฟ”ใ™ใ€‚"""
117
+ if isinstance(image, str):
118
+ image = Image.open(image)
119
+ img = image.convert("RGB").resize((32, 32))
120
+ arr = np.array(img, dtype=np.float32) / 255.0
121
+ arr = (arr - MEAN) / STD # ใƒใƒฃใƒณใƒใƒซใ”ใจใฎๆญฃ่ฆๅŒ–
122
+ arr = arr.transpose(2, 0, 1) # HWC โ†’ CHW
123
+ return arr[np.newaxis] # ใƒใƒƒใƒๆฌกๅ…ƒใ‚’่ฟฝๅŠ 
124
+
125
+
126
+ # โ”€โ”€ ๅญฆ็ฟ’ใƒซใƒผใƒ— โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
127
+
128
+ def fit(train_fn, X_train: np.ndarray, y_train: np.ndarray) -> None:
129
+ n = len(X_train)
130
+ for epoch in range(N_EPOCHS):
131
+ idx = np.random.permutation(n)
132
+ losses, errs = [], []
133
+ for i in range(n // BATCH_SIZE):
134
+ b = idx[i * BATCH_SIZE : (i + 1) * BATCH_SIZE]
135
+ l, e = train_fn(X_train[b], y_train[b])
136
+ losses.append(l)
137
+ errs.append(e)
138
+ print(
139
+ f"Epoch {epoch + 1:3d} / {N_EPOCHS} "
140
+ f"loss={np.mean(losses):.4f} "
141
+ f"err={np.mean(errs):.4f}"
142
+ )
143
+
144
+
145
+ # โ”€โ”€ ๆŽจ่ซ– โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
146
+
147
+ def classify(pred_fn, image) -> str:
148
+ arr = preprocess(image)
149
+ idx = pred_fn(arr)[0]
150
+ return LABELS[idx]
151
+
152
+
153
+ # โ”€โ”€ ใƒขใƒ‡ใƒซใฎไฟๅญ˜ / ่ชญใฟ่พผใฟ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
154
+
155
+ def save_model(params, path: str) -> None:
156
+ weights = [p.get_value() for p in params]
157
+ with open(path, "wb") as f:
158
+ pickle.dump(weights, f, protocol=2)
159
+
160
+
161
+ def load_model(params, path: str) -> None:
162
+ with open(path, "rb") as f:
163
+ weights = pickle.load(f)
164
+ for p, w in zip(params, weights):
165
+ p.set_value(w)
model_2025.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ 2025 ๅฎŸ่ฃ… โ€” HuggingFace Transformers ใ‚’ไฝฟใฃใŸ็”ปๅƒๅˆ†้กž
3
+ ๅฎŸ่ณช 5 ่กŒใงๅ‰ๅ‡ฆ็†ใƒปๆŽจ่ซ–ใƒปๅพŒๅ‡ฆ็†ใŒใ™ในใฆๅฎŒ็ตใ™ใ‚‹ใ€‚
4
+ """
5
+
6
+ from transformers import pipeline
7
+
8
+ # ใƒขใƒ‡ใƒซใฎใƒญใƒผใƒ‰๏ผˆๅˆๅ›žใฎใฟใƒ€ใ‚ฆใƒณใƒญใƒผใƒ‰๏ผ‰
9
+ classifier = pipeline(
10
+ "image-classification",
11
+ model="google/vit-base-patch16-224",
12
+ )
13
+
14
+
15
+ def classify(image) -> list[dict]:
16
+ """
17
+ Parameters
18
+ ----------
19
+ image : PIL.Image | str
20
+ PIL ็”ปๅƒใ‚ชใƒ–ใ‚ธใ‚งใ‚ฏใƒˆใ€ใพใŸใฏใƒ•ใ‚กใ‚คใƒซใƒ‘ใ‚นๆ–‡ๅญ—ๅˆ—
21
+
22
+ Returns
23
+ -------
24
+ list[dict]
25
+ [{"label": str, "score": float}, ...] ไธŠไฝ 5 ไปถ
26
+ """
27
+ return classifier(image, top_k=5)
requirements.txt ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
2
+ # ็”ปๅƒๅˆ†้กžใƒ‡ใƒขใ‚ขใƒ—ใƒช โ€” requirements.txt
3
+ # Python 3.10 ใ€œ 3.12 ๆŽจๅฅจ
4
+ # โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
5
+
6
+ # โ”€โ”€ 2025 ๅฎŸ่ฃ…๏ผˆๅ‹•ไฝœใซๅฟ…้ ˆ๏ผ‰ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
7
+ transformers>=4.40.0 # HuggingFace Transformers๏ผˆViT ใƒขใƒ‡ใƒซ๏ผ‰
8
+ torch>=2.2.0 # PyTorch ใƒใƒƒใ‚ฏใ‚จใƒณใƒ‰๏ผˆCPU ใงใ‚‚ๅ‹•ไฝœ๏ผ‰
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 ใ‚’ๅŽ้Œฒ๏ผ‰
17
+ # ๅฎŸ่กŒใซใฏ Python 3.8 + Theano 1.0 ใŒๅฟ…่ฆใชใŸใ‚ใ€็พ็’ฐๅขƒใงใฏๅ‹•ไฝœใ—ใพใ›ใ‚“ใ€‚
18
+ # ๆฏ”่ผƒใƒปๆ•™่‚ฒ็›ฎ็š„ใฎใ‚ณใƒผใƒ‰่จ˜้Œฒใจใ—ใฆไฟๅญ˜ใ—ใฆใ„ใพใ™ใ€‚
19
+ #
20
+ # theano==1.0.5 # Python 3.8 ไปฅไธ‹ใŒๅฟ…่ฆ
21
+ # numpy==1.19.5
22
+ # โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€