Food Vision
AI · Computer Vision · 2026 · Solo Builder
Food recognition with nutrition for each dish: a fine-tuned CNN, a fine-tuned ViT and zero-shot CLIP compared on Food-101, plus multi-dish detection, served through FastAPI on ONNX Runtime with no PyTorch.
How it works
- Food-101 subset: 20 dishes, leak-free splits
- Three models: EfficientNet-B0, ViT-S/16, zero-shot CLIP
- Evaluation: McNemar tests, error analysis, Grad-CAM
- ONNX export: Verified against PyTorch on 2,000 images
- FastAPI + Docker: /predict and /detect, no PyTorch
One photo, end to end
One real photo, traced through the service as you scroll, then the evidence behind the model that serves it. The boxes, scores and nutrition are the pipeline’s own output on a held-out Food-101 test photo.
Food-101 test photo hamburger/450282, classified whole: hamburger 87.3%. Detected regions: sandwich (0.74) classified as hamburger 91.0%; sandwich (0.43) classified as french fries 92.6%; hot dog (0.33) classified as french fries 92.7%.
Hamburger: 1 single-patty burger with bun (~220 g) · 500 kcal · protein 28 g. French fries: 1 medium portion (~117 g) · 365 kcal · protein 4 g. Approximate reference values for one typical serving, not measurements of the pictured food.
Errors on 2000 test images: EfficientNet-B0 (fine-tuned, 4.0M parameters) 190, 90.5% top-1; ViT-S/16 (fine-tuned, 21.7M parameters, deployed) 159, 92.0% top-1; CLIP ViT-B/32 (zero-shot, 87.8M parameters) 146, 92.7% top-1. McNemar tests: ViT vs CNN p = 0.019, the ViT is better; ViT vs CLIP p = 0.364, statistically tied. ONNX = PyTorch on 2,000 of 2,000. 107 tests in CI.
Photo from the Food-101 test set (Bossard, Guillaumin and Van Gool, ECCV 2014)
Results
Three model families on the same leak-free Food-101 splits (20 dishes; 6,000 training, 1,500 validation and 2,000 test images): a fine-tuned EfficientNet-B0, a fine-tuned ViT-S/16 and zero-shot CLIP ViT-B/32. All numbers are on the held-out test split, 100 images per dish, and differences are checked with exact McNemar tests on the paired predictions.
- Top-1 accuracy, fine-tuned ViT-S/16: 92.1% (99.25% top-5 · beats the CNN (90.45%), p = 0.019)
- Zero-shot CLIP, with no training: 92.7% (Tied with the ViT: McNemar p = 0.364)
- ONNX agreement with PyTorch: 100% (Top-1 on all 2,000 test images)
- ViT inference on CPU, ONNX Runtime: 24 ms (Mean of 100 runs at batch 1 · p95 24.5 ms)
The fine-tuned models overfit: training top-1 reaches about 99% while validation levels off at 86–89%. Steak against filet mignon is the main error for all three models, 42–43 errors each. Detection has no accuracy measurement, because Food-101 has no bounding boxes. Nutrition values are approximate references for a typical serving, not measurements of the pictured food.
Highlights
- Three model families compared on identical leak-free splits, with McNemar significance tests instead of eyeballed accuracy.
- Zero-shot CLIP (92.7%) is statistically tied with the fine-tuned ViT-S/16 (92.1%); the ViT is deployed, with 4× fewer parameters and lower latency.
- Multi-dish photos: a YOLO11n detector finds the food regions, and the ViT names each one and adds approximate nutrition.
- Every export is verified before it is served: the ONNX ViT agrees with PyTorch on all 2,000 test images.
- Error analysis, Grad-CAM and a measurement of where ViT attention maps mislead, with 107 tests run in CI.
Stack
PyTorch, ONNX Runtime, FastAPI, YOLO11, CLIP, Docker