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

import torch
import torch.nn as nn
from torchvision import models, transforms
from huggingface_hub import hf_hub_download

# Modell laden
ckpt_path = hf_hub_download("benvened/nutrilens-resnet18", "cv_model.pt")

model = models.resnet18(weights=None)
model.fc = nn.Linear(model.fc.in_features, 30)
model.load_state_dict(torch.load(ckpt_path, map_location="cpu"))
model.eval()

# Inferenz
transform = transforms.Compose([
    transforms.Resize((224, 224)),
    transforms.ToTensor(),
    transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
])

from PIL import Image
img = transform(Image.open("food.jpg")).unsqueeze(0)
with torch.no_grad():
    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).

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support