← All Projects
Live Demo2023

FoodVision - Image Classification System

A PyTorch transfer-learning pipeline comparing EfficientNet against a Vision Transformer, deployed as two live Gradio demos.

PyTorchTorchVisionEfficientNetVision Transformer (ViT)GradioHuggingFace SpacesPython

live demos

FoodVision Mini (pizza · steak · sushi)

FoodVision Mini (pizza · steak · sushi)Open in HuggingFace ↗

FoodVision Big (101 food classes)

FoodVision Big (101 food classes)Open in HuggingFace ↗

About this project

A PyTorch computer vision pipeline built from the ground up: starting with a from-scratch TinyVGG architecture, then moving through transfer-learning experiments that directly compare an EfficientNetB2 feature extractor against a ViT-B/16 transformer on a 3-class food dataset (pizza, steak, sushi). ViT reached 98.47% test accuracy versus EfficientNetB2's 86.88% - but at roughly 11x the model size and 5.7x the inference latency, a deployment tradeoff resolved in favor of EfficientNetB2 for the live demo, given a real-time inference target. The same EfficientNetB2 architecture was then fine-tuned on the full 101-class Food101 dataset ("FoodVision Big") and shipped as a second, independent Gradio app on HuggingFace Spaces.

Technical details

The project progresses through nine PyTorch notebooks: fundamentals and autograd, a supervised classification pipeline, custom Dataset/DataLoader patterns, a TinyVGG model built from scratch, transfer learning with pretrained backbones, TensorBoard experiment tracking, Vision Transformer (ViT-B/16) fine-tuning, and a final deployment-focused comparison notebook.

The deployment notebook set an explicit target: ≥95% test accuracy at ≥30 FPS (under 0.03s per prediction on CPU). Neither model actually cleared that bar on its own - EfficientNetB2 scored 86.88% accuracy at 0.106s/prediction, while ViT-B/16 scored 98.47% accuracy but took 0.603s/prediction and carried an 11.3x larger footprint (327MB vs 29MB). Rather than chasing accuracy alone, the tradeoff was resolved explicitly: EfficientNetB2 was shipped to production because a 5.7x latency penalty and an 11x storage cost were judged not worth an 11.6-point accuracy gain for a real-time, free-tier-hosted demo.

FoodVision Big scales the same EfficientNetB2 feature extractor to the full 101-class Food101 dataset, trained on a 20% data subset for 5 epochs with an Adam optimizer (lr=1e-3) and label smoothing (0.1) to offset the large class count. It reached 58.47% test accuracy - a reasonable baseline for a 101-way classification problem trained on a fifth of the available data in a handful of epochs.

Both models were packaged identically for deployment: a `model.py` defining the architecture and transforms, an `app.py` wiring a Gradio `Interface` with an image input and label/confidence/latency outputs, and a `requirements.txt`, all zipped and uploaded to independent HuggingFace Spaces. Training infrastructure (the engine loop, data setup utilities, and reproducibility helpers) was abstracted into a reusable `going_modular` package rather than duplicated per-notebook, mirroring how shared training code is structured in production ML codebases.