A full pipeline for detecting and classifying tomato ripeness using:
- Faster R-CNN β tomato object detection
- MobileNetV2 (fine-tuned) β ripeness classification
- Real-time webcam demo β bounding boxes + labels + confidence
Ripeness levels:
- unripe (green)
- semi-ripe (orange)
- fully-ripe (red)
This project supports training, preprocessing, conversion from COCO annotations, and real-time inference.
project_root/
β
ββ data/
β ββ raw/ # Original images + COCO annotations
β ββ processed/ # Cropped images for 3-class classification
β
ββ models/
β ββ mobilenet_tomato_classifier.h5 # Base MobileNetV2
β ββ mobilenet_tomato_finetune.h5 # Fine-tuned MobileNetV2
β
ββ notebooks/
β ββ MobileNet_V2_training.ipynb # MobileNetV2 base training
β
ββ src/
β ββ check.py # Check the labels
β ββ convert_coco_to_classification.py # Convert COCO β cropped dataset
β
ββ demos/
β ββ camera_demo.py # MobileNetV2 webcam classifier
β ββ camera_demo_fasterrcnn.py # Faster R-CNN + MobileNetV2 demo
ββ dashboard/
β ββ app.py # Flask application
β ββ camera.py # setup camera
β
ββ requirements.txt
- Python 3.8+
- TensorFlow 2.x
- PyTorch + torchvision
- OpenCV
- Pillow
pip install tensorflow torch torchvision opencv-python pillowOpen the fine-tuning notebook:
jupyter notebook notebooks/MobileNet_V2_training.ipynbThe 2 trained model will be saved to the directory and we will use:
models/mobilenet_tomato_finetune.h5
python demos/camera_demo.pyThis runs:
- Webcam livestream
- Full-frame classification
- Displays predicted ripeness + confidence
python demos/camera_demo_fasterrcnn.pyPipeline:
- Faster R-CNN detects tomato bounding boxes
- Each crop is classified with MobileNetV2
- Bounding boxes + label + confidence displayed in real-time
- Press q to quit
- Use good lighting β improves detection accuracy
- If FPS is low β resize frame before sending to Faster R-CNN
- For highest accuracy β fine-tune Faster R-CNN on your tomato dataset
- Convert model to TensorFlow Lite for IoT devices (optional)
- Tomato dataset: tomatOD
- MobileNetV2 pretrained on ImageNet
- Faster R-CNN pretrained on COCO
AIoT project for real-time tomato ripeness classification & detection.