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.
-
Python: Ensure Python 3.6 or higher is installed on your system. You can download it from python.org.
-
Jupyter Notebook: Install Jupyter Notebook to run the
.ipynbfile. You can install it using:pip install notebook
-
TensorFlow: TensorFlow is required to run the object detection model. Install it using:
pip install tensorflow
-
OpenCV: Used for image processing and visualization. Install it using:
pip install opencv-python
-
NumPy: A fundamental package for scientific computing with Python. Install it using:
pip install numpy
-
Matplotlib: Required for displaying images and results in the notebook. Install it using:
pip install matplotlib
-
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.
-
Label Map: Ensure you have a label map file that maps object IDs to human-readable labels.
-
Clone the Repository: Clone this repository to your local machine:
git clone <repository-url>
-
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/ -
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/. -
Open the Notebook: Open the Jupyter Notebook using:
jupyter notebook "Object detection.ipynb"This will open the notebook in your default web browser.
-
Load the Notebook: Open the
Object detection.ipynbfile in Jupyter Notebook. -
Configure the Notebook:
- Modify the paths to the model and label map file as needed.
- Ensure that the
image_pathvariable points to the image you want to process.
-
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.
-
Visualize Results: The notebook will display the input image with bounding boxes around detected objects and labels indicating the detected object classes.
- 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.
- 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.
- 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_pathvariable to test different images.
Install all the required dependencies using:
pip install -r requirements.txtCreate a requirements.txt file with the following content:
tensorflow
opencv-python
numpy
matplotlib
jupyter
This project utilizes various open-source libraries and models. Special thanks to the TensorFlow, OpenCV, and Jupyter communities for their contributions.