Spaces:
Sleeping
Sleeping
Delete README.md
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135---license: mittags:- food- ingredient-classification- computer-vision- multi-label-classification- pytorchlibrary_name: pytorch---
# Food Ingredient Classifier
A multi-label classification model that identifies ingredients in food images.
## Model Description
This model uses a ResNet-50 backbone fine-tuned on the Food-101 dataset to classify 101 different food ingredients.
## Performance
- **Validation Accuracy**: 99.01%- **Architecture**: ResNet-50 with custom classification head- **Training Epochs**: 1- **Number of Classes**: 101
## Ingredients Classified
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
## Usage
```pythonimport torchfrom torchvision import transforms, modelsfrom PIL import Imageimport torch.nn as nnfrom huggingface_hub import hf_hub_download
# Model architectureclass FoodIngredientClassifier(nn.Module): def __init__(self, num_classes=101): super().__init__() self.backbone = models.resnet50(pretrained=False) num_features = self.backbone.fc.in_features self.backbone.fc = nn.Sequential( nn.Dropout(0.5), nn.Linear(num_features, 512), nn.ReLU(), nn.Dropout(0.3), nn.Linear(512, num_classes) ) def forward(self, x): return self.backbone(x)
# Load modeldevice = torch.device('cuda' if torch.cuda.is_available() else 'cpu')model = FoodIngredientClassifier(num_classes=101).to(device)
# Download checkpoint from Hugging Facecheckpoint_path = hf_hub_download( repo_id="YOUR_USERNAME/food-ingredient-classifier", filename="best_model.pth")checkpoint = torch.load(checkpoint_path, map_location=device, weights_only=False)model.load_state_dict(checkpoint['model_state_dict'])model.eval()
# Get ingredient labelsmlb = checkpoint['mlb']
# Prepare imagetransform = transforms.Compose([ transforms.Resize((224, 224)), transforms.ToTensor(), transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])])
# Inferenceimg = Image.open('food_image.jpg').convert('RGB')img_tensor = transform(img).unsqueeze(0).to(device)
with torch.no_grad(): output = model(img_tensor) probs = torch.sigmoid(output).cpu().numpy()[0]
# Get predictions (threshold at 0.5)threshold = 0.5pred_indices = (probs > threshold).nonzero()[0]ingredients = mlb.classes_[pred_indices]confidences = probs[pred_indices]
for ingredient, confidence in zip(ingredients, confidences): print(f"{ingredient}: {confidence:.2%}")```
## Training Details
- **Dataset**: Food-101 (101,000 images across 101 categories)- **Batch Size**: 64- **Optimizer**: AdamW with weight decay (0.01)- **Learning Rate**: 0.001 with OneCycleLR scheduler- **Data Augmentation**: Random horizontal flip, rotation (15°), color jitter- **Mixed Precision Training**: Enabled for faster training- **Image Size**: 224x224
## Model Architecture
- **Backbone**: ResNet-50 (pretrained on ImageNet)- **Custom Head**: - Dropout (0.5) - Linear (2048 → 512) - ReLU - Dropout (0.3) - Linear (512 → 101)- **Output**: Multi-label (sigmoid activation)
## Citation
If you use this model, please cite:
```bibtex@misc{food-ingredient-classifier, author = {Your Name}, title = {Food Ingredient Classifier}, year = {2025}, publisher = {Hugging Face}, howpublished = {\url{https://huggingface.co/YOUR_USERNAME/food-ingredient-classifier}}}```
## License
MIT LicenseREADME.mdDeleted-135