Upload README.md
Browse files
README.md
CHANGED
|
@@ -1,112 +1,139 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
|
| 8 |
---
|
| 9 |
|
| 10 |
-
##
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 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 |
-
|
|
|
|
|
|
|
| 23 |
|
| 24 |
---
|
| 25 |
|
| 26 |
-
##
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
|
| 37 |
---
|
| 38 |
|
| 39 |
-
##
|
| 40 |
-
|
| 41 |
-
### 1. リポジトリを取得
|
| 42 |
|
| 43 |
-
```bash
|
| 44 |
-
git clone <this-repo>
|
| 45 |
-
cd imgclf_app
|
| 46 |
```
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
```
|
| 55 |
|
| 56 |
-
|
| 57 |
-
> ```bash
|
| 58 |
-
> pip install torch torchvision --index-url https://download.pytorch.org/whl/cu121
|
| 59 |
-
> ```
|
| 60 |
|
| 61 |
-
##
|
| 62 |
|
| 63 |
```bash
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
python app.py
|
|
|
|
| 65 |
```
|
| 66 |
|
| 67 |
-
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
---
|
| 71 |
|
| 72 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
|
|
|
| 78 |
|
| 79 |
---
|
| 80 |
|
| 81 |
-
## 2015 実装
|
| 82 |
|
| 83 |
-
`model_2015.py`
|
| 84 |
-
|
| 85 |
-
|
| 86 |
|
| 87 |
-
|
|
|
|
|
|
|
| 88 |
|
| 89 |
-
-
|
| 90 |
-
-
|
| 91 |
-
-
|
| 92 |
-
-
|
| 93 |
-
-
|
| 94 |
-
-
|
| 95 |
-
-
|
|
|
|
| 96 |
|
| 97 |
---
|
| 98 |
|
| 99 |
-
## 技術スタック
|
| 100 |
|
| 101 |
-
|
|
| 102 |
|---|---|---|
|
| 103 |
-
| `transformers` | ≥ 4.40 | ViT
|
| 104 |
-
| `torch` | ≥ 2.2 | 推論バックエンド |
|
| 105 |
-
| `Pillow` | ≥ 10.0 | 画像入出力 |
|
| 106 |
| `gradio` | ≥ 4.36 | Web UI |
|
| 107 |
|
| 108 |
---
|
| 109 |
|
| 110 |
-
## ライセンス
|
| 111 |
|
| 112 |
MIT
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Image Classification 2015 vs 2025
|
| 3 |
+
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 |
+
---
|
| 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
|