Turning cafeteria trash into smarter menus.
Trash2Taste is an AI-powered food-waste reduction system for school cafeterias, built at HackByte. A camera mounted inside a trash can identifies the food being thrown away, that waste data is logged and enriched, and a machine-learning model uses it to recommend weekly menus that students are less likely to waste.
┌──────────────┐ CSV log ┌──────────────┐ enriched rows ┌──────────────────┐
│ Trash-can │ ─────────────▶ │ Conversion │ ────────────────▶ │ Waste dataset │
│ camera app │ (Flask, :5001)│ + GPT tags │ │ (.csv) │
└──────────────┘ └──────────────┘ └────────┬─────────┘
YOLOv8 detect + │ retrain
food classifier ▼
┌──────────────┐ predicted waste ┌──────────────────┐
│ Weekly menu │ ◀───────────────── │ Random Forest │
│ (GPT-4 + │ │ waste predictor │
│ ranking) │ └──────────────────┘
└──────────────┘
-
Detect waste. A Kivy camera app (
Appbasic.py) runs two models on every frame:- YOLOv8n (COCO) for general object detection, filtered to food classes
- A custom YOLOv8 classifier fine-tuned on the Food-101 / Food-41 dataset (94 dishes)
Results are smoothed across the last 5 frames by majority vote. Anything with average confidence ≥ 30% is logged to
combined_detection_log.csv. -
Collect the log.
Server_Cam.pyserves the log over HTTP, andclient.py/fetch.pypull it to the main machine. -
Enrich the data.
conversion.pyremoves duplicate detections (5-second window per item), asks OpenAI for each item's attributes (category, meat/dairy/veg, fried, sweet, spicy, serving size…), and appends the rows to the waste dataset. -
Retrain.
transfer_learning.pyupdates the label encoders and retrains the Random Forest waste-prediction pipeline on the combined dataset. -
Generate menus.
menu_generation.pyasks GPT-4 for 20 candidate cafeteria meals, scores each one with the waste model over repeated random weekly samples, and returns the 5 meals with the lowest predicted waste. -
Web front end.
about.html,menu.htmlandcontact.html(+styles.css) form the Trash2Taste site, including a weekly menu generator and a waste breakdown view.
| Area | Tools |
|---|---|
| Computer vision | Ultralytics YOLOv8, PyTorch / TorchScript, torchvision, OpenCV |
| Camera app | Kivy |
| ML / data | scikit-learn (Random Forest), pandas, NumPy, joblib, Faker |
| LLM | OpenAI API (GPT-3.5-turbo, GPT-4) |
| Networking | Flask, requests |
| Front end | HTML, CSS, JavaScript |
├── Appbasic.py # Kivy camera app: YOLO detection + custom food classifier, logs waste
├── Server_Cam.py # Flask server exposing the detection log (port 5001)
├── client.py / fetch.py # Pull the detection log from the camera device
├── conversion.py # Dedupe detections, tag attributes via OpenAI, append to dataset
├── transfer_learning.py # Retrain the waste-prediction model on new data
├── model.py # Same retraining logic wrapped in a function
├── menu_generation.py / main.py # GPT-4 menu candidates ranked by predicted waste
├── synthetic_data_generation.py # Generates the synthetic cafeteria waste dataset (~200 school days)
├── Tuning_YOLO.py # Train/val split + YOLOv8 classification fine-tuning (Colab)
├── YOLO_Convertor.py # Export the tuned classifier to TorchScript
├── OG_YOLO_Conversion.py # Export base YOLO to TorchScript
├── *.html, styles.css # Trash2Taste website
├── *.pt # YOLO weights (base, tuned, TorchScript)
├── *.pkl # Trained waste model + label encoders
└── *.csv # Synthetic, collected and correlated waste data
pip install ultralytics torch torchvision opencv-python kivy pillow \
scikit-learn pandas numpy joblib faker flask requests "openai<1.0"The code uses the legacy
openai.ChatCompletionAPI, so installopenai<1.0.
- OpenAI key: set
openai.api_keyinconversion.pyandmenu_generation.py. A better option is to read it from an environment variable:openai.api_key = os.environ["OPENAI_API_KEY"]. Never commit your key. - Model paths:
Appbasic.py,Server_Cam.py,YOLO_Convertor.pyandOG_YOLO_Conversion.pycontain absolute Windows paths. Change them to point to your localCustom.pt/YOLO_Model.pt/ log file. - Device IP: update
YOLO_IPinclient.py(and the URL infetch.py) to the camera machine's IP address.
# On the camera device
python Appbasic.py # start detecting and logging waste
python Server_Cam.py # serve the log on :5001
# On the main machine
python fetch.py # download the log
python -c "import conversion; conversion.process_detections('downloaded_file.csv')"
python transfer_learning.py # retrain the waste model
python menu_generation.py # print the optimized weekly menuOpen about.html in a browser to view the website.
- The waste model was first trained on synthetic data (
synthetic_data_generation.py). Real predictions improve only as real detections are collected. - Detection counts items thrown away, not the weight wasted. Adding a scale or volume estimation would make the data more accurate.
- Menu features currently use default attribute values. Using GPT attribute tagging for menu candidates too would sharpen the predictions.
- Nutritional compliance checks are a placeholder.
Built at HackByte by Ahan Bhowmik and Advay.