Depth articles - image processing methods (ii) and IOU elaborate performance evaluation GIOU

Skip to main content

Contents return some methods of image processing

Previous: depth articles - image processing methods (a)  on three levels of image processing and selective search

Next: Depth articles - image processing methods (iii)   elaborate HOG features and bag-of-word

 

In this section, elaborate and performance evaluation Giou IOU, and the next section HOG features elaborate bag-of-word

 

GIOU 论文地址:Generalized Intersection over Union: A Metric and A Loss for Bounding Box Regression

 

Performance Evaluation

Naturally, the object bounding boxes and comprising ground true (truth) is obtained by calculation window overlap more, then the better the performance.

 

三. IOU (Instersectiou Over Union, IOU)

1. IOU is a measure of a particular data set corresponding to the detection accuracy of a standard object.

2. IOU's formula:

             \LARGE IOU(g_{c, i}, l_{j}) = \frac{area(g_{c, i}) \cap area(l_{j})}{area(g_{c, i}) \cup area(l_{j})}

         \large g_{c, i}: For each fixed to the of class C, each ground true (truth) is represented  \large g_{c, i}, wherein \large g_{c, i} \in G_{c}

         \large l_{j}: For each bounding box, which \large l_{j} \in L

         In fact, \large IOU = \frac{A \cap B}{A \cup B} the area ratio.

      

 

      IOU's loss is:

              \ LARGE L_ {IOU} = 1 - IOU

 

3. IOU python code

#!/usr/bin/env python
# _*_ coding:utf-8 _*_
# ============================================
# @Time     : 2020/02/01 16:04
# @Author   : WanDaoYi
# @FileName : bbox_iou.py
# ============================================

import numpy as np


# IOU
def bboxes_iou(boxes1, boxes2):
    boxes1 = np.array(boxes1)
    boxes2 = np.array(boxes2)

    # 计算 面积
    boxes1_area = (boxes1[..., 2] - boxes1[..., 0]) * (boxes1[..., 3] - boxes1[..., 1])
    boxes2_area = (boxes2[..., 2] - boxes2[..., 0]) * (boxes2[..., 3] - boxes2[..., 1])

    # 交集的 左上角坐标
    left_up = np.maximum(boxes1[..., :2], boxes2[..., :2])
    # 交集的 右下角坐标
    right_down = np.minimum(boxes1[..., 2:], boxes2[..., 2:])

    # 计算交集矩形框的 high 和 width
    inter_section = np.maximum(right_down - left_up, 0.0)

    # 两个矩形框的 交集 面积
    inter_area = inter_section[..., 0] * inter_section[..., 1]

    # 两个矩形框的并集面积
    union_area = boxes1_area + boxes2_area - inter_area
    # 计算 iou
    ious = np.maximum(1.0 * inter_area / union_area, np.finfo(np.float32).eps)

    return ious

4. MABO (Mean Average Best Overlap, MABO) overlapping the highest average rate

    In doing performance evaluation time, sometimes with MABO to assess its formula is as follows:

          \LARGE ABO = \frac{1}{|G_{c}|} \sum_{g_{c, i} \in G_{c}} \max_{l_{j} \in L} IOU(g_{c, i}, l_{j})

   For performance evaluation in all categories, it is natural to assess performance in all categories, it is natural to use the average of all categories of ABO MABO evaluated.

 

5. single policy evaluation

    You can change any of the diversity strategy, performance assessment MABO selective search. Policy papers taken are as follows:

    (1) using the RGB color space (FIG based divided image may be an image with a different color area division)

    (2) using the four kinds of combinations calculated similarity

    (3) Set the threshold for image segmentation k = 50

    Then, by changing one policy parameters, obtain MABO performance indicators.

 

6. Diversity strategy combination

    Greedy search algorithm, the combination of a single strategy, will get a higher MABO, however, will result in increased computational cost.

 

四. GIOU (Generalized IOU, GIOU) 广义 IOU

          

1. For IOU has the following two drawbacks:

   (1) When  \large IOU(B^{p}, B^{g}) = 0 , that is bounding box with ground true when there is no intersection, can not know the bounding box of each other near the ground true is still very far away.

          \large B^{p}: Is predicted box, is the bounding box, the corresponding coordinates \large (x_{1}^{p},\; y_{1}^{p},\; x_{2}^{p},\; y_{2}^{p})

          \large B^{g}: Is ground true, the corresponding coordinates \large (x_{1}^{g},\; y_{1}^{g},\; x_{2}^{g},\; y_{2}^{g})

   . (2) IOU alignment can not distinguish different ways, such as direction and inconsistent, as follows:

 

2. GIOU IOU optimized is calculated as follows:

   \large B^{p}: Is predicted box, is the bounding box, the corresponding coordinates \large (x_{1}^{p},\; y_{1}^{p},\; x_{2}^{p},\; y_{2}^{p})

   \large B^{g}: Is ground true, the corresponding coordinates \large (x_{1}^{g},\; y_{1}^{g},\; x_{2}^{g},\; y_{2}^{g})

   (1) Calculation  \large B^{p} of the area

          \LARGE \hat{x}_{1}^{p} = \min (x_{1}^{p},\; x_{2}^{p})

          \LARGE \hat{x}_{2}^{p} = \max (x_{1}^{p},\; x_{2}^{p})

          \LARGE \hat{y}_{1}^{p} = \min (y_{1}^{p},\; y_{2}^{p})

          \LARGE \hat{y}_{2}^{p} = \max (y_{1}^{p},\; y_{2}^{p})

          \LARGE A^{p} = (\hat{x}_{2}^{p} - \hat{x}_{1}^{p}) \times (\hat{y}_{2}^{p} - \hat{y}_{1}^{p})

   (2) Calculate  \large B^{g} the area (empathy) of

          \LARGE A^{g} = (x_{2}^{g} - x_{1}^{g}) \times (y_{2}^{g} - y_{1}^{g})

 

   (3) computing  \large A^{p} \cap A^{g} the area \large I

          \LARGE x_{1}^{I} = max (\hat{x}_{1}^{p},\; x_{1}^{g})

          \LARGE x_{2}^{I} = min (\hat{x}_{2}^{p},\; x_{2}^{g})

          \LARGE y_{1}^{I} = max (\hat{y}_{1}^{p},\; y_{1}^{g})

          \LARGE y_{2}^{I} = min (\hat{y}_{2}^{p},\; y_{2}^{g})

          \LARGE I = \left\{\begin{matrix} (x_{2}^{I} - x_{1}^{I}) \times (y_{2}^{I} - y_{1}^{I}) & \;\;\; if \; x_{2}^{I} > x_{1}^{I},\; y_{2}^{I} > y_{1}^{I} \\ 0 & otherwise \end{matrix}\right.

 

   . (4) comprises a calculation  \large B^{p} and a  \large B^{g} minimum sealing area Box   \large B^{c}:

          \LARGE x_{1}^{c} = min (\hat{x}_{1}^{p},\; x_{1}^{g})

          \LARGE x_{2}^{c} = max (\hat{x}_{2}^{p},\; x_{2}^{g})

          \LARGE y_{1}^{c} = min (\hat{y}_{1}^{p},\; y_{1}^{g})

          \LARGE y_{2}^{c} = max (\hat{y}_{2}^{p},\; y_{2}^{g})​​​​​​​

          \LARGE A^{c} = (x_{2}^{c} - x_{1}^{c}) \times (y_{2}^{c} - y_{1}^{c})

          \LARGE IOU = \frac{I}{U} \;\;\;\;\;\;\; (U = A^{p} + A^{g} - I)

          \LARGE GIOU = IOU - \frac{A^{c} - U}{A^{c}}

        GIOU of loss as follows:

           \ LARGE L_ {GIOU} = 1 - GIOU

 

3. GIOU optimization of understanding

    Calculated by:

           \ Large 0 \ leq IOU \ leq 1

           \ Large -1 \ leq GIOU \ leq 1

    (1) When the IOU = 0, IOU can not be optimized. The  \large L_{GIOU} behavior:

               \ Large L_ {GIOU} = 1 - GIOU = 1 + \ frac {A ^ {c} - U} {A ^ {c}} - IOU

         When  \large B^{p} the  \large B^{g} time does not intersect, i.e.  \ Large I = 0 \; \; (IOU = 0), this case  \large L_{GIOU} reduces to:

               \large L_{GIOU} = 1 + \frac{A^{c} - U}{A^{c}} = 2 - \frac{U}{A^{c}}

          Minimizing the need to maximize GIOU loss  \large \frac{U}{A^{c}}, which is an already normalized, i.e.  \large 0 \leq \frac{U}{A^{c}} \leq 1, one which is required to maximize and minimize  \large A^{c}, maximize the same time  \large U, because  \large I = 0, therefore  \large U = B^{p} + B^{g}, since the  \large B^{g} known and fixed, it is necessary to maximum technology  \large B^{p}, that is, minimize  \large A^{c} and maximize the same time  \large B^{p}, obviously, which makes  \large B^{p} tend to  \large B^{g} coincide.        

    (2) because when  \ Large GIOU \ leq 0 the time, GIOU still can be optimized, so, GIOU only to retain the original nature of the IOU, while weakening its weaknesses, so the paper can be considered as an IOU GIOU replacement.

 

4. GIOU python code:

#!/usr/bin/env python
# _*_ coding:utf-8 _*_
# ============================================
# @Time     : 2020/02/01 16:04
# @Author   : WanDaoYi
# @FileName : bbox_giou.py
# ============================================

import tensorflow as tf


def bbox_giou(boxes1, boxes2):
    # 将 中心点 与 high 和 width 转为 左上 和 右下 坐标点
    boxes1 = tf.concat([boxes1[..., :2] - boxes1[..., 2:] * 0.5,
                        boxes1[..., :2] + boxes1[..., 2:] * 0.5], axis=-1)
    boxes2 = tf.concat([boxes2[..., :2] - boxes2[..., 2:] * 0.5,
                        boxes2[..., :2] + boxes2[..., 2:] * 0.5], axis=-1)

    # 获取 框 的 左上角 和 右下角 的坐标值
    boxes1 = tf.concat([tf.minimum(boxes1[..., :2], boxes1[..., 2:]),
                        tf.maximum(boxes1[..., :2], boxes1[..., 2:])], axis=-1)
    boxes2 = tf.concat([tf.minimum(boxes2[..., :2], boxes2[..., 2:]),
                        tf.maximum(boxes2[..., :2], boxes2[..., 2:])], axis=-1)

    # 计算 面积
    boxes1_area = (boxes1[..., 2] - boxes1[..., 0]) * (boxes1[..., 3] - boxes1[..., 1])
    boxes2_area = (boxes2[..., 2] - boxes2[..., 0]) * (boxes2[..., 3] - boxes2[..., 1])

    # 计算交集的 左上角 和 右下角 坐标
    left_up = tf.maximum(boxes1[..., :2], boxes2[..., :2])
    right_down = tf.minimum(boxes1[..., 2:], boxes2[..., 2:])

    # 计算 交集 的 high 和 width
    inter_section = tf.maximum(right_down - left_up, 0.0)
    # 计算 交集 的面积
    inter_area = inter_section[..., 0] * inter_section[..., 1]
    # 计算 并集 的面积
    union_area = boxes1_area + boxes2_area - inter_area
    # 计算 IOU
    iou = inter_area / union_area

    # 计算最小密封框 的 左上角 坐标
    enclose_left_up = tf.minimum(boxes1[..., :2], boxes2[..., :2])
    # 计算最小密封框 的 右下角 坐标
    enclose_right_down = tf.maximum(boxes1[..., 2:], boxes2[..., 2:])
    # 计算最小密封框 的 high 和 width
    enclose = tf.maximum(enclose_right_down - enclose_left_up, 0.0)
    # 计算最小密封框 的 面积
    enclose_area = enclose[..., 0] * enclose[..., 1]
    # 计算 GIOU
    giou = iou - 1.0 * (enclose_area - union_area) / enclose_area

    return giou

 

                  

 

 

Skip to main content

Contents return some methods of image processing

Previous: depth articles - image processing methods (a)  on three levels of image processing and selective search

Next: Depth articles - image processing methods (iii)   elaborate HOG features and bag-of-word

Published 63 original articles · won praise 16 · views 5991

Guess you like

Origin blog.csdn.net/qq_38299170/article/details/104434443