Title: Intersection over Union (IoU) for object detection - PyImageSearch

URL Source: https://pyimagesearch.com/2016/11/07/intersection-over-union-iou-for-object-detection/

Published Time: 2016-11-07T15:00:59+00:00

Markdown Content:
Last Updated on April 30, 2022

* * *

**Table of Contents**
---------------------

*   [Intersection over Union for object detection](#h2Intersection)

*   [What is Intersection over Union?](#h3What)
*   [Where are you getting the ground-truth examples from?](#h3Where)
*   [Why do we use Intersection over Union?](#h3Why)
*   [Implementing Intersection over Union in Python](#h3Implementing)
*   [Comparing predicted detections to the ground-truth with Intersection over Union](#h3Comparing)
*   [Alternative Intersection over Union implementations](#h3Alternative)

*   [Summary](#h2Summary)

![Image 1: Figure 1: An example of detecting a stop sign in an image. The predicted bounding box is drawn in red while the ground-truth bounding box is drawn in green. Our goal is to compute the Intersection of Union between these bounding box.](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20600%20450'%3E%3C/svg%3E)

Intersection over Union (IoU) is used to evaluate the performance of object detection by comparing the ground truth bounding box to the preddicted bounding box and IoU is the topic of this tutorial.

A solid understanding of IoU requires practical applications. Access to a well-curated dataset allows learners to engage with real-world challenges, enhancing their understanding of object detection and how IoU is applied for accuracy.

[Roboflow](https://roboflow.com/?ref=pyimagesearch) has free tools for each stage of the computer vision pipeline that will streamline your workflows and supercharge your productivity.

Sign up or Log in to your [Roboflow account](https://roboflow.com/?ref=pyimagesearch) to access state of the art dataset libaries and revolutionize your computer vision pipeline.

You can start by choosing your own datasets or using our [PyimageSearch’s assorted library of useful datasets](https://universe.roboflow.com/pyimagesearch?ref=pyimagesearch).

Bring data in any of 40+ formats to [Roboflow](https://roboflow.com/?ref=pyimagesearch), train using any state-of-the-art model architectures, deploy across multiple platforms (API, NVIDIA, browser, iOS, etc), and connect to applications or 3rd party tools.

With a few images, you can train a working computer vision model in an afternoon. For example, bring data into [Roboflow](https://roboflow.com/?ref=pyimagesearch) from anywhere via API, label images with the cloud-hosted image annotation tool, kickoff a hosted model training with one-click, and deploy the model via a hosted API endpoint. This process can be executed in a code-centric way, in the cloud-based UI, or any mix of the two.

Over 250,000 developers and machine learning engineers from companies such as Cardinal Health, Walmart, USG, Rivian, Intel, and Medtronic build computer vision pipelines with Roboflow. Get started today, no credit card required.

Today’s blog post is inspired from an email I received from Jason, a student at the University of Rochester.

Jason is interested in building a custom object detector using the [HOG + Linear SVM framework](https://pyimagesearch.com/2014/11/10/histogram-oriented-gradients-object-detection/) for his final year project. He understands the steps required to build the object detector well enough — _but he isn’t sure how to **evaluate the accuracy**_ _of his detector once it’s trained._

His professor mentioned that he should use the _**Intersection over Union (IoU)**_ method for evaluation, but Jason’s not sure how to implement it.

I helped Jason out over email by:

1.  Describing _what_ Intersection over Union is.
2.  Explaining _why_ we use Intersection over Union to evaluate object detectors.
3.  Providing him with some _example Python code from my own personal library_ to perform Intersection over Union on bounding boxes.

My email really helped Jason finish getting his final year project together and I’m sure he’s going to pass with flying colors.

With that in mind, I’ve decided to turn my response to Jason into an actual blog post in hopes that it will help you as well.

_**To learn how to evaluate your own custom object detectors using the Intersection over Union evaluation metric, just keep reading.**_

*   **Update July 2021:** Added section on alternative Intersection over Union implementations, including IoU methods that can be used as loss functions when training deep neural network object detectors.
*   **Update Apr 2022:** Added TOC and linked the post to a new intersection over Union tutorial.
*   **Update Dec 2022**: Removed link to the dataset as the dataset is no longer publicly available and refresed the content.

* * *

![Image 2](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20128%20128'%3E%3C/svg%3E)

#### Looking for the source code to this post?

[Jump Right To The Downloads Section](#download-the-code)

In the remainder of this blog post I’ll explain _what_ the Intersection over Union evaluation metric is and _why_ we use it.

I’ll also provide a Python implementation of Intersection over Union that you can use when evaluating your own custom object detectors.

Finally, we’ll look at some _actual results_ of applying the Intersection over Union evaluation metric to a set of _ground-truth_ and _predicted_ bounding boxes.

* * *

### [What is Intersection over Union?](#TOC)

Intersection over Union is an evaluation metric used to measure the accuracy of an object detector on a particular dataset. We often see this evaluation metric used in object detection challenges such as the popular [PASCAL VOC challenge](http://host.robots.ox.ac.uk/pascal/VOC/).

You’ll typically find Intersection over Union used to evaluate the performance of [HOG + Linear SVM object detectors](https://pyimagesearch.com/2014/11/10/histogram-oriented-gradients-object-detection/) and Convolutional Neural Network detectors (R-CNN, Faster R-CNN, YOLO, etc.); however, keep in mind that the _actual algorithm used to generate the predictions **doesn’t matter.**_

Intersection over Union is simply an _evaluation metric_. Any algorithm that provides predicted bounding boxes as output can be evaluated using IoU.

More formally, in order to apply Intersection over Union to evaluate an (arbitrary) object detector we need:

1.  The _ground-truth bounding boxes_ (i.e., the hand labeled bounding boxes from the testing set that specify _where_ in the image our object is).
2.  The _predicted bounding boxes_ from our model.

As long as we have these two sets of bounding boxes we can apply Intersection over Union.

Below I have included a visual example of a ground-truth bounding box versus a predicted bounding box:

![Image 3: Figure 1: An example of detecting a stop sign in an image. The predicted bounding box is drawn in red while the ground-truth bounding box is drawn in green. Our goal is to compute the Intersection of Union between these bounding box.](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20600%20450'%3E%3C/svg%3E)

**Figure 1**: An example of detecting a stop sign in an image. The predicted bounding box is drawn in red while the ground-truth bounding box is drawn in green. Our goal is to compute the Intersection over Union between these bounding box.

In the figure above we can see that our object detector has detected the presence of a stop sign in an image.

The _predicted_ bounding box is drawn in _red_ while the _ground-truth_ (i.e., hand labeled) bounding box is drawn in green.

Computing Intersection over Union can therefore be determined via:

![Image 4: Figure 2: Computing the Intersection of Union is as simple as dividing the area of overlap between the bounding boxes by the area of union (thank you to the excellent Pittsburg HW4 assignment for the inspiration for this figure).](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20600%20468'%3E%3C/svg%3E)

**Figure 2:** Computing the Intersection over Union is as simple as dividing the area of overlap between the bounding boxes by the area of union (thank you to the excellent [Pittsburg HW4 assignment](https://people.cs.pitt.edu/~kovashka/cs1699/hw4.html) for the inspiration for this figure).

Examining this equation you can see that Intersection over Union is simply a ratio.

In the numerator we compute the _**area of overlap**_ between the _predicted_ bounding box and the _ground-truth_ bounding box.

The denominator is the _**area of union**_, or more simply, the area encompassed by _both_ the predicted bounding box and the ground-truth bounding box.

Dividing the area of overlap by the area of union yields our final score — _the Intersection over Union._

* * *

### [Where are you getting the ground-truth examples from?](#TOC)

Before we get too far, you might be wondering where the ground-truth examples come from. I’ve mentioned before that these images are “hand labeled”, but what exactly does that mean?

You see, when training your own object detector (such as the [HOG + Linear SVM method](https://pyimagesearch.com/2014/11/10/histogram-oriented-gradients-object-detection/)), you need a dataset. This dataset should be broken into (at least) two groups:

1.  A _training set_ used for training your object detector.
2.  A _testing set_ for evaluating your object detector.

You may also have a _validation set_ used to [tune the hyperparameters of your model](https://pyimagesearch.com/2016/08/15/how-to-tune-hyperparameters-with-python-and-scikit-learn/).

Both the training and testing set will consist of:

1.  The actual images themselves.
2.  The _bounding boxes_ associated with the object(s) in the image. The bounding boxes are simply the _(x, y)_\-coordinates of the object in the image.

The bounding boxes for the training and testing sets are _hand labeled_ and hence why we call them the “ground-truth”.

Your goal is to take the training images + bounding boxes, construct an object detector, and then evaluate its performance on the testing set.

**An Intersection over Union score _\> 0.5_ is normally considered a “good” prediction.**

* * *

### [Why do we use Intersection over Union?](#TOC)

If you have performed any previous machine learning in your career, specifically classification, you’ll likely be used to _predicting class labels_ where your model outputs a single label that is either _correct_ or _incorrect._

This type of binary classification makes computing accuracy straightforward; however, for object detection it’s not so simple.

In all reality, it’s _extremely unlikely_ that the _(x, y)_\-coordinates of our predicted bounding box are going to **_exactly match_** the _(x, y)_\-coordinates of the ground-truth bounding box.

Due to varying parameters of our model (image pyramid scale, sliding window size, feature extraction method, etc.), a complete and total match between predicted and ground-truth bounding boxes is simply unrealistic.

Because of this, we need to define an evaluation metric that _rewards_ predicted bounding boxes for heavily overlapping with the ground-truth:

![Image 5: Figure 3: An example of computing Intersection over Unions for various bounding boxes.](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20600%20248'%3E%3C/svg%3E)

**Figure 3:** An example of computing Intersection over Unions for various bounding boxes.

In the above figure I have included examples of good and bad Intersection over Union scores.

As you can see, predicted bounding boxes that heavily overlap with the ground-truth bounding boxes have higher scores than those with less overlap. This makes Intersection over Union an excellent metric for evaluating custom object detectors.

We aren’t concerned with an _exact_ match of _(x, y)_\-coordinates, but we do want to ensure that our predicted bounding boxes match as closely as possible — Intersection over Union is able to take this into account.

* * *

### [Implementing Intersection over Union in Python](#TOC)

Now that we understand what Intersection over Union is and why we use it to evaluate object detection models, let’s go ahead and implement it in Python.

Before we get started writing any code though, I want to provide the five example images we will be working with:

![Image 6: Figure 4: In this example, we'll be detecting the presence of cars in images.](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20580%20593'%3E%3C/svg%3E)

**Figure 4**: In this example, we’ll be detecting the presence of cars in images.

These images are part of the CALTECH-101 dataset used for both _image classification_ and _object detection._

This dataset was publicly available but as of December of 2022 it is not longer public.

Inside the _**[PyImageSearch Gurus course](https://pyimagesearch.com/pyimagesearch-gurus/)**_ I demonstrate how to train a custom object detector to detect the presence of cars in images like the ones above using the HOG + Linear SVM framework.

I have provided a visualization of the ground-truth bounding boxes (green) along with the predicted bounding boxes (red) from the custom object detector below:

![Image 7: Figure 5: Our goal is to evaluate the performs of our object detector by using Intersection of Union. Specifically, we want to measure the accuracy of the predicted bounding box (red) against the ground-truth (green).](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20580%20593'%3E%3C/svg%3E)

**Figure 5:** Our goal is to evaluate the performance of our object detector by using Intersection over Union. Specifically, we want to measure the accuracy of the predicted bounding box (red) against the ground-truth (green).

Given these bounding boxes, our task is to define the Intersection over Union metric that can be used to evaluate how “good (or bad) our predictions are.

With that said, open up a new file, name it `intersection_over_union.py` , and let’s get coding:

\# import the necessary packages
from collections import namedtuple
import numpy as np
import cv2

# define the \`Detection\` object
Detection = namedtuple("Detection", \["image\_path", "gt", "pred"\])

We start off by importing our required Python packages. We then define a `Detection` object that will store three attributes:

*   `image_path` : The path to our input image that resides on disk.
*   `gt` : The ground-truth bounding box.
*   `pred` : The predicted bounding box from our model.

As we’ll see later in this example, I’ve already obtained the predicted bounding boxes from our five respective images and hardcoded them into this script to keep the example short and concise.

For a complete review of the HOG + Linear SVM object detection framework, [please refer to this blog post](https://pyimagesearch.com/2014/11/10/histogram-oriented-gradients-object-detection/). And if you’re interested in learning more about training your own custom object detectors from scratch, be sure to check out the [PyImageSearch Gurus course](https://pyimagesearch.com/pyimagesearch-gurus/).

Let’s go ahead and define the `bb_intersection_over_union` function, which as the name suggests, is responsible for computing the Intersection over Union between two bounding boxes:

def bb\_intersection\_over\_union(boxA, boxB):
	# determine the (x, y)-coordinates of the intersection rectangle
	xA = max(boxA\[0\], boxB\[0\])
	yA = max(boxA\[1\], boxB\[1\])
	xB = min(boxA\[2\], boxB\[2\])
	yB = min(boxA\[3\], boxB\[3\])

	# compute the area of intersection rectangle
	interArea = max(0, xB - xA + 1) \* max(0, yB - yA + 1)

	# compute the area of both the prediction and ground-truth
	# rectangles
	boxAArea = (boxA\[2\] - boxA\[0\] + 1) \* (boxA\[3\] - boxA\[1\] + 1)
	boxBArea = (boxB\[2\] - boxB\[0\] + 1) \* (boxB\[3\] - boxB\[1\] + 1)

	# compute the intersection over union by taking the intersection
	# area and dividing it by the sum of prediction + ground-truth
	# areas - the interesection area
	iou = interArea / float(boxAArea + boxBArea - interArea)

	# return the intersection over union value
	return iou

This method requires two parameters: `boxA` and `boxB` , which are presumed to be our ground-truth and predicted bounding boxes (the actual _order_ in which these parameters are supplied to `bb_intersection_over_union` doesn’t matter).

**Lines 11-14** determine the _(x, y)_\-coordinates of the intersection rectangle which we then use to compute the area of the intersection (**Line 17**).

The `interArea` variable now represents the _numerator_ in the Intersection over Union calculation.

To compute the denominator we first need to derive the area of both the predicted bounding box and the ground-truth bounding box (**Lines 21 and 22**).

The Intersection over Union can then be computed on **Line 27** by dividing the intersection area by the union area of the two bounding boxes, taking care to subtract out the intersection area from the denominator (otherwise the intersection area would be doubly counted).

Finally, the Intersection over Union score is returned to the calling function on **Line 30**.

Now that our Intersection over Union method is finished, we need to define the ground-truth and predicted bounding box coordinates for our five example images:

\# define the list of example detections
examples = \[
	Detection("image\_0002.jpg", \[39, 63, 203, 112\], \[54, 66, 198, 114\]),
	Detection("image\_0016.jpg", \[49, 75, 203, 125\], \[42, 78, 186, 126\]),
	Detection("image\_0075.jpg", \[31, 69, 201, 125\], \[18, 63, 235, 135\]),
	Detection("image\_0090.jpg", \[50, 72, 197, 121\], \[54, 72, 198, 120\]),
	Detection("image\_0120.jpg", \[35, 51, 196, 110\], \[36, 60, 180, 108\])\]

As I mentioned above, in order to keep this example short(er) and concise, I have _manually obtained_ the predicted bounding box coordinates from my HOG + Linear SVM detector. These predicted bounding boxes (And corresponding ground-truth bounding boxes) are then _hardcoded_ into this script.

For more information on how I trained this exact object detector, [please refer to the PyImageSearch Gurus course](https://pyimagesearch.com/pyimagesearch-gurus/).

We are now ready to evaluate our predictions:

\# loop over the example detections
for detection in examples:
	# load the image
	image = cv2.imread(detection.image\_path)

	# draw the ground-truth bounding box along with the predicted
	# bounding box
	cv2.rectangle(image, tuple(detection.gt\[:2\]), 
		tuple(detection.gt\[2:\]), (0, 255, 0), 2)
	cv2.rectangle(image, tuple(detection.pred\[:2\]), 
		tuple(detection.pred\[2:\]), (0, 0, 255), 2)

	# compute the intersection over union and display it
	iou = bb\_intersection\_over\_union(detection.gt, detection.pred)
	cv2.putText(image, "IoU: {:.4f}".format(iou), (10, 30),
		cv2.FONT\_HERSHEY\_SIMPLEX, 0.6, (0, 255, 0), 2)
	print("{}: {:.4f}".format(detection.image\_path, iou))

	# show the output image
	cv2.imshow("Image", image)
	cv2.waitKey(0)

On **Line 41** we start looping over each of our `examples` (which are `Detection` objects).

For each of them, we load the respective `image` from disk on **Line 43** and then draw the ground-truth bounding box in green (**Lines 47 and 48**) followed by the predicted bounding box in red (**Lines 49 and 50**).

The actual Intersection over Union metric is computed on **Line 53** by passing in the ground-truth and predicted bounding box.

We then write the Intersection over Union value on the `image` itself followed by our console as well.

Finally, the output image is displayed to our screen on **Lines 59 and 60**.

* * *

### [Comparing predicted detections to the ground-truth with Intersection over Union](#TOC)

To see the Intersection over Union metric in action, make sure you have downloaded the source code + example images to this blog post by using the **_“Downloads”_** section found at the bottom of this tutorial.

After unzipping the archive, execute the following command:

$ python intersection\_over\_union.py

Our first example image has an Intersection over Union score of _0.7980_, indicating that there is significant overlap between the two bounding boxes:

![Image 8: Figure 6: Computing the Intersection of Union using Python.](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20600%20492'%3E%3C/svg%3E)

**Figure 6:** Computing the Intersection over Union using Python.

The same is true for the following image which has an Intersection over Union score of _0.7899_:

![Image 9: Figure 7: A slightly better Intersection over Union score.](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20600%20492'%3E%3C/svg%3E)

**Figure 7:** A slightly better Intersection over Union score.

Notice how the ground-truth bounding box (green) is wider than the predicted bounding box (red). This is because our object detector is defined using the HOG + Linear SVM framework which requires us to specify a fixed size sliding window (not to mention, an image pyramid scale and the HOG parameters themselves).

Ground-truth bounding boxes will naturally have a slightly different aspect ratio than the predicted bounding boxes, but that’s okay provided that the Intersection over Union score is _\> 0.5_ — as we can see, this still a great prediction.

The next example demonstrates a slightly “less good” prediction where our predicted bounding box is much less “tight” than the ground-truth bounding box:

![Image 10: Figure 8: Deriving the Intersection of Union evaluation metric for object detection.](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20600%20492'%3E%3C/svg%3E)

**Figure 8:** Deriving the Intersection over Union evaluation metric for object detection.

The reason for this is because our HOG + Linear SVM detector likely couldn’t “find” the car in the lower layers of the image pyramid and instead fired near the top of the pyramid where the image is much smaller.

The following example is an _extremely good_ detection with an Intersection over Union score of _0.9472_:

![Image 11: Figure 9: Measuring object detection performance using Intersection over Union.](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20600%20492'%3E%3C/svg%3E)

**Figure 9:** Measuring object detection performance using Intersection over Union.

Notice how the predicted bounding box nearly perfectly overlaps with the ground-truth bounding box.

Here is one final example of computing Intersection over Union:

![Image 12: Figure 10: Intersection over Union for evaluating object detection algorithms.](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20600%20492'%3E%3C/svg%3E)

**Figure 10:** Intersection over Union for evaluating object detection algorithms.

* * *

### [Alternative Intersection over Union implementations](#TOC)

This tutorial provided a Python and NumPy implementation of IoU. However, there are other implementations of IoU that may be better for your particular application and project.

For example, if you are training a deep learning model using a popular library/framework such as TensorFlow, Keras, or PyTorch, then implementing IoU using your deep learning framework _should_ improve the speed of the algorithm.

The following list provides my suggested alternative implementations of Intersection over Union, including implementations that can be used as loss/metric functions when training a deep neural network object detector:

*   [TensorFlow’s MeanIoU function](https://www.tensorflow.org/api_docs/python/tf/keras/metrics/MeanIoU), which computes the mean Intersection over Union for a sample of object detection results.
*   [TensorFlow’s GIoULoss loss metric](https://www.tensorflow.org/addons/api_docs/python/tfa/losses/GIoULoss), which was first introduced in [_Generalized Intersection over Union: A Metric and A Loss for Bounding Box Regression_](https://giou.stanford.edu/GIoU.pdf) by Rezatofighi et al. Just as you train a neural network to minimize mean squared error, cross-entropy, etc., this method acts as a drop-in replacement loss function, potentially leading to higher object detection accuracy.
*   [A PyTorch implementation of IoU](https://www.kaggle.com/iezepov/fast-iou-scoring-metric-in-pytorch-and-numpy) (which I have not tested or used), but seems to be helpful to the PyTorch community.
*   We have a great [Mean Average Precision (mAP) Using the COCO Evaluator](https://pyimg.co/nwoka) tutorial that will walk you through using intersection over union for evaluating YOLO performance. Learn the theoretical concepts of Mean Average Precision (mAP) and evaluate the YOLOv4 detector using the gold standard COCO Evaluator.

Of course, you can always take my Python/NumPy implementation of IoU and convert it to your own library, language, etc.

Happy hacking!

### What's next? We recommend [PyImageSearch University](https://pyimagesearch.com/pyimagesearch-university/?utm_source=blogPost&utm_medium=bottomBanner&utm_campaign=What%27s%20next%3F%20I%20recommend).

**Course information:**  
84 total classes • 114+ hours of on-demand code walkthrough videos • Last updated: February 2024  
★★★★★ 4.84 (128 Ratings) • 16,000+ Students Enrolled

**I strongly believe that if you had the right teacher you could _master_ computer vision and deep learning.**

Do you think learning computer vision and deep learning has to be time-consuming, overwhelming, and complicated? Or has to involve complex mathematics and equations? Or requires a degree in computer science?

That’s _not_ the case.

All you need to master computer vision and deep learning is for someone to explain things to you in _simple, intuitive_ terms. _And that’s exactly what I do_. My mission is to change education and how complex Artificial Intelligence topics are taught.

If you're serious about learning computer vision, your next stop should be PyImageSearch University, the most comprehensive computer vision, deep learning, and OpenCV course online today. Here you’ll learn how to _successfully_ and _confidently_ apply computer vision to your work, research, and projects. Join me in computer vision mastery.

**Inside PyImageSearch University you'll find:**

*   ✓ **84 courses** on essential computer vision, deep learning, and OpenCV topics
*   ✓ **84 Certificates** of Completion
*   ✓ **114+ hours** of on-demand video
*   ✓ **Brand new courses released _regularly_**, ensuring you can keep up with state-of-the-art techniques
*   ✓ **Pre-configured Jupyter Notebooks in Google Colab**
*   ✓ Run all code examples in your web browser — works on Windows, macOS, and Linux (no dev environment configuration required!)
*   ✓ Access to **centralized code repos for _all_ 536+ tutorials** on PyImageSearch
*   ✓ **Easy one-click downloads** for code, datasets, pre-trained models, etc.
*   ✓ **Access** on mobile, laptop, desktop, etc.

[Click here to join PyImageSearch University](https://pyimagesearch.com/pyimagesearch-university/?utm_source=blogPost&utm_medium=bottomBanner&utm_campaign=What%27s%20next%3F%20I%20recommend)

* * *

[Summary](#TOC)
---------------

In this blog post I discussed the _Intersection over Union_ metric used to evaluate object detectors. This metric can be used to assess _any_ object detector provided that (1) the model produces predicted _(x, y)_\-coordinates \[i.e., the bounding boxes\] for the object(s) in the image and (2) you have the ground-truth bounding boxes for your dataset.

Typically, you’ll see this metric used for evaluating HOG + Linear SVM and CNN-based object detectors.

To learn more about training your own custom object detectors, please refer to this blog post on the [HOG + Linear SVM framework](https://pyimagesearch.com/2014/11/10/histogram-oriented-gradients-object-detection/) along with the [_**PyImageSearch Gurus course**_](https://pyimagesearch.com/pyimagesearch-gurus/) where I demonstrate how to implement custom object detectors from scratch. If you’d like to dive deeper, consider [studying computer vision](https://pyimagesearch.com/) with our free course.

_**Finally, before you go, be sure to enter your email address in the form below to be notified when future PyImageSearch blog posts are published — you won’t want to miss them!**_

![Image 13](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20410%20567'%3E%3C/svg%3E)

#### Download the Source Code and FREE 17-page Resource Guide

Enter your email address below to get a .zip of the code and a **FREE 17-page Resource Guide on Computer Vision, OpenCV, and Deep Learning.** Inside you'll find my hand-picked tutorials, books, courses, and libraries to help you master CV and DL!