Spaces:
Sleeping
Sleeping
add lowercase readme.md
Browse files
readme.md
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Aircraft Classifier Model Comparison
|
| 3 |
+
emoji: βοΈ
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: gray
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 4.44.0
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# Aircraft Classifier β Model Comparison
|
| 13 |
+
|
| 14 |
+
A computer-vision web app that classifies images of 14 aircraft types and
|
| 15 |
+
compares three different approaches side-by-side:
|
| 16 |
+
|
| 17 |
+
1. **Custom fine-tuned ViT** β `google/vit-base-patch16-224` fine-tuned via
|
| 18 |
+
transfer learning on a custom aircraft dataset.
|
| 19 |
+
2. **CLIP zero-shot** β `openai/clip-vit-large-patch14`, open-source.
|
| 20 |
+
3. **OpenAI GPT-4o** β closed-source vision model called via the OpenAI API.
|
| 21 |
+
|
| 22 |
+
## Dataset
|
| 23 |
+
|
| 24 |
+
Custom dataset of 14 aircraft classes (60 images each, 840 total),
|
| 25 |
+
collected from **Wikimedia Commons** via its public API
|
| 26 |
+
(`download_data.py` / `download_missing.py`). All images are CC-licensed.
|
| 27 |
+
|
| 28 |
+
| Class | Train | Test |
|
| 29 |
+
|-----------------------------|------:|-----:|
|
| 30 |
+
| AH-64 Apache | 51 | 9 |
|
| 31 |
+
| Airbus A320 | 51 | 9 |
|
| 32 |
+
| Airbus A380 | 51 | 9 |
|
| 33 |
+
| ATR 72 | 51 | 9 |
|
| 34 |
+
| Northrop B-2 Spirit | 51 | 9 |
|
| 35 |
+
| Boeing 737 | 51 | 9 |
|
| 36 |
+
| Boeing 747 | 51 | 9 |
|
| 37 |
+
| Boeing 787 Dreamliner | 51 | 9 |
|
| 38 |
+
| Cessna 172 | 51 | 9 |
|
| 39 |
+
| Concorde | 51 | 9 |
|
| 40 |
+
| F-16 Fighting Falcon | 51 | 9 |
|
| 41 |
+
| MiG-21 | 51 | 9 |
|
| 42 |
+
| SR-71 Blackbird | 51 | 9 |
|
| 43 |
+
| V-22 Osprey | 51 | 9 |
|
| 44 |
+
|
| 45 |
+
The mix is intentionally varied: civilian airliners (737/747/787/A320/A380),
|
| 46 |
+
regional turboprop (ATR 72), small GA (Cessna 172), supersonic transport
|
| 47 |
+
(Concorde), modern jet fighters (F-16, MiG-21), stealth bomber (B-2),
|
| 48 |
+
strategic recon (SR-71), tiltrotor (V-22), and an attack helicopter (AH-64).
|
| 49 |
+
|
| 50 |
+
## Preprocessing
|
| 51 |
+
|
| 52 |
+
- Convert every image to RGB (Wikimedia files include RGBA / grayscale).
|
| 53 |
+
- Thumbnail to longest side 512 px on download (`Pillow.Image.thumbnail`).
|
| 54 |
+
- Model preprocessing via `AutoImageProcessor.from_pretrained("google/vit-base-patch16-224")`
|
| 55 |
+
β resize/center-crop to 224Γ224, ImageNet mean/std normalization.
|
| 56 |
+
- Random split: 80% train, 10% validation, 10% test (`seed=42`).
|
| 57 |
+
|
| 58 |
+
## Model & Training
|
| 59 |
+
|
| 60 |
+
- Base model: **google/vit-base-patch16-224** (Vision Transformer pre-trained
|
| 61 |
+
on ImageNet-21k, fine-tuned on ImageNet-1k).
|
| 62 |
+
- Transfer-learning strategy: **freeze the backbone**, train only the new
|
| 63 |
+
14-class classifier head (~11K trainable params out of ~86M).
|
| 64 |
+
- Hyperparameters: 10 epochs, batch size 16, learning rate `3e-4`, AdamW,
|
| 65 |
+
best-checkpoint selection on validation accuracy.
|
| 66 |
+
- Trainer: π€ `transformers.Trainer` (`train.py`).
|
| 67 |
+
|
| 68 |
+
### Evaluation
|
| 69 |
+
|
| 70 |
+
Numbers from a single training run on the held-out 10% test split (~84 images):
|
| 71 |
+
|
| 72 |
+
| Model | Test accuracy |
|
| 73 |
+
|--------------------------------|--------------:|
|
| 74 |
+
| Custom ViT (fine-tuned) | 0.611 |
|
| 75 |
+
| CLIP zero-shot (large/14) | ~0.55 (qualitativ) |
|
| 76 |
+
| OpenAI GPT-4o (vision) | ~0.85 (qualitativ) |
|
| 77 |
+
|
| 78 |
+
Custom-ViT-Zahl: tatsΓ€chlicher Test-Split (~84 Bilder, 10% Holdout, seed=42),
|
| 79 |
+
10 Epochen, nur 14-Klassen Klassifikator-Kopf trainiert. Validation-Accuracy: 0.690.
|
| 80 |
+
|
| 81 |
+
## Comparison results
|
| 82 |
+
|
| 83 |
+
- **Custom ViT** β fine-tuned on the in-domain Wikimedia images, learns
|
| 84 |
+
airline liveries and viewing angles typical of the dataset. Fast local
|
| 85 |
+
inference once loaded.
|
| 86 |
+
- **CLIP zero-shot** β recognizes broad categories ("airliner", "fighter",
|
| 87 |
+
"helicopter") well, but confuses similar narrowbodies (737 vs A320) and
|
| 88 |
+
some military variants without training.
|
| 89 |
+
- **GPT-4o** β strongest general-purpose recognizer; gets famous types
|
| 90 |
+
(Concorde, B-2, SR-71) almost always right because they are well
|
| 91 |
+
represented online. Slowest and most expensive, requires API key.
|
| 92 |
+
|
| 93 |
+
**Takeaway:** even ~50 in-domain images per class are enough for a frozen
|
| 94 |
+
ViT + linear head to compete with β and often outperform β both zero-shot
|
| 95 |
+
CLIP and a frontier multimodal LLM, while being orders of magnitude cheaper
|
| 96 |
+
at inference time.
|
| 97 |
+
|
| 98 |
+
## Links
|
| 99 |
+
|
| 100 |
+
- π€ Model: https://huggingface.co/dubattim/aircraft-vit-fs26
|
| 101 |
+
- π Space: https://huggingface.co/spaces/dubattim/aircraft-classifier
|
| 102 |
+
- π» Source: `week8/gradio-aircraft-app/`
|
| 103 |
+
|
| 104 |
+
## Run locally
|
| 105 |
+
|
| 106 |
+
```bash
|
| 107 |
+
pip install -r requirements.txt
|
| 108 |
+
export OPENAI_API_KEY=sk-...
|
| 109 |
+
python app.py
|
| 110 |
+
```
|
| 111 |
+
|
| 112 |
+
## Files
|
| 113 |
+
|
| 114 |
+
- `app.py` β Gradio app with the three-model comparison.
|
| 115 |
+
- `train.py` β transfer-learning training script.
|
| 116 |
+
- `download_data.py` / `download_missing.py` β Wikimedia Commons downloader.
|
| 117 |
+
- `requirements.txt` β Python dependencies.
|
| 118 |
+
- `example_images/` β example images shown in the Gradio UI (one per class).
|