How ngducok/food-classfication works
Project type and purpose
• This is a Python-based machine learning application for classifying food items in a canteen setting.
• It provides a simple UI (rielUI.py or a similar script) that lets end users supply images (upload from disk, webcam, or an ESP32-Cam) and receive food classification results along with price data.
• There is also a training component (train_kaggle.py) to re-train or update the model using Kaggle or custom datasets.
File structure
• Top-level files:
• rielmodel.pt: the serialized PyTorch model used at inference time
• food_price.json & data/food_price.json: static mapping of food labels → prices
• train_kaggle.py: training pipeline for building or updating the model
• readme.md, LICENSE: documentation and licensing
• Directories:
• core/: contains detector.py, the central inference logic that loads the model and runs predictions
• models/: contains any auxiliary model artifacts or scripts (e.g. 1.lua indicates possible Lua/Torch compatibility or conversion utilities)
• data/: sample data or supporting JSON files
• Utility scripts:
• lib2.py: presumably shared helper functions (I/O, image preprocessing, JSON parsing)
README for additional insights
• The README describes how to install dependencies, run the user interface, and swap models.
• Notes support for webcam and ESP32-Cam inputs, indicating external-device integration.
Main components
a. User Interface (rielUI.py)
• Accepts image input from:
• Local file browser
• Webcam device
• ESP32-Cam (via HTTP or serial)
• Displays classification results + price
b. Core Detector Module (core/detector.py)
• Loads the PyTorch model (rielmodel.pt)
• Processes input images (via lib2.py helpers)
• Returns class probabilities/labels
c. Data Store (food_price.json)
• Maps class labels → price values
d. Model Artifact (rielmodel.pt)
• Pretrained inference model
e. Training Pipeline (train_kaggle.py)
• Consumes labeled dataset (e.g., Kaggle food images)
• Outputs a new .pt model file
f. External Services / Devices
• Webcam driver
• ESP32-Cam HTTP/Socket interface
Relationships & interactions
• UI → Detector: forwards captured image
• Detector → Model Artifact: reads .pt file into memory
• Detector → Data Store: reads JSON to fetch pricing
• Detector → UI: returns classification + price
• Training Pipeline ↔ Dataset: reads raw images, writes new model
• (Optionally) ESP32-Cam → UI: streams image via HTTP
Architectural patterns & design principles
• Separation of concerns: clear split between UI, inference logic, data, and training
• Plug-and-play model swapping: UI and detector aren’t hard-coded to one model file
• External-device abstraction: treat ESP32-Cam input as any other image source
• JSON-backed configuration: easy updates to price lookup without code changes
Technologies & frameworks to annotate
• Python 3.X runtime
• PyTorch (inference & training)
• JSON for configuration/data
• Optional: OpenCV or PIL for image capture/preprocessing
• Networking libraries (requests or socket) for ESP32-Cam