Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intersection-over-union between two detections

Tags:

I was reading through the paper : Ferrari et al. in the "Affinity Measures" section. I understood that Ferrari et al. tries to obtain affinity by :

  1. Location affinity - using area of intersection-over-union between two detections
  2. Appearance affinity - using Euclidean distances between Histograms
  3. KLT point affinity measure

However, I have 2 main problems:

  1. I cannot understand what is actually meant by intersection-over-union between 2 detections and how to calculate it
  2. I tried a slightly difference appearance affinity measure. I transformed the RGB detection into HSV..concatenating the Hue and Saturation into 1 vector, and used it to compare with other detections. However, using this technique failed as a detection of a bag had a better similarity score than a detection of the same person's head (with a different orientation).

Any suggestions or solutions to my problems described above? Thank you and your help is very much appreciated.

like image 773
Sambas23 Avatar asked Feb 25 '15 16:02

Sambas23


People also ask

How do you calculate IoU between two boxes?

Intersection over Union calculation example Area of Union: Area of the Red Bounding Box + Area of the Green Bounding Box - Area of Overlap = 10 10 + 10 10 - 25 = 175. IoU: Area of Overlap / Area of Union = 25 / 175 ~ 0.14 - poor IoU.

Can intersection over union be greater than 1?

The IoU can have any value between 0 and 1. If two boxes do not intersect, the IoU is 0. On the other hand, if they completely overlap, the intersection and the union areas are equal. So, in that case, the IoU is 1.

What is the intersection over union IoU of the following boxes?

Intersect over Union (IoU) is a metric that allows us to evaluate how similar our predicted bounding box is to the ground truth bounding box. The idea is that we want to compare the ratio of the area where the two boxes overlap to the total combined area of the two boxes.

Is intersection over union differentiable?

Yes, the intersection between two bounding boxes is differentiable with respect to the centers of each box, as well as their widths and heights. Usually, IoU is only used as an evaluation metric in inference, not training.


1 Answers

Try intersection over Union

Intersection over Union is an evaluation metric used to measure the accuracy of an object detector on a particular dataset.

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.

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

enter image description here

The predicted bounding box is drawn in red while the ground-truth (i.e., hand labeled) bounding box is drawn in green.

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

Computing Intersection over Union can therefore be determined via:

enter image description here

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

Here is the Python code

# 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"])  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 = (xB - xA) * (yB - yA)      # compute the area of both the prediction and ground-truth     # rectangles     boxAArea = (boxA[2] - boxA[0]) * (boxA[3] - boxA[1])     boxBArea = (boxB[2] - boxB[0]) * (boxB[3] - boxB[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 

The gt and pred are

  1. gt : The ground-truth bounding box.
  2. pred : The predicted bounding box from our model.

For more information, you can click this post

like image 58
GoingMyWay Avatar answered Sep 19 '22 13:09

GoingMyWay