Views
No views yet
google/vit-base-patch16-224 for food image classification across 10 categories.| Metric | Value |
|---|---|
| Accuracy | 98.04% |
| Epoch | Training Loss | Validation Loss | Accuracy |
|---|---|---|---|
| 1 | 0.3254 | 0.1076 | 97.20% |
| 2 | 0.1216 | 0.0904 | 97.68% |
| 3 | 0.0361 | 0.0770 | 97.88% |
| 4 | 0.0118 | 0.0764 | 98.00% |
| 5 | 0.0084 | 0.0767 | 98.04% |
1from datasets import load_dataset
2from transformers import pipeline
3from tqdm import tqdm
4
5# Load model
6classifier = pipeline("image-classification", model="Nav772/vit-food-classifier", device=0)
7
8# Load same test split
9dataset = load_dataset("food101", split="validation")
10
11# Filter to same 10 classes
12selected_classes = ["pizza", "sushi", "hamburger", "ice_cream", "steak",
13 "baklava", "cheesecake", "pancakes", "tacos", "ramen"]
14class_names = dataset.features['label'].names
15selected_indices = [class_names.index(c) for c in selected_classes]
16
17filtered = dataset.filter(lambda x: x['label'] in selected_indices)
18
19# Evaluate
20correct = 0
21total = 0
22
23for example in tqdm(filtered):
24 pred = classifier(example['image'])[0]['label']
25 true_label = class_names[example['label']]
26 if pred == true_label:
27 correct += 1
28 total += 1
29
30print(f"Accuracy: {correct/total:.4f} ({correct}/{total})")1from transformers import pipeline
2
3classifier = pipeline("image-classification", model="Nav772/vit-food-classifier")
4result = classifier("path/to/food/image.jpg")
5print(result)