aayanb09 commited on
Commit
a30d5f7
·
verified ·
1 Parent(s): 80a4190

Delete README.md

Browse files
Files changed (1) hide show
  1. README.md +0 -135
README.md DELETED
@@ -1,135 +0,0 @@
1
- ---
2
- license: mit
3
- tags:
4
- - food
5
- - ingredient-classification
6
- - computer-vision
7
- - multi-label-classification
8
- - pytorch
9
- library_name: pytorch
10
- ---
11
-
12
- # Food Ingredient Classifier
13
-
14
- A multi-label classification model that identifies ingredients in food images.
15
-
16
- ## Model Description
17
-
18
- This model uses a ResNet-50 backbone fine-tuned on the Food-101 dataset to classify 101 different food ingredients.
19
-
20
- ## Performance
21
-
22
- - **Validation Accuracy**: 99.01%
23
- - **Architecture**: ResNet-50 with custom classification head
24
- - **Training Epochs**: 1
25
- - **Number of Classes**: 101
26
-
27
- ## Ingredients Classified
28
-
29
- apple_pie, baby_back_ribs, baklava, beef_carpaccio, beef_tartare, beet_salad, beignets, bibimbap, bread_pudding, breakfast_burrito, bruschetta, caesar_salad, cannoli, caprese_salad, carrot_cake, ceviche, cheese_plate, cheesecake, chicken_curry, chicken_quesadilla, chicken_wings, chocolate_cake, chocolate_mousse, churros, clam_chowder, club_sandwich, crab_cakes, creme_brulee, croque_madame, cup_cakes, deviled_eggs, donuts, dumplings, edamame, eggs_benedict, escargots, falafel, filet_mignon, fish_and_chips, foie_gras, french_fries, french_onion_soup, french_toast, fried_calamari, fried_rice, frozen_yogurt, garlic_bread, gnocchi, greek_salad, grilled_cheese_sandwich, grilled_salmon, guacamole, gyoza, hamburger, hot_and_sour_soup, hot_dog, huevos_rancheros, hummus, ice_cream, lasagna, lobster_bisque, lobster_roll_sandwich, macaroni_and_cheese, macarons, miso_soup, mussels, nachos, omelette, onion_rings, oysters, pad_thai, paella, pancakes, panna_cotta, peking_duck, pho, pizza, pork_chop, poutine, prime_rib, pulled_pork_sandwich, ramen, ravioli, red_velvet_cake, risotto, samosa, sashimi, scallops, seaweed_salad, shrimp_and_grits, spaghetti_bolognese, spaghetti_carbonara, spring_rolls, steak, strawberry_shortcake, sushi, tacos, takoyaki, tiramisu, tuna_tartare, waffles
30
-
31
- ## Usage
32
-
33
- ```python
34
- import torch
35
- from torchvision import transforms, models
36
- from PIL import Image
37
- import torch.nn as nn
38
- from huggingface_hub import hf_hub_download
39
-
40
- # Model architecture
41
- class FoodIngredientClassifier(nn.Module):
42
- def __init__(self, num_classes=101):
43
- super().__init__()
44
- self.backbone = models.resnet50(pretrained=False)
45
- num_features = self.backbone.fc.in_features
46
- self.backbone.fc = nn.Sequential(
47
- nn.Dropout(0.5),
48
- nn.Linear(num_features, 512),
49
- nn.ReLU(),
50
- nn.Dropout(0.3),
51
- nn.Linear(512, num_classes)
52
- )
53
-
54
- def forward(self, x):
55
- return self.backbone(x)
56
-
57
- # Load model
58
- device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
59
- model = FoodIngredientClassifier(num_classes=101).to(device)
60
-
61
- # Download checkpoint from Hugging Face
62
- checkpoint_path = hf_hub_download(
63
- repo_id="YOUR_USERNAME/food-ingredient-classifier",
64
- filename="best_model.pth"
65
- )
66
- checkpoint = torch.load(checkpoint_path, map_location=device, weights_only=False)
67
- model.load_state_dict(checkpoint['model_state_dict'])
68
- model.eval()
69
-
70
- # Get ingredient labels
71
- mlb = checkpoint['mlb']
72
-
73
- # Prepare image
74
- transform = transforms.Compose([
75
- transforms.Resize((224, 224)),
76
- transforms.ToTensor(),
77
- transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
78
- ])
79
-
80
- # Inference
81
- img = Image.open('food_image.jpg').convert('RGB')
82
- img_tensor = transform(img).unsqueeze(0).to(device)
83
-
84
- with torch.no_grad():
85
- output = model(img_tensor)
86
- probs = torch.sigmoid(output).cpu().numpy()[0]
87
-
88
- # Get predictions (threshold at 0.5)
89
- threshold = 0.5
90
- pred_indices = (probs > threshold).nonzero()[0]
91
- ingredients = mlb.classes_[pred_indices]
92
- confidences = probs[pred_indices]
93
-
94
- for ingredient, confidence in zip(ingredients, confidences):
95
- print(f"{ingredient}: {confidence:.2%}")
96
- ```
97
-
98
- ## Training Details
99
-
100
- - **Dataset**: Food-101 (101,000 images across 101 categories)
101
- - **Batch Size**: 64
102
- - **Optimizer**: AdamW with weight decay (0.01)
103
- - **Learning Rate**: 0.001 with OneCycleLR scheduler
104
- - **Data Augmentation**: Random horizontal flip, rotation (15°), color jitter
105
- - **Mixed Precision Training**: Enabled for faster training
106
- - **Image Size**: 224x224
107
-
108
- ## Model Architecture
109
-
110
- - **Backbone**: ResNet-50 (pretrained on ImageNet)
111
- - **Custom Head**:
112
- - Dropout (0.5)
113
- - Linear (2048 → 512)
114
- - ReLU
115
- - Dropout (0.3)
116
- - Linear (512 → 101)
117
- - **Output**: Multi-label (sigmoid activation)
118
-
119
- ## Citation
120
-
121
- If you use this model, please cite:
122
-
123
- ```bibtex
124
- @misc{food-ingredient-classifier,
125
- author = {Your Name},
126
- title = {Food Ingredient Classifier},
127
- year = {2025},
128
- publisher = {Hugging Face},
129
- howpublished = {\url{https://huggingface.co/YOUR_USERNAME/food-ingredient-classifier}}
130
- }
131
- ```
132
-
133
- ## License
134
-
135
- MIT License