Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

add mask_iou #552

Merged
merged 3 commits into from
Apr 3, 2018
Merged

add mask_iou #552

merged 3 commits into from
Apr 3, 2018

Conversation

knorth55
Copy link
Contributor

@knorth55 knorth55 commented Apr 3, 2018

add mask_iou function in utils

@knorth55 knorth55 self-assigned this Apr 3, 2018
@knorth55 knorth55 requested a review from yuyu2172 April 3, 2018 02:13
Copy link
Member

@Hakuyume Hakuyume left a 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):
Copy link
Member

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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestMaskIou~

@knorth55 knorth55 force-pushed the mask-iou branch 2 times, most recently from 318038f to 634cca1 Compare April 3, 2018 04:49
@knorth55
Copy link
Contributor Author

knorth55 commented Apr 3, 2018

I add doc, thx.


n_mask_a = len(mask_a)
n_mask_b = len(mask_b)
iou = xp.zeros((n_mask_a, n_mask_b), dtype=xp.float32)
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx, i will updated.

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):
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx, i will updated.

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):
Copy link
Member

@Hakuyume Hakuyume Apr 3, 2018

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?

Copy link
Member

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).

Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see.

@yuyu2172
Copy link
Member

yuyu2172 commented Apr 3, 2018

LGTM

@yuyu2172 yuyu2172 merged commit ea6c306 into chainer:master Apr 3, 2018
@knorth55 knorth55 deleted the mask-iou branch April 3, 2018 12:37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants