common/— shared code between training and serving: model architecture (model.py), class labels (labels.py), and image transforms (transforms.py). Keeps the two from silently drifting apart.model/— training pipeline. Downloads the TrashNet dataset and fine-tunes an EfficientNet-b0 to classify 6 categories: cardboard, glass, metal, paper, plastic, trash.ml_backend/— FastAPI server that receives a photo from the ESP32 over WiFi and returns the predicted category as plain text.firmware/— PlatformIO project for a Freenove ESP32-WROVER CAM board: captures a photo on an ultrasonic trigger, sends it toml_backend, and drives servos to sort the item into a bin.
All Python commands below are run from the repo root, so common resolves as a sibling package.
python -m venv .venv && source .venv/bin/activate
pip install -r model/requirements.txt
python -m model.download_dataset # downloads TrashNet into model/data/
python -m model.train # trains, writes model/checkpoints/best_model.pth + model_config.json
pip install -r ml_backend/requirements.txt
uvicorn ml_backend.main:app --host 0.0.0.0 --port 8000
POST /predict with a raw JPEG body returns the predicted label as plain text (e.g. plastic).
cd firmware
pio run --target upload
pio device monitor
Before flashing:
- Fill in the real servo angles in
firmware/src/sorter.cpp'sCALIBRATION_TABLE(currently placeholders) to match your physical sorter. - Set
SERVER_HOSTinfirmware/include/config.hto the IP the machine runningml_backendgets once it joins the ESP32'strashcanWiFi network.