A comprehensive food detection application using YOLOv8 for detecting 10 different food classes in images.
- Apple Pie 🥧
- Chocolate 🍫
- French Fries 🍟
- Hotdog 🌭
- Nachos 🌮
- Pizza 🍕
- Onion Rings 🧅
- Pancakes 🥞
- Spring Rolls 🥢
- Tacos 🌮
- Web Interface: Beautiful, modern web UI with drag-and-drop functionality
- Command Line Tool: Fast batch processing for multiple images
- Real-time Detection: Instant results with confidence scores
- Bounding Box Visualization: Annotated images with detection boxes
- Batch Processing: Process entire directories of images
- API Endpoint: RESTful API for integration with other applications
- Python 3.8+
- YOLOv8 model (already trained and available in
runs/detect/yolov8n_food101/weights/best.pt)
-
Install Dependencies:
pip install -r requirements.txt
-
Verify Model Path: Ensure your YOLO model is located at:
runs/detect/yolov8n_food101/weights/best.pt
Start the Flask server:
python food_detection_app.pyAccess the application:
- Open your browser and go to:
http://localhost:5000 - Upload images by dragging and dropping or clicking to browse
- View real-time detection results with bounding boxes
Single Image Detection:
python food_detection_cli.py path/to/image.jpg -o output.jpgBatch Processing:
python food_detection_cli.py path/to/images/folder -d output/folderList Supported Classes:
python food_detection_cli.py --list-classesAdjust Confidence Threshold:
python food_detection_cli.py image.jpg -c 0.7Upload and Detect:
curl -X POST -F "[email protected]" http://localhost:5000/uploadAPI Response Format:
{
"success": true,
"detections": [
{
"class_name": "Pizza",
"confidence": 95.2,
"bbox": [100, 150, 300, 400]
}
],
"total_detections": 1,
"original_image": "timestamp_image.jpg",
"annotated_image": "annotated_timestamp_image.jpg"
}├── food_detection_app.py # Flask web application
├── food_detection_cli.py # Command-line tool
├── requirements.txt # Python dependencies
├── templates/
│ └── index.html # Web interface template
├── uploads/ # Temporary uploaded files
├── results/ # Annotated output images
└── runs/detect/yolov8n_food101/weights/
└── best.pt # Trained YOLO model
- Modern UI: Beautiful gradient design with smooth animations
- Drag & Drop: Easy image upload with visual feedback
- Real-time Results: Instant detection with loading indicators
- Statistics: Total detections and unique food types
- Responsive Design: Works on desktop and mobile devices
- Error Handling: Clear error messages for troubleshooting
- Model Path:
runs/detect/yolov8n_food101/weights/best.pt - Confidence Threshold: Default 0.5 (50%)
- Max File Size: 16MB for web uploads
- Host:
0.0.0.0(accessible from any IP) - Port:
5000 - Debug Mode: Enabled for development
- Inference Speed: ~50-100ms per image (depending on hardware)
- Accuracy: Trained on Food-101 dataset subset
- Memory Usage: ~2-4GB RAM (depending on image size)
-
Model Not Found:
❌ Error loading YOLO model: [Errno 2] No such file or directorySolution: Ensure the model file exists at the specified path
-
CUDA/GPU Issues:
❌ CUDA out of memorySolution: Use CPU mode or reduce batch size
-
Import Errors:
ModuleNotFoundError: No module named 'ultralytics'Solution: Install requirements:
pip install -r requirements.txt
- GPU Acceleration: Install CUDA-enabled PyTorch for faster inference
- Batch Processing: Use CLI tool for processing multiple images
- Image Optimization: Resize large images before processing
| Endpoint | Method | Description |
|---|---|---|
/ |
GET | Main web interface |
/upload |
POST | Upload and detect food in image |
/detect |
POST | API endpoint for detection |
/uploads/<filename> |
GET | Serve uploaded files |
/results/<filename> |
GET | Serve result files |
- Real-time video detection
- Mobile app integration
- Nutritional information lookup
- Recipe suggestions based on detected foods
- Multi-language support
- Cloud deployment options
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is part of the AIML Computer Vision Food-101 Detection project.
- YOLOv8 by Ultralytics
- Food-101 dataset
- Flask web framework
- OpenCV for image processing
Happy Food Detection! 🍕🍔🍟