Intersection over Union(IoU)

ChangSeong Yooยท2023๋…„ 7์›” 20์ผ
0

Machine Learning

๋ชฉ๋ก ๋ณด๊ธฐ
2/5
post-thumbnail
post-custom-banner

๐Ÿ“์ด ํฌ์ŠคํŠธ๋Š” Intersection over Union์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.




์ •์˜

IoU๋Š” ๊ฐ์ฒด ํƒ์ง€์˜ ์ •ํ™•๋„๋ฅผ ์ธก์ •ํ•˜๋Š”๋ฐ ์ด์šฉ๋˜๋Š” ํ‰๊ฐ€ ์ง€ํ‘œ์ž…๋‹ˆ๋‹ค.
IoU๋Š” ์˜ˆ์ธกํ•œ ์˜์—ญ๊ณผ ์‹ค์ œ ์˜์—ญ ๊ฐ„์˜ ๊ฒน์น˜๋Š” ์˜์—ญ์˜ ๋น„์œจ์„ ๊ณ„์‚ฐํ•ฉ๋‹ˆ๋‹ค.
์˜ˆ์ธกํ•œ ์˜์—ญ์€ test ์‹œ ๋ชจ๋ธ์ด ์˜ˆ์ธกํ•œ ์˜์—ญ์„ ๋œปํ•ฉ๋‹ˆ๋‹ค.
์‹ค์ œ ์˜์—ญ์€ target data๋กœ ์‹ค์ œ ์ •๋‹ต์˜ ์˜์—ญ์„ ๋œปํ•ฉ๋‹ˆ๋‹ค.
์‹ค์ œ ์˜์—ญ๊ณผ ๋ชจ๋ธ์ด ์˜ˆ์ธกํ•œ ์˜์—ญ์˜ ์˜ค์ฐจ๋ฅผ ๊ตฌํ•˜์—ฌ ๋น„์œจ๋กœ ๋‚˜ํƒ€๋‚ด๋Š” ๊ฒƒ์„ Intersection over Union์ด๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค.




์›๋ฆฌ

IoU=AโˆฉBAโˆชBIoU = \frac{A \cap B}{A \cup B} ์„ ์ˆ˜์‹์œผ๋กœ ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ด๋ฏธ์ง€๋กœ ๋ณด๋ฉด ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

๋นจ๊ฐ„ bounding box๊ฐ€ ์‹ค์ œ ์˜์—ญ(target)์ด๊ณ  ํ•˜๋Š˜์ƒ‰ bounding box๊ฐ€ ๋ชจ๋ธ์ด ์˜ˆ์ธกํ•œ ์˜์—ญ์ž…๋‹ˆ๋‹ค.
์ด๋กœ์จ ๋‘ bounding box๊ฐ€ ์ตœ๋Œ€ํ•œ ๊ฒน์น ์ˆ˜๋ก ํ•ฉ์ง‘ํ•ฉ ์˜์—ญ์€ ์ค„์–ด๋“ค๊ณ โ†“\downarrow ๊ต์ง‘ํ•ฉ ์˜์—ญ์ด ์ฆ๊ฐ€โ†‘\uparrowํ•˜์—ฌ
๊ฐ’์ด 1์— ๊ฐ€๊นŒ์šธ์ˆ˜๋ก ์„ฑ๋Šฅ์ด ์ข‹์€ ๋ชจ๋ธ์ด๋ผ๊ณ  ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์œ„์˜ ๊ทธ๋ฆผ๊ณผ ๊ฐ™์ด ๋‘ ๊ต์ง‘ํ•ฉ ์˜์—ญ๊ณผ ํ•ฉ์ง‘ํ•ฉ ์˜์—ญ์ด ์ตœ๋Œ€ํ•œ ๊ฒน์ณ์•ผ IoU ์„ฑ๋Šฅ์ด ์ข‹๋‹ค๊ณ  ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.




์ฝ”๋“œ ์ดํ•ด

import numpy as np

def Intersection_over_Union(box1, box2):
	
    # ๊ต์ง‘ํ•ฉ ์˜์—ญ ์  ํƒ์ƒ‰
    x1 = np.maximum(box1[0], box2[0])
    y1 = np.maximum(box1[1], box2[1])
    x2 = np.minimum(box1[2], box2[2])
    y2 = np.minimum(box1[3], box2[3])
	
    # ๊ต์ง‘ํ•ฉ ์˜์—ญ
    intersection_area = np.maximum(0, x2 - x1 + 1) * np.maximum(0, y2 - y1 + 1)

    box1_area = (box1[2] - box1[0] + 1) * (box1[3] - box1[1] + 1)
    box2_area = (box2[2] - box2[0] + 1) * (box2[3] - box2[1] + 1)
	
    # ํ•ฉ์ง‘ํ•ฉ ์˜์—ญ
    union_area = box1_area + box2_area - intersection_area

    IoU = intersection_area / union_area

    return IoU
profile
๐’ฅ๐“Š๐“ƒ๐’พโ„ด๐“‡ ๐’Ÿ๐’ถ๐“‰๐’ถ ๐’ฎ๐’ธ๐’พโ„ฏ๐“ƒ๐“‰๐’พ๐“ˆ๐“‰
post-custom-banner

1๊ฐœ์˜ ๋Œ“๊ธ€

comment-user-thumbnail
2023๋…„ 7์›” 20์ผ

์ข‹์€ ๊ธ€ ์ž˜ ์ฝ์—ˆ์Šต๋‹ˆ๋‹ค, ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

๋‹ต๊ธ€ ๋‹ฌ๊ธฐ