π½οΈ Food Nutrition Predictor
A ViT-based model that predicts:
- Food name (classification)
- Estimated calories (regression)
- Macronutrient breakdown: carbs, protein, fat (regression)
This repo contains training, inference, and Hugging Faceβready export using google/vit-base-patch16-224 as the backbone.
Features
- Multi-head model: classification + regression
- Trainer script with validation and checkpointing
- Inference wrapper returning JSON output
- Hugging Face model card and sample inference
- Example
labels.csvformat and dataset loader
Quick start
- Create a virtualenv and install requirements:
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
Prepare
data/labels.csvanddata/images/(seedata/labels.csvexample below).Train:
python src/train.py --config config.json --data_csv data/labels.csv --img_dir data/images --output_dir outputs
- Run inference:
python src/inference.py --model_path outputs/checkpoint_best.pth --labels_file data/classes.txt --image sample.jpg
Data format
data/labels.csv should have columns:
image,class_id,calories,carbs,protein,fat
burger_001.jpg,0,550,45,25,30
pizza_01.jpg,1,285,36,12,10
Create data/classes.txt listing class names in order (one per line).
File structure
food-nutrition-predictor/
β
βββ README.md
βββ requirements.txt
βββ config.json
β
βββ src/
β βββ dataset.py
β βββ model.py
β βββ train.py
β βββ inference.py
β βββ utils.py
β
βββ data/
β βββ images/
β βββ labels.csv
β
βββ notebooks/
β βββ EDA_and_Training.ipynb
β
βββ huggingface/
βββ model_card.md
βββ sample_inference.py
Notes & tips
- Use mixed precision (AMP) for faster training on modern GPUs.
- If you have few classes or small dataset, apply heavy augmentation.
- Calorie/macros targets can be normalized (optional) β this repo expects raw grams/calorie values.
- Downloads last month
- 26