簡體   English   中英

對工會理解的交集?

[英]Intersection over union understanding?

正在在線閱讀一些代碼以在 python 中實現 IOU,其中大部分部分我非常了解,但對於它的核心數學存在一些混淆。

這是代碼:

def get_iou(boxA, boxB):
    # This will calculate boxes given in any order...
    # This will get max value between 2 boxes becuase max mening overlapping 
    # area just begins for x 
    interxA = max(boxA[0], boxB[0])
    # This will get max value between 2 boxes becuase max mening overlapping 
    # area just begins for y
    interyA = max(boxA[1], boxB[1])
    # This will get min value between 2 boxes becuase min mening overlapping 
    # area just begins for x because bottom right should be less as it's ending
    interxB = min(boxA[2], boxB[2])
    # This will get min value between 2 boxes becuase min mening overlapping 
    # area just begins for y because bottom right should be less as it's ending
    interyB = min(boxA[3], boxB[3])

    # Now basic concept to find area of any rectangle in co-ordinate plane we 
    # can think in this way, this is values top-left: (xa, ya), 
    # bottom-right: (xb, yb)
    # (xb - xa + 1) * (yb - ya + 1) this formula will yield us the area of that 
    # rectangle


    # this will find area of intersection rectangle
    interArea = max(0, interxB - interxA + 1) * max(0, interyB - interyA + 1)

    boxAarea = (boxA[2] - boxA[0] + 1) * (boxA[3] - boxA[1] + 1)
    boxBarea = (boxB[2] - boxB[0] + 1) * (boxB[3] - boxB[1] + 1)

    return (interArea / (boxAarea + boxBarea - interArea))

在上面的代碼中,為什么我們使用“+ 1”作為代碼的一部分,因為我檢查了有沒有這樣的代碼:get_iou([25, 25, 175, 200], [45, 45, 175, 200])它改變了,但只有幾個小數位? 如果我使用它是否重要,如果某些機構甚至可以解釋我們為什么需要它,這將更有幫助。 提前致謝。

這可能是一個代碼調整,以防止分數的分母在某些情況下為 0。 例如,如果我們從代碼中刪除+1並且兩個框相等,我們會得到返回 0/0。 在數學上這被解釋為 1,但在計算上這將是一個數學錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM