license: mit
tags:
- food-classification
- computer-vision
- resnet18
- food-101
library_name: pytorch
NutriLens ResNet18 — Food Classification
ResNet18 fine-tuned auf einem 30-Klassen-Subset von Food-101.
Performance: 62% Top-1 Accuracy (Test-Set, 2400 Bilder)
Hinweis: Dieses Modell wurde im Rahmen des Projekts
NutriLens als Baseline-Vergleich trainiert. In der finalen App wird stattdessen CLIP ViT-B/32 Zero-Shot eingesetzt (89% Accuracy). Siehe Projekt-Doku für Details.
Architecture
- Backbone: ResNet18 (ImageNet-pretrained, frozen)
- Head: linearer Layer mit 30 Output-Neuronen (fc-Layer ersetzt)
- Training: 6 Epochs, Adam optimizer (lr=1e-3), CrossEntropyLoss
- Augmentation: RandomHorizontalFlip, RandomRotation(±15°), ColorJitter
Klassen (30)
Pizza, Hamburger, Hot Dog, French Fries, Donuts, Pancakes, Waffles, Cheesecake, Apple Pie, Steak, Spaghetti Bolognese, Lasagna, Tiramisu, Bruschetta, Ravioli, Risotto, Sushi, Ramen, Pad Thai, Dumplings, Fried Rice, Spring Rolls, Tacos, Guacamole, Caesar Salad, Greek Salad, Hummus, Falafel, Omelette, Ice Cream
Usage
1import torch
2import torch.nn as nn
3from torchvision import models, transforms
4from huggingface_hub import hf_hub_download
5
6# Modell laden
7ckpt_path = hf_hub_download("benvened/nutrilens-resnet18", "cv_model.pt")
8
9model = models.resnet18(weights=None)
10model.fc = nn.Linear(model.fc.in_features, 30)
11model.load_state_dict(torch.load(ckpt_path, map_location="cpu"))
12model.eval()
13
14# Inferenz
15transform = transforms.Compose([
16 transforms.Resize((224, 224)),
17 transforms.ToTensor(),
18 transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
19])
20
21from PIL import Image
22img = transform(Image.open("food.jpg")).unsqueeze(0)
23with torch.no_grad():
24 pred = model(img).argmax(dim=1).item()
Limitations
- Frozen Backbone limitiert Feinkörnigkeit: Verwechslungen bei visuell ähnlichen Texturen (z.B. pad_thai ↔ spaghetti_bolognese)
- Dataset-Bias: westlich/asiatisch dominiert, andere Küchen unterrepräsentiert
- Zero-Shot Foundation Models (CLIP) erreichen auf denselben Klassen 89% Accuracy
Citation
Trained as part of the AI Applications course project at ZHAW (Zurich University of Applied Sciences).