728x90
반응형
본 포스팅은 위치기반 민감도 특이도를 구할 때 3D bbox dice를 계산하여 필터링에 도움이 될 만한 3D dice score 계산 코드에 대해 설명하겠다.
(기본적인 Dice 설명은 아래의 링크에 참고해 주세요.)
Dice 설명 : https://baembaembaem.tistory.com/99
[Python] Dice score 코드 만들기 (segmentation 평가)
본 포스팅은 Dice score에 대한 기본적인 내용을 정리 후 python에서 segmentation 성능 평가 사용되도록 contour dice score 및 bbox dice score 계산하는 코드를 구성하고자 한다. Dice score coefficient (DSC) Dice score는
baembaembaem.tistory.com
3D DICE score
오늘은 contour가 아닌 좌표 기반의 bbox 들의 dice를 계산하는 코드에 대해 설명해 보겠다.
def DICE_3D(self, box1, box2):
box1_area = (box1[1] - box1[0] + 1) * (box1[3] - box1[2] + 1) * (box1[5] - box1[4] + 1)
box2_area = (box2[1] - box2[0] + 1) * (box2[3] - box2[2] + 1) * (box2[5] - box2[4] + 1)
x1 = max(box1[0], box2[0])
y1 = max(box1[2], box2[2])
z1 = max(box1[4], box2[4])
x2 = min(box1[1], box2[1])
y2 = min(box1[3], box2[3])
z2 = min(box1[5], box2[5])
w = max(0, x2 - x1 + 1)
h = max(0, y2 - y1 + 1)
d = max(0, z2 - z1 + 1)
inter = w * h * d
dice = inter * 2 / (box1_area + box2_area)
return dice
입력은 box1과 box2이며, 부피라고 생각하면 쉽게 이해가 될 것이다.
box1_area와 box2_area는 각 bbox의 영역 크기이며, 각 축 (x,y,z)에 해당하는 겹치는 길이는 w,h,d로 선언한 뒤 이를 곱해주어 겹치는 부피를 구한다.
만약 w,h,d 중 하나라도 0이라면 두 bbox는 겹치지 않는 것이기 때문에 dice 분자는 0이 되어 score는 '0'이 될 것이다.
3D IOU score
아래 함수는 동일하지만, Dice가 아닌 IoU 성능 평가 함수이다.
def IOU_3D(self, box1, box2):
box1_area = (box1[1] - box1[0] + 1) * (box1[3] - box1[2] + 1) * (box1[5] - box1[4] + 1)
box2_area = (box2[1] - box2[0] + 1) * (box2[3] - box2[2] + 1) * (box2[5] - box2[4] + 1)
x1 = max(box1[0], box2[0])
y1 = max(box1[2], box2[2])
z1 = max(box1[4], box2[4])
x2 = min(box1[1], box2[1])
y2 = min(box1[3], box2[3])
z2 = min(box1[5], box2[5])
w = max(0, x2 - x1 + 1)
h = max(0, y2 - y1 + 1)
d = max(0, z2 - z1 + 1)
inter = w * h * d
iou = inter / (box1_area + box2_area - inter)
return iou
728x90
반응형
'Python' 카테고리의 다른 글
[Python] sys.modules, __getattr__, __setattr__ 활용하기 (0) | 2023.02.11 |
---|---|
[Python] try except 활용하여 오류 모아보기 (0) | 2023.02.08 |
[Python] Dice score 코드 만들기 (segmentation 평가) (0) | 2023.01.09 |
[Python] upper, lower, isupper, islower - 문자열 대문자, 소문자 변경 및 확인하기 (0) | 2022.09.26 |
[Python] np.ceil, np.round, np.floor - 숫자 올림, 반올림, 버림 (0) | 2022.09.21 |
댓글