Skip to content

Repository files navigation

Mobile Phone Detection using YOLOv5

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.

🚀 Features

  • 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.

📂 Project Structure

  • 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).

🛠️ Installation

  1. Clone the repository:

    git clone https://github.com/wareeshayy/CV_MobilePhoneDetection.git
    cd CV_MobilePhoneDetection
  2. 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
  3. 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

⚡ Quick Start

To see mobile phone detection in action immediately using the standard pre-trained YOLOv5s model (trained on COCO dataset):

python stop_on_phone_detect.py

This will:

  1. Open your webcam.
  2. Detect mobile phones (class 'cell phone').
  3. Stop automatically after 300 frames.
  4. Print a detection summary (total phones detected, frames with detections).

🏋️ Training on Custom Data

To train a model specifically for your environment or better accuracy:

  1. Prepare your Dataset: Organize your images and labels in the mobile_phone_dataset directory:

    mobile_phone_dataset/
    ├── images/
    │   ├── train/  (training images)
    │   └── val/    (validation images)
    └── labels/
        ├── train/  (YOLO format txt files)
        └── val/    (YOLO format txt files)
    
  2. Run the Training Script:

    python train_mobile_phone.py
  3. Select Option 1 to start training.

    • You can configure epochs, batch size, and model size in the script or follow the prompts.

🔍 Running Detection with Custom Model

Once you have trained your own model, you can run inference using:

python run_detection.py

Alternatively, run train_mobile_phone.py and select Option 3.

📊 Evaluation & Export

  • Validation: Run train_mobile_phone.py and select Option 2 to see Mean Average Precision (mAP) scores.
  • Export: Run train_mobile_phone.py and select Option 4 to convert your model for mobile or edge deployment (ONNX, TFLite, etc.).

📝 License

This project is open source and available under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages