第14章コンピュータビジョン
14.4.2. Intersection over Union (IoU)14.4.2 IoU(Intersection over Union)
We just mentioned that an anchor box “well” surrounds the dog in the image. If the ground-truth bounding box of the object is known, how can “well” here be quantified? Intuitively, we can measure the similarity between the anchor box and the ground-truth bounding box. We know that the Jaccard index can measure the similarity between two sets. Given sets and , their Jaccard index is the size of their intersection divided by the size of their union:
英語のヒント
アンカーボックスが画像の中の犬を「うまく」囲んでいると述べたばかりである。物体の正解の境界ボックスがわかっているとき、ここでの「うまく」はどう定量化できるだろうか。直観的には、アンカーボックスと正解の境界ボックスの類似度を測ればよい。ジャカード係数は二つの集合の類似度を測れることがわかっている。集合とが与えられたとき、そのジャカード係数は、共通部分の大きさを和集合の大きさで割ったものである。
(14.4.2)
In fact, we can consider the pixel area of any bounding box as a set of pixels. In this way, we can measure the similarity of the two bounding boxes by the Jaccard index of their pixel sets. For two bounding boxes, we usually refer their Jaccard index as intersection over union (IoU), which is the ratio of their intersection area to their union area, as shown in Fig. 14.4.1. The range of an IoU is between 0 and 1: 0 means that two bounding boxes do not overlap at all, while 1 indicates that the two bounding boxes are equal.
英語のヒント
実際、どの境界ボックスの画素の領域も、画素の集合とみなせる。こうすると、二つの境界ボックスの類似度を、それらの画素の集合のジャカード係数で測れる。二つの境界ボックスについては、そのジャカード係数をふつうIoU(intersection over union)と呼ぶ。これは、図14.4.1に示すように、それらの共通部分の面積と和集合の面積の比である。IoUの範囲は0から1である。0は二つの境界ボックスがまったく重ならないことを意味し、1は二つの境界ボックスが等しいことを示す。
Fig. 14.4.1図14.4.1
IoU is the ratio of the intersection area to the union area of two bounding boxes.
英語のヒント
IoUは、二つの境界ボックスの共通部分の面積と和集合の面積の比である。
For the remainder of this section, we will use IoU to measure the similarity between anchor boxes and ground-truth bounding boxes, and between different anchor boxes. Given two lists of anchor or bounding boxes, the following
box_iou computes their pairwise IoU across these two lists.英語のヒント
この節の残りでは、IoUを使って、アンカーボックスと正解の境界ボックスの類似度、および異なるアンカーボックスのあいだの類似度を測る。アンカーボックスか境界ボックスの二つのリストが与えられると、次の
box_iouは、これら二つのリストにわたるペアごとのIoUを計算する。#@save
def box_iou(boxes1, boxes2):
"""Compute pairwise IoU across two lists of anchor or bounding boxes."""
box_area = lambda boxes: ((boxes[:, 2] - boxes[:, 0]) *
(boxes[:, 3] - boxes[:, 1]))
# Shape of `boxes1`, `boxes2`, `areas1`, `areas2`: (no. of boxes1, 4),
# (no. of boxes2, 4), (no. of boxes1,), (no. of boxes2,)
areas1 = box_area(boxes1)
areas2 = box_area(boxes2)
# Shape of `inter_upperlefts`, `inter_lowerrights`, `inters`: (no. of
# boxes1, no. of boxes2, 2)
inter_upperlefts = torch.max(boxes1[:, None, :2], boxes2[:, :2])
inter_lowerrights = torch.min(boxes1[:, None, 2:], boxes2[:, 2:])
inters = (inter_lowerrights - inter_upperlefts).clamp(min=0)
# Shape of `inter_areas` and `union_areas`: (no. of boxes1, no. of boxes2)
inter_areas = inters[:, :, 0] * inters[:, :, 1]
union_areas = areas1[:, None] + areas2 - inter_areas
return inter_areas / union_areas