Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,27 +1,78 @@
|
|
| 1 |
---
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
tags:
|
| 4 |
+
- computer-vision
|
| 5 |
+
- image-classification
|
| 6 |
+
- food101
|
| 7 |
+
- cnn-vit
|
| 8 |
+
- hybrid
|
| 9 |
+
datasets:
|
| 10 |
+
- food101
|
| 11 |
+
metrics:
|
| 12 |
+
- accuracy
|
| 13 |
+
library_name: pytorch
|
| 14 |
+
---
|
| 15 |
+
|
| 16 |
+
# 🍕 Hybrid Food Image Classifier (CNN + ViT)
|
| 17 |
+
|
| 18 |
+
This model combines ResNet50 (CNN) and DeiT-Base (ViT) with an adaptive fusion module for state-of-the-art food image classification.
|
| 19 |
+
|
| 20 |
+
## Model Architecture
|
| 21 |
+
|
| 22 |
+
- **CNN Branch**: ResNet50 (pretrained on ImageNet)
|
| 23 |
+
- **ViT Branch**: DeiT-Base Distilled (pretrained)
|
| 24 |
+
- **Fusion Module**: Adaptive attention-based fusion with multi-head cross-attention
|
| 25 |
+
- **Classes**: 101 food categories from Food-101 dataset
|
| 26 |
+
|
| 27 |
+
## Performance
|
| 28 |
+
|
| 29 |
+
- **Validation Accuracy**: ~82.5%
|
| 30 |
+
- **Top-5 Accuracy**: >95%
|
| 31 |
+
|
| 32 |
+
## Files
|
| 33 |
+
|
| 34 |
+
- `best_model.pth`: Trained PyTorch checkpoint
|
| 35 |
+
- `real_class_mapping.json`: Human-readable class names
|
| 36 |
+
- `config.yaml`: Training configuration
|
| 37 |
+
- `food101_class_names.json`: Original class names
|
| 38 |
+
|
| 39 |
+
## Quick Usage
|
| 40 |
+
|
| 41 |
+
```python
|
| 42 |
+
from huggingface_hub import hf_hub_download
|
| 43 |
+
import torch
|
| 44 |
+
|
| 45 |
+
# Download model
|
| 46 |
+
ckpt_path = hf_hub_download(
|
| 47 |
+
repo_id="codealchemist01/food-image-classifier-hybrid",
|
| 48 |
+
filename="best_model.pth"
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
# Load checkpoint
|
| 52 |
+
checkpoint = torch.load(ckpt_path, map_location="cpu")
|
| 53 |
+
```
|
| 54 |
+
|
| 55 |
+
## Demo
|
| 56 |
+
|
| 57 |
+
Try the live demo: [Food Classifier Space](https://huggingface.co/spaces/codealchemist01/food-classifier-space)
|
| 58 |
+
|
| 59 |
+
## Training Details
|
| 60 |
+
|
| 61 |
+
- **Dataset**: Food-101 (101,000 images across 101 categories)
|
| 62 |
+
- **Framework**: PyTorch 2.0+
|
| 63 |
+
- **Image Size**: 224x224
|
| 64 |
+
- **Optimizer**: AdamW with cosine annealing warm restarts
|
| 65 |
+
- **Augmentations**: Albumentations (flip, rotation, color jitter)
|
| 66 |
+
- **Mixed Precision**: FP16 training
|
| 67 |
+
|
| 68 |
+
## Citation
|
| 69 |
+
|
| 70 |
+
```bibtex
|
| 71 |
+
@misc{food-classifier-hybrid,
|
| 72 |
+
author = {codealchemist01},
|
| 73 |
+
title = {Hybrid Food Image Classifier},
|
| 74 |
+
year = {2025},
|
| 75 |
+
publisher = {Hugging Face},
|
| 76 |
+
howpublished = {\url{https://huggingface.co/codealchemist01/food-image-classifier-hybrid}}
|
| 77 |
+
}
|
| 78 |
+
```
|