Upload 6 files
Browse files- README.md +109 -10
- __pycache__/model_2025.cpython-313.pyc +0 -0
- app.py +238 -0
- model_2015.py +165 -0
- model_2025.py +27 -0
- requirements.txt +22 -0
README.md
CHANGED
|
@@ -1,13 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|