This project implements a real-time mobile phone detection system using the YOLOv5 object detection architecture. It provides scripts for training a custom model, running real-time detection on a webcam, and validating model performance.
- Real-time Detection: Detect mobile phones in real-time using your webcam.
- Custom Training: Tools to fine-tune YOLOv5 on your own mobile phone dataset.
- Validation: Evaluate model performance with precision/recall metrics.
- Model Export: Export trained models to ONNX, TorchScript, or TFLite for deployment.
train_mobile_phone.py: The main utility script for training, validating, and detecting.stop_on_phone_detect.py: A standalone script that runs detection using the pre-trained COCO model (class 67: cell phone) and provides a summary.run_detection.py: A shortcut to launch the real-time detection mode of the main script.mobile_phone_dataset/: Directory structure for your custom dataset (images and labels).runs/: Stores training results (weights, confusion matrices, loss plots).
-
Clone the repository:
git clone https://github.com/wareeshayy/CV_MobilePhoneDetection.git cd CV_MobilePhoneDetection -
Set up the environment: Create a virtual environment (recommended) and install dependencies.
# Windows python -m venv venv .\venv\Scripts\activate # Linux/Mac python3 -m venv venv source venv/bin/activate
-
Install YOLOv5 Dependencies: The scripts will automatically clone the YOLOv5 repository if missing, but you need to install its requirements.
pip install -r yolov5/requirements.txt
To see mobile phone detection in action immediately using the standard pre-trained YOLOv5s model (trained on COCO dataset):
python stop_on_phone_detect.pyThis will:
- Open your webcam.
- Detect mobile phones (class 'cell phone').
- Stop automatically after 300 frames.
- Print a detection summary (total phones detected, frames with detections).
To train a model specifically for your environment or better accuracy:
-
Prepare your Dataset: Organize your images and labels in the
mobile_phone_datasetdirectory:mobile_phone_dataset/ ├── images/ │ ├── train/ (training images) │ └── val/ (validation images) └── labels/ ├── train/ (YOLO format txt files) └── val/ (YOLO format txt files) -
Run the Training Script:
python train_mobile_phone.py
-
Select Option 1 to start training.
- You can configure epochs, batch size, and model size in the script or follow the prompts.
Once you have trained your own model, you can run inference using:
python run_detection.pyAlternatively, run train_mobile_phone.py and select Option 3.
- Validation: Run
train_mobile_phone.pyand select Option 2 to see Mean Average Precision (mAP) scores. - Export: Run
train_mobile_phone.pyand select Option 4 to convert your model for mobile or edge deployment (ONNX, TFLite, etc.).
This project is open source and available under the MIT License.