An AI-powered nutrition tracking application that uses deep learning to identify food from images and automatically track nutritional intake. Simply upload a photo of your meal, and FoodAdvisor will recognize the food, calculate the nutritional values, and help you maintain your health goals.
- Deep Learning Model: Trained CNN model capable of recognizing 101 different food categories
- Image Classification: Upload a photo and get instant food identification
- Confidence Scoring: Model provides confidence levels for predictions
- User Correction System: Collect feedback on incorrect predictions to improve the model through RLHF (Reinforcement Learning from Human Feedback)
- Automatic Nutritional Analysis: Retrieves detailed nutrition data via Nutritionix API
- Macronutrient Breakdown: Track calories, proteins, carbohydrates, and fats
- Portion Size Adjustment: Customize serving sizes (small, medium, large)
- Daily Meal History: View all meals logged throughout the day with timestamps
- Custom Calorie Targets: Calculates daily caloric needs based on:
- Age, sex, height, and weight
- Activity level (low, moderate, high)
- Workout frequency (0-1, 2-3, 4+ times per week)
- Health goals (lose weight, maintain, gain weight)
- Macronutrient Goals: Personalized protein, carb, and fat targets
- Weight Tracking: Log and visualize weight changes over time
- Progress Visualization: Interactive graphs showing weight trends
- Visual Progress Charts: Matplotlib-generated graphs for weight tracking
- Meal Statistics: View nutritional summaries for each meal
- Daily Progress: Track progress toward daily nutritional goals
- Historical Data: Access past meals and nutritional data
- Secure Authentication: User registration and login system
- Profile Management: Create and customize personal health profiles
- Data Privacy: User-specific data isolation and protection
- Django 5.2.6: Python web framework for robust backend architecture
- PostgreSQL: Relational database for data persistence
- Gunicorn: WSGI HTTP server for production deployment
- WhiteNoise: Static file serving for Django applications
- TensorFlow 2.20.0: Deep learning framework
- Keras: High-level neural networks API
- NumPy & Pandas: Data manipulation and numerical computing
- scikit-learn: Machine learning utilities
- Pillow: Image processing library
- React 18: Modern JavaScript library for building user interfaces
- TypeScript: Type-safe JavaScript development
- Vite: Fast build tool and development server
- TailwindCSS: Utility-first CSS framework
- React Router: Client-side routing
- TanStack Query: Server state management
- Nutritionix API: Real-time nutritional data retrieval
- Requests: HTTP library for API calls
- Matplotlib: Python plotting library for weight graphs
- Railway: Cloud platform for deployment
- python-decouple: Environment variable management
- dj-database-url: Database URL parsing
I started by defining the core problem: manually tracking nutrition is tedious and time-consuming. The solution was to leverage AI for automatic food recognition combined with a comprehensive tracking system. I designed a full-stack architecture with Django handling the backend and ML model serving, while React provided a responsive frontend.
Initially, I planned to train a CNN from scratch, but after research and experimentation, I opted for transfer learning:
- Dataset: Food101 dataset containing 101 food categories
- Base Model: Fine-tuned ImageNet pre-trained model
- Training Process: Conducted extensive experimentation in Jupyter notebooks (
CNN_model.ipynb) - Model Performance: Achieved ~69% Top-1 accuracy, which is reasonable given the complexity of food recognition and dataset limitations
Built a robust Django application with:
- Database Models: Designed normalized schema for Users, Profiles, Meals, FoodItems, and WeightEntries
- ML Integration: Created prediction functions (
prediction_funcs.py) that load the Keras model and process images - API Integration: Implemented Nutritionix API client (
nutrition_api.py) for fetching nutritional data - Business Logic:
- Developed calorie calculation algorithms based on Mifflin-St Jeor equation
- Implemented macronutrient distribution (24% protein, 50% carbs, 26% fats)
- Created portion size multipliers for serving adjustments
Developed a modern React/TypeScript interface:
- Component Architecture: Built reusable UI components with shadcn/ui library
- Responsive Design: Used TailwindCSS for mobile-first, responsive layouts
- Type Safety: Implemented TypeScript for better developer experience and fewer runtime errors
- Build Optimization: Configured Vite for fast development and optimized production builds
Established a continuous improvement workflow:
- Prediction Correction System: Users can correct misidentified foods
- Data Collection: Store incorrect predictions with correct labels (
CorrectedPredictionmodel) - Export Functionality: Created Django management command to export feedback data
- RLHF Preparation: Designed the system for future model retraining with human feedback
- Personalization Engine: Implemented sophisticated calorie and macro calculations considering multiple factors
- Visual Feedback: Generated dynamic weight tracking graphs using Matplotlib
- Meal Management: Built intuitive interfaces for viewing, editing, and saving meals
- Form Validation: Implemented comprehensive validation for user inputs
- Model Evaluation: Created evaluation functions and tracked accuracy metrics
- Performance Analysis: Built project size analyzer to optimize deployment
- Database Optimization: Implemented efficient queries and proper indexing
- Static File Handling: Configured WhiteNose for efficient static file serving
- Railway Platform: Deployed on Railway for scalable cloud hosting
- Environment Management: Used python-decouple for secure configuration
- Database Migration: Configured PostgreSQL for production with proper migrations
- Static Files: Set up WhiteNoise for production static file serving
- Build Scripts: Created automated build scripts for streamlined deployment
The app is designed for evolution:
- Feedback Loop: Collecting user corrections for future model improvements
- Modular Architecture: Easy to add new features and food categories
- Scalable Design: Database and API structure support growth
- Jupyter Notebooks: Maintaining notebooks for model experimentation and retraining
- Python 3.10+
- Node.js 16+
- PostgreSQL
- Clone the repository
git clone https://github.com/yourusername/FoodAdvisor.git
cd FoodAdvisor- Install Python dependencies
pip install -r requirements.txt- Install frontend dependencies
npm install- Set up environment variables
Create a
.envfile with:
SECRET_KEY=your-secret-key
DATABASE_URL=your-database-url
NUTRITIONIX_APP_ID=your-app-id
NUTRITIONIX_API_KEY=your-api-key
- Run migrations
python manage.py migrate- Start the development server
# Backend
python manage.py runserver
# Frontend (in another terminal)
npm run devThis project is open source and available under the MIT License.
Contributions, issues, and feature requests are welcome!
Visit FoodAdvisor: https://food-advisor-production-3924.up.railway.app