-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fix] Fix bitmap mask translate when out_shape is different. (#8993)
* [Fix] Fix bitmap mask translate when out_shape is different. * fix corner case * fix filename
- Loading branch information
Showing
2 changed files
with
52 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from unittest import TestCase | ||
|
||
import numpy as np | ||
from mmengine.testing import assert_allclose | ||
|
||
from mmdet.structures.mask import BitmapMasks | ||
|
||
|
||
class TestMaskStructures(TestCase): | ||
|
||
def test_bitmap_translate_same_size(self): | ||
mask_array = np.zeros((5, 10, 10), dtype=np.uint8) | ||
mask_array[:, 0:5, 0:5] = 1 | ||
mask_target = np.zeros((5, 10, 10), dtype=np.uint8) | ||
mask_target[:, 0:5, 5:10] = 1 | ||
|
||
mask = BitmapMasks(mask_array, 10, 10) | ||
mask = mask.translate((10, 10), 5) | ||
assert mask.masks.shape == (5, 10, 10) | ||
assert_allclose(mask_target, mask.masks) | ||
|
||
def test_bitmap_translate_diff_size(self): | ||
# test out shape larger | ||
mask_array = np.zeros((5, 10, 10), dtype=np.uint8) | ||
mask_array[:, 0:5, 0:5] = 1 | ||
|
||
mask_target = np.zeros((5, 20, 20), dtype=np.uint8) | ||
mask_target[:, 0:5, 5:10] = 1 | ||
mask = BitmapMasks(mask_array, 10, 10) | ||
mask = mask.translate((20, 20), 5) | ||
assert mask.masks.shape == (5, 20, 20) | ||
assert_allclose(mask_target, mask.masks) | ||
|
||
# test out shape smaller | ||
mask_array = np.zeros((5, 10, 10), dtype=np.uint8) | ||
mask_array[:, 0:5, 0:5] = 1 | ||
|
||
mask_target = np.zeros((5, 20, 8), dtype=np.uint8) | ||
mask_target[:, 0:5, 5:] = 1 | ||
mask = BitmapMasks(mask_array, 10, 10) | ||
mask = mask.translate((20, 8), 5) | ||
assert mask.masks.shape == (5, 20, 8) | ||
assert_allclose(mask_target, mask.masks) |