--- title: SmartPlate emoji: 🐨 colorFrom: gray colorTo: gray sdk: docker pinned: false --- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference # Smart Plate - Indian Food Classification and Calorie Estimation Smart Plate README poster by Aishrica Dhiman Smart Plate logo Smart Plate is a computer vision and deep learning project for Indian food image classification with calorie estimation. The core work is a Vision Transformer based prediction model trained and evaluated on 80 Indian food categories, with an inference pipeline that maps the predicted dish to serving-size and calorie metadata.
The project includes: - model development and evaluation in `notebook/indian-food-image-detection-vit.ipynb` - technical model documentation in `DOC.md` - a model card in `MODEL_CARD.md` - a FastAPI inference service that loads the bundled ViT model from `models/aishrica_food_predictor/` The deployed inference pipeline loads model weights locally, so runtime inference does not depend on downloading weights from HuggingFace. Repository: `https://github.com/aishricadhiman/SmartPlate` --- ## What This Project Demonstrates - Computer vision model development for multi-class food classification - Calorie estimation from predicted dish class, serving-size metadata, and nutrition data - Fine-tuning and evaluating a Vision Transformer using HuggingFace Transformers - Image dataset preprocessing, augmentation, stratified splitting, and label encoding - Deep learning evaluation using accuracy, macro-F1, confusion matrix, and classification report - Local model serving with PyTorch, Transformers, and FastAPI - Inference post-processing that joins predicted labels with nutrition metadata - Clear ML project documentation through README, model card, reports, and training config --- ## Model Training Summary The model development notebook trains and evaluates a ViT image classifier on the Kaggle Indian Food Images Dataset. | Item | Details | |---|---| | Dataset | Kaggle Indian Food Images Dataset | | Total images | 4,000 | | Classes | 80 Indian food categories | | Samples per class | 50 | | Split | 60% train / 40% test, stratified | | Train samples | 2,400 | | Test samples | 1,600 | | Base model | `google/vit-base-patch16-224-in21k` | | Fine-tuning checkpoint | `aishrica/indian_food_prediction` | | Architecture | Vision Transformer, ViT-Base | | Epochs | 20 | | Learning rate | 1e-6 | | Batch size | 64 train / 32 eval | | Final test accuracy | 0.7519 | | Final macro-F1 | 0.7352 | The notebook also generates detailed evaluation outputs, including a confusion matrix and per-class precision / recall / F1 scores. Full technical documentation is available in `DOC.md`. --- ## How The Inference Pipeline Works 1. The input food image is loaded and converted to RGB. 2. The ViT image processor resizes and normalizes the image. 3. The bundled ViT classifier predicts the top food classes. 4. The highest-ranked predicted label is matched with `calorie_db.json`. 5. The API estimates calories using the matched dish metadata and typical serving size. 6. The API returns the predicted dish, confidence, food category, serving size, and calories. --- ## Supported Dishes The model supports 80 Indian food categories, including: Biryani, Samosa, Jalebi, Dosa, Gulab Jamun, Butter Chicken, Dal Makhani, Bhatura, Chapati, Naan, Paratha, Paneer Butter Masala, Kadai Paneer, Rasgulla, Ras Malai, Aloo Tikki, Gajar Ka Halwa, Poha, and many more. --- ## Project Structure ```text SmartPlate/ |-- app.py |-- calorie_db.json |-- .gitignore |-- DOC.md |-- LICENSE |-- MODEL_CARD.md |-- README.md |-- requirements-dev.txt |-- requirements.txt |-- requirements-train.txt |-- configs/ | `-- train_config.yaml |-- data/ | |-- README.md | |-- raw/ | `-- processed/ |-- notebook/ | `-- indian-food-image-detection-vit.ipynb |-- models/ | |-- README.md | `-- aishrica_food_predictor/ | |-- config.json | |-- model.safetensors | `-- preprocessor_config.json |-- reports/ | |-- README.md | `-- metrics.json |-- scripts/ | |-- evaluate.py | |-- export_model.py | |-- predict_image.py | `-- train.py |-- src/ | |-- __init__.py | |-- model_loader.py | |-- nutrition.py | |-- predict.py | `-- preprocessing.py |-- static/ | |-- css/ | |-- data/ | | `-- model_card.json | |-- img/ | | |-- confusion_matrix.png | | |-- smart-plate-readme-poster.png | | |-- smart-plate-logo-transparent.png | | `-- smart-plate-logo.png | |-- js/ | |-- pages/ | `-- index.html `-- tests/ |-- test_calorie_db.py `-- test_project_files.py ``` --- ## GitHub Visibility For Large Files The repository is structured so important ML metadata remains visible on GitHub even when large files are not committed. - Dataset images are documented in `data/README.md`; raw images should stay outside Git. - Model weights such as `model.safetensors` are ignored unless Git LFS is configured. - Model metadata stays visible through `models/README.md`, `config.json`, `preprocessor_config.json`, `MODEL_CARD.md`, and `configs/train_config.yaml`. - Evaluation metadata stays visible through `reports/metrics.json`, `DOC.md`, and the confusion matrix image in `static/img/confusion_matrix.png`. --- ## Setup And Run Inference ### 1. Install inference dependencies ```bash pip install -r requirements.txt ``` ### 2. Start the FastAPI server ```bash python app.py ``` ### 3. Open the local interface ```text http://localhost:8000 ``` The bundled model is loaded from: ```text models/aishrica_food_predictor/ ``` For training and evaluation experiments, install: ```bash pip install -r requirements-train.txt ``` For local test dependencies, install: ```bash pip install -r requirements-dev.txt ``` Run the lightweight project checks with: ```bash python -m pytest tests ``` --- ## API Endpoints | Method | Endpoint | Description | |---|---|---| | GET | `/` | Opens the Smart Plate interface | | POST | `/predict` | Uploads an image and returns food prediction + calorie estimate | | GET | `/foods` | Returns all supported food items with calorie data | | GET | `/{page}` | Serves pages such as `home`, `scan`, `dashboard`, `history`, and `model` | ### Example Request ```bash curl -X POST http://localhost:8000/predict \ -F "file=@biryani.jpg" ``` ### Example Response ```json { "top_prediction": { "label": "Biryani", "raw_label": "biryani", "confidence": 75.2, "category": "Rice Dish", "calories_per_100g": 145, "serving_g": 300, "calories_per_serving": 435 }, "predictions": [ { "label": "Biryani", "raw_label": "biryani", "confidence": 75.2, "category": "Rice Dish", "calories_per_100g": 145, "serving_g": 300, "calories_per_serving": 435 } ] } ``` --- ## Tech Stack - Model development: PyTorch, HuggingFace Transformers, HuggingFace Datasets - Architecture: Vision Transformer, ViT-Base - Evaluation: Evaluate, scikit-learn, confusion matrix, classification report - Image processing: Pillow, torchvision transforms - Backend inference: Python, FastAPI, Uvicorn - Frontend: HTML, CSS, JavaScript - Data: JSON calorie metadata --- ## Model Limitations - The model classifies one dominant dish per image; it does not perform food segmentation or multi-item plate detection. - The dataset contains 50 images per class, so real-world generalization may vary. - Similar-looking dishes, especially curries and sweets, may be confused. - Confidence scores should be treated carefully because the documented training run showed poorly calibrated probabilities. - Calorie estimates are based on typical serving sizes, not actual measured portion volume. --- ## Documentation For full model-development details, see: ```text DOC.md MODEL_CARD.md notebook/indian-food-image-detection-vit.ipynb configs/train_config.yaml reports/metrics.json ``` These files document the dataset, preprocessing, augmentation, training configuration, evaluation metrics, inference pipeline, limitations, and future improvements. Project repository: `https://github.com/aishricadhiman/SmartPlate`