Food Ingredient Classification and Recipe Recommendation using CNN and Transfer Learning
ECE-GY 6143 · Intro to Machine Learning --- Course Project
Author: Shreyansh Saurabh
NetID: ss21034
- GitHub: https://github.com/binaryshrey/Hungr-AI\
- Live Demo: https://hungrai-6143.vercel.app/
Hungr AI is an end-to-end machine learning web application where users upload multiple images of fruits and vegetables and the system:
- Detects the ingredients present in the images (e.g., apple, tomato, onion)
- Recommends recipes that best match the detected ingredients
The project demonstrates a complete ML lifecycle: dataset preprocessing, CNN-based image classification using transfer learning, model evaluation, backend inference serving, database-backed recipe retrieval and frontend deployment.
- Supervised learning (image classification)
- Convolutional Neural Networks (CNNs)
- Transfer learning with pretrained backbones (EfficientNet)
- Train / validation / test split
- Model evaluation and metrics
- Top-1 / Top-3 / Top-5 accuracy
- Confusion matrix and error analysis
- Python
- PyTorch, torchvision, timm
- pandas
- FastAPI
- Supabase (Postgres)
- React
- Vercel
- Render (API)
- Vercel (Frontend)
- Kaggle: Fruit and Vegetable Image Recognition
- 36 classes (apple, banana, garlic, etc.)
- Used for training the CNN classifier
Link : https://www.kaggle.com/datasets/kritikseth/fruit-and-vegetable-image-recognition
- Kaggle: RecipeNLG
- Large-scale recipe dataset
- Preprocessed and stored (subset ~200k recipes) in Supabase
Link : https://www.kaggle.com/datasets/paultimothymooney/recipenlg
All datasets are public and used strictly for academic purposes.
Vision Dataset - Verified folder structure and labels - Image resizing and normalization - Light augmentation (flip, rotation)
Recipe Dataset - Safe JSON parsing - Ingredient text normalization - CSV export and Supabase ingestion
- Single label per image (fruit/vegetable)
- Multi-image input → merged unique ingredient set
- Ranked by ingredient overlap
- Matched ingredients
- Missing ingredients (optional)
- Recipe title and instructions
Vision - No manual feature extraction - CNN learns features directly from pixels
Recipes - Ingredient normalization - Optional synonym mapping (e.g., capsicum ↔ bell pepper)
- Class distribution analysis
- Confusion matrix for similar ingredients
- Recipe coverage and ingredient frequency
- EfficientNet with transfer learning
- Metrics:
- Loss
- Top-1 / Top-3 / Top-5 accuracy
- Confusion matrix visualization
Saved Artifacts - best_model.pt - classes.json -
model_config.json
- Analysis of common misclassifications
- Identification of visually similar classes
- Qualitative evaluation of recipe retrieval quality
- Multi-image upload UI
- Async requests to backend
- Displays:
- Per-image predictions
- Merged ingredient list
- Ranked recipe recommendations
Concepts: SPA, async APIs, multipart upload, CORS
Endpoints - GET /health - POST /predict - POST /recipes/search
(optional)
Inference Pipeline
- Receive images
- Preprocess images
- Run CNN inference
- Merge predicted ingredients
- Query Supabase recipes
- Rank and return results
- PyTorch model loaded at startup
- CPU-based inference
torch.no_grad()for efficiency- Softmax confidence scores
- Stores recipes as JSONB
- Ingredient overlap matching
- Recommended improvement:
TEXT[]ingredients column- GIN index for fast overlap queries
- Frontend: Vercel
- Backend: Render
- Python 3.11 runtime
- Environment variables:
SUPABASE_URLSUPABASE_SERVICE_ROLE_KEY
- Built and deployed an end-to-end ML system
- Applied CNN transfer learning in practice
- Designed scalable ML-backed APIs
- Integrated ML inference with a real database
- Deployed a full-stack ML application to production
This project is developed for academic purposes as part of ECE-GY 6143.



