Closed CRISZJ closed 3 years ago
Here, the IoU is defined on vowelized shapes (voxel=1 for inside, voxel=0 for outside). The IoU between shape A and b equals the size of their intersection area divided by the size of their union area. See the below code as an example:
def IoUarr(arr1, arr2, inside=0, reduce_mean=True):
"""Calculate IoU for two batched input binary arrays. Default 0 for inside, 1 for outside.
:param arr1: ndarray. (B, D1, D2, ...)
:param arr2: ndarray. (B, D1, D2, ...)
:param inside: int. Inside label, 0 or 1.
:param reduce_mean: Boolean. Reduce mean over batch.
:return:
"""
if not arr1.shape == arr2.shape:
raise ValueError("Two input arrays should be of equal size.")
if not inside == 1:
arr1 = (1 - arr1).astype(np.bool)
arr2 = (1 - arr2).astype(np.bool)
axes = tuple(range(1, len(arr1.shape)))
intersection = np.sum(np.logical_and(arr1, arr2), axes)
union = np.sum(np.logical_or(arr1, arr2), axes)
iou = intersection / union
if reduce_mean:
iou = np.mean(iou)
return iou
ok, got it. thanks very much.
Hello, I am sorry to disturb you. I want to know how your IoU is calculated. I know that IoU is used a lot in CV detection. thanks. ----best