File size: 1,915 Bytes
c762fb0
729d8cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
---
license: apache-2.0
tags:
  - computer-vision
  - image-classification
  - food101
  - cnn-vit
  - hybrid
datasets:
  - food101
metrics:
  - accuracy
library_name: pytorch
---

# 🍕 Hybrid Food Image Classifier (CNN + ViT)

This model combines ResNet50 (CNN) and DeiT-Base (ViT) with an adaptive fusion module for state-of-the-art food image classification.

## Model Architecture

- **CNN Branch**: ResNet50 (pretrained on ImageNet)
- **ViT Branch**: DeiT-Base Distilled (pretrained)
- **Fusion Module**: Adaptive attention-based fusion with multi-head cross-attention
- **Classes**: 101 food categories from Food-101 dataset

## Performance

- **Validation Accuracy**: ~82.5%
- **Top-5 Accuracy**: >95%

## Files

- `best_model.pth`: Trained PyTorch checkpoint
- `real_class_mapping.json`: Human-readable class names
- `config.yaml`: Training configuration
- `food101_class_names.json`: Original class names

## Quick Usage

```python
from huggingface_hub import hf_hub_download
import torch

# Download model
ckpt_path = hf_hub_download(
    repo_id="codealchemist01/food-image-classifier-hybrid",
    filename="best_model.pth"
)

# Load checkpoint
checkpoint = torch.load(ckpt_path, map_location="cpu")
```

## Demo

Try the live demo: [Food Classifier Space](https://huggingface.co/spaces/codealchemist01/food-classifier-space)

## Training Details

- **Dataset**: Food-101 (101,000 images across 101 categories)
- **Framework**: PyTorch 2.0+
- **Image Size**: 224x224
- **Optimizer**: AdamW with cosine annealing warm restarts
- **Augmentations**: Albumentations (flip, rotation, color jitter)
- **Mixed Precision**: FP16 training

## Citation

```bibtex
@misc{food-classifier-hybrid,
  author = {codealchemist01},
  title = {Hybrid Food Image Classifier},
  year = {2025},
  publisher = {Hugging Face},
  howpublished = {\url{https://huggingface.co/codealchemist01/food-image-classifier-hybrid}}
}
```