Skip to content

alexmerex/ObjectDetection

Repository files navigation

Overview

This project contains a Jupyter Notebook (Object detection.ipynb) for performing object detection on images using a pre-trained deep learning model. The notebook leverages popular libraries such as TensorFlow, OpenCV, and NumPy to detect objects within an image and visualize the results directly within the notebook.

Prerequisites

  1. Python: Ensure Python 3.6 or higher is installed on your system. You can download it from python.org.

  2. Jupyter Notebook: Install Jupyter Notebook to run the .ipynb file. You can install it using:

    pip install notebook
  3. TensorFlow: TensorFlow is required to run the object detection model. Install it using:

    pip install tensorflow
  4. OpenCV: Used for image processing and visualization. Install it using:

    pip install opencv-python
  5. NumPy: A fundamental package for scientific computing with Python. Install it using:

    pip install numpy
  6. Matplotlib: Required for displaying images and results in the notebook. Install it using:

    pip install matplotlib
  7. Pre-trained Model: Download a pre-trained object detection model (e.g., SSD, Faster R-CNN) and place it in the appropriate directory. You can get pre-trained models from the TensorFlow Model Zoo.

  8. Label Map: Ensure you have a label map file that maps object IDs to human-readable labels.

Setup

  1. Clone the Repository: Clone this repository to your local machine:

    git clone <repository-url>
  2. Download the Pre-trained Model: Download a pre-trained model from the TensorFlow Model Zoo and extract it to the project directory. For example:

    ./models/faster_rcnn_inception_v2_coco_2018_01_28/
    
  3. Label Map: Ensure you have a label map file (e.g., label_map.pbtxt) that corresponds to your model. Place it in the appropriate directory, such as ./data/.

  4. Open the Notebook: Open the Jupyter Notebook using:

    jupyter notebook "Object detection.ipynb"

    This will open the notebook in your default web browser.

Usage

  1. Load the Notebook: Open the Object detection.ipynb file in Jupyter Notebook.

  2. Configure the Notebook:

    • Modify the paths to the model and label map file as needed.
    • Ensure that the image_path variable points to the image you want to process.
  3. Run the Notebook: Execute the cells in the notebook sequentially. The notebook will:

    • Load the pre-trained model.
    • Load the input image.
    • Perform object detection on the image.
    • Display the image with detected objects and their labels.
  4. Visualize Results: The notebook will display the input image with bounding boxes around detected objects and labels indicating the detected object classes.

Notebook Structure

  • Cell 1: Imports required libraries such as TensorFlow, OpenCV, NumPy, and Matplotlib.
  • Cell 2: Configures the model path, label map path, and loads the pre-trained model.
  • Cell 3: Loads and preprocesses the input image.
  • Cell 4: Performs object detection and post-processing.
  • Cell 5: Visualizes the results with bounding boxes and labels on the image.

Error Handling

  • The notebook includes basic error handling to check for the existence of the model and label map files.
  • If an error occurs, an appropriate message will be displayed in the notebook output.

Customization

  • Model: You can change the pre-trained model by updating the path to the model directory in the notebook.
  • Threshold: Modify the detection threshold in the notebook to control the sensitivity of object detection.
  • Image Path: Change the image_path variable to test different images.

Dependencies

Install all the required dependencies using:

pip install -r requirements.txt

Create a requirements.txt file with the following content:

tensorflow
opencv-python
numpy
matplotlib
jupyter

Acknowledgments

This project utilizes various open-source libraries and models. Special thanks to the TensorFlow, OpenCV, and Jupyter communities for their contributions.


About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages