mean Intersection over Union(mIoU)의 이해 및 구현
6825 단어 Pythonsegmentation
표현식 1
$$
mIoU =\frac{1}{k}\sum_{i=1}^k\frac{N_{ii}}{\sum_{i=1}^k N_{ij} +\sum_{j=1}^k N_{ji} - N_{ii}}
$$
총결산
Acuracy의 이점
이루어지다
import numpy as np
from sklearn.metrics import confusion_matrix
def mIoU(true: np.ndarray, pred: np.ndarray) -> float:
"""Calculate mIoU between 2 class label arrays
Parameters
----------
true : np.ndarray
A 2d class label array
pred : np.ndarray
A 2d class label array of the same shape of true
Return
------
float
mIoU
"""
c_matrix = confusion_matrix(true.ravel(), pred.ravel())
intersection = np.diag(c_matrix)
union = np.sum(c_matrix, axis=0) + np.sum(c_matrix, axis=1) - intersection
iou = intersection / union
miou = np.mean(iou)
return miou
# Test
true = np.zeros((5, 5))
true[1:3, 1:3] = 1
pred = np.zeros((5, 5))
pred[2:4, 2:4] = 1
assert mIoU(true, pred) == np.mean([1 / 7, (5 * 5 - 7) / (5 * 5 - 1)])
print("true")
print(true)
print("pred")
print(pred)
print("mIoU = %.2f" % mIoU(true, pred))
이해와 실시에 오류가 있다면 지적해 주십시오.참고 자료
5. 실천 편: MRI 이미지 분할 - 의료 AI 전공 과정 온라인 강의 자료 문서
Reference
이 문제에 관하여(mean Intersection over Union(mIoU)의 이해 및 구현), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/krrka/items/9c531305a88a268954ea텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)