-
Notifications
You must be signed in to change notification settings - Fork 304
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update utils.rst
'expected': np.zeros((0, 1)) | ||
}, | ||
) | ||
class TestmaskIou(unittest.TestCase): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TestMaskIou
'mask_b': np.array([[[False, False, True], [True, True]]], dtype=np.bool) | ||
}, | ||
) | ||
class TestmaskIouInvalidShape(unittest.TestCase): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TestMaskIou~
318038f
to
634cca1
Compare
I add doc, thx. |
chainercv/utils/mask/mask_iou.py
Outdated
|
||
n_mask_a = len(mask_a) | ||
n_mask_b = len(mask_b) | ||
iou = xp.zeros((n_mask_a, n_mask_b), dtype=xp.float32) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about using xp.empty
? Since all elements are updated in the following loop, iou
does not need to be initialized here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thx, i will updated.
chainercv/utils/mask/mask_iou.py
Outdated
n_mask_b = len(mask_b) | ||
iou = xp.zeros((n_mask_a, n_mask_b), dtype=xp.float32) | ||
for i, m_a in enumerate(mask_a): | ||
for j, m_b in enumerate(mask_b): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using n
and k
is consistent with the docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thx, i will updated.
chainercv/utils/mask/mask_iou.py
Outdated
n_mask_a = len(mask_a) | ||
n_mask_b = len(mask_b) | ||
iou = xp.zeros((n_mask_a, n_mask_b), dtype=xp.float32) | ||
for i, m_a in enumerate(mask_a): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove these loops by using numpy tricks.
i = xp.bitwise_and(mask_a[:, None], mask_b).sum(axis=(2,3))
u = xp.bitwise_or(mask_a[:, None], mask_b).sum(axis=(2,3))
return i / u
How do you think of it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A drawback is that it requires an array (N, K, H, W)
, where the original code requires only (H, W)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(N, K, H, W)
requires too much memory, so I write the original one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see.
LGTM |
add
mask_iou
function inutils