Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix numpy >= 1.20 np.bool deprecation #832

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion imgaug/augmentables/polys.py
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ def extract_from_image(self, image):
rr_face, cc_face = skimage.draw.polygon(
yy_mask, xx_mask, shape=(height_mask, width_mask))

mask = np.zeros((height_mask, width_mask), dtype=np.bool)
mask = np.zeros((height_mask, width_mask), dtype=bool)
mask[rr_face, cc_face] = True

if image.ndim == 3:
Expand Down
2 changes: 1 addition & 1 deletion imgaug/augmenters/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -3384,7 +3384,7 @@ def _get_augmenter_active(self, nb_rows, random_state):
# pylint: disable=invalid-name
nn = self._get_n(nb_rows, random_state)
nn = [min(n, len(self)) for n in nn]
augmenter_active = np.zeros((nb_rows, len(self)), dtype=np.bool)
augmenter_active = np.zeros((nb_rows, len(self)), dtype=bool)
for row_idx, n_true in enumerate(nn):
if n_true > 0:
augmenter_active[row_idx, 0:n_true] = 1
Expand Down
8 changes: 4 additions & 4 deletions test/augmentables/test_bbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ def test_draw_label_on_image(self):
def _get_standard_draw_box_on_image_vars(cls):
image = np.zeros((10, 10, 3), dtype=np.uint8)
bb = ia.BoundingBox(y1=1, x1=1, y2=3, x2=3)
bb_mask = np.zeros(image.shape[0:2], dtype=np.bool)
bb_mask = np.zeros(image.shape[0:2], dtype=bool)
bb_mask[1:3+1, 1] = True
bb_mask[1:3+1, 3] = True
bb_mask[1, 1:3+1] = True
Expand Down Expand Up @@ -823,7 +823,7 @@ def test_draw_box_on_image_no_copy(self):
def test_draw_box_on_image_bb_outside_of_image(self):
image = np.zeros((10, 10, 3), dtype=np.uint8)
bb = ia.BoundingBox(y1=-1, x1=-1, y2=2, x2=2)
bb_mask = np.zeros(image.shape[0:2], dtype=np.bool)
bb_mask = np.zeros(image.shape[0:2], dtype=bool)
bb_mask[2, 0:3] = True
bb_mask[0:3, 2] = True

Expand All @@ -837,7 +837,7 @@ def test_draw_box_on_image_bb_outside_of_image(self):
def test_draw_box_on_image_bb_outside_of_image_and_very_small(self):
image, bb, bb_mask = self._get_standard_draw_box_on_image_vars()
bb = ia.BoundingBox(y1=-1, x1=-1, y2=1, x2=1)
bb_mask = np.zeros(image.shape[0:2], dtype=np.bool)
bb_mask = np.zeros(image.shape[0:2], dtype=bool)
bb_mask[0:1+1, 1] = True
bb_mask[1, 0:1+1] = True

Expand All @@ -850,7 +850,7 @@ def test_draw_box_on_image_bb_outside_of_image_and_very_small(self):

def test_draw_box_on_image_size_2(self):
image, bb, _ = self._get_standard_draw_box_on_image_vars()
bb_mask = np.zeros(image.shape[0:2], dtype=np.bool)
bb_mask = np.zeros(image.shape[0:2], dtype=bool)
bb_mask[0:5, 0:5] = True
bb_mask[2, 2] = False

Expand Down
22 changes: 11 additions & 11 deletions test/augmentables/test_kps.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ def test_draw_on_image(self):
kpi = ia.KeypointsOnImage(keypoints=kps, shape=(5, 5, 3))
image = np.zeros((5, 5, 3), dtype=np.uint8) + 10

kps_mask = np.zeros(image.shape[0:2], dtype=np.bool)
kps_mask = np.zeros(image.shape[0:2], dtype=bool)
kps_mask[2, 1] = 1
kps_mask[4, 3] = 1

Expand All @@ -640,7 +640,7 @@ def test_draw_on_image_alpha_is_50_percent(self):
kpi = ia.KeypointsOnImage(keypoints=kps, shape=(5, 5, 3))
image = np.zeros((5, 5, 3), dtype=np.uint8) + 10

kps_mask = np.zeros(image.shape[0:2], dtype=np.bool)
kps_mask = np.zeros(image.shape[0:2], dtype=bool)
kps_mask[2, 1] = 1
kps_mask[4, 3] = 1

Expand All @@ -659,7 +659,7 @@ def test_draw_on_image_size_3(self):
kpi = ia.KeypointsOnImage(keypoints=kps, shape=(5, 5, 3))
image = np.zeros((5, 5, 3), dtype=np.uint8) + 10

kps_mask = np.zeros(image.shape[0:2], dtype=np.bool)
kps_mask = np.zeros(image.shape[0:2], dtype=bool)
kps_mask[2, 1] = 1
kps_mask[4, 3] = 1

Expand All @@ -678,7 +678,7 @@ def test_draw_on_image_blue_color(self):
kpi = ia.KeypointsOnImage(keypoints=kps, shape=(5, 5, 3))
image = np.zeros((5, 5, 3), dtype=np.uint8) + 10

kps_mask = np.zeros(image.shape[0:2], dtype=np.bool)
kps_mask = np.zeros(image.shape[0:2], dtype=bool)
kps_mask[2, 1] = 1
kps_mask[4, 3] = 1

Expand All @@ -694,7 +694,7 @@ def test_draw_on_image_single_int_as_color(self):
kpi = ia.KeypointsOnImage(keypoints=kps, shape=(5, 5, 3))
image = np.zeros((5, 5, 3), dtype=np.uint8) + 10

kps_mask = np.zeros(image.shape[0:2], dtype=np.bool)
kps_mask = np.zeros(image.shape[0:2], dtype=bool)
kps_mask[2, 1] = 1
kps_mask[4, 3] = 1

Expand All @@ -710,7 +710,7 @@ def test_draw_on_image_copy_is_false(self):
kpi = ia.KeypointsOnImage(keypoints=kps, shape=(5, 5, 3))
image = np.zeros((5, 5, 3), dtype=np.uint8) + 10

kps_mask = np.zeros(image.shape[0:2], dtype=np.bool)
kps_mask = np.zeros(image.shape[0:2], dtype=bool)
kps_mask[2, 1] = 1
kps_mask[4, 3] = 1

Expand All @@ -733,7 +733,7 @@ def test_draw_on_image_keypoint_is_outside_of_image(self):
)
image = np.zeros((5, 5, 3), dtype=np.uint8) + 10

kps_mask = np.zeros(image.shape[0:2], dtype=np.bool)
kps_mask = np.zeros(image.shape[0:2], dtype=bool)
kps_mask[2, 1] = 1
kps_mask[4, 3] = 1

Expand Down Expand Up @@ -766,7 +766,7 @@ def test_draw_on_image_one_kp_at_bottom_right_corner(self):
shape=(5, 5, 3))
image = np.zeros((5, 5, 3), dtype=np.uint8) + 10

kps_mask = np.zeros(image.shape[0:2], dtype=np.bool)
kps_mask = np.zeros(image.shape[0:2], dtype=bool)
kps_mask[2, 1] = 1
kps_mask[4, 3] = 1

Expand All @@ -784,7 +784,7 @@ def test_draw_on_image_one_kp_at_bottom_right_corner_and_raise_true(self):
shape=(5, 5, 3))
image = np.zeros((5, 5, 3), dtype=np.uint8) + 10

kps_mask = np.zeros(image.shape[0:2], dtype=np.bool)
kps_mask = np.zeros(image.shape[0:2], dtype=bool)
kps_mask[2, 1] = 1
kps_mask[4, 3] = 1

Expand Down Expand Up @@ -908,7 +908,7 @@ def test_to_keypoint_image_size_1(self):

image = kpi.to_keypoint_image(size=1)

kps_mask = np.zeros((5, 5, 2), dtype=np.bool)
kps_mask = np.zeros((5, 5, 2), dtype=bool)
kps_mask[2, 1, 0] = 1
kps_mask[4, 3, 1] = 1
assert np.all(image[kps_mask] == 255)
Expand All @@ -920,7 +920,7 @@ def test_to_keypoint_image_size_3(self):

image = kpi.to_keypoint_image(size=3)

kps_mask = np.zeros((5, 5, 2), dtype=np.bool)
kps_mask = np.zeros((5, 5, 2), dtype=bool)
kps_mask[2-1:2+1+1, 1-1:1+1+1, 0] = 1
kps_mask[4-1:4+1+1, 3-1:3+1+1, 1] = 1
assert np.all(image[kps_mask] >= 128)
Expand Down
2 changes: 1 addition & 1 deletion test/augmentables/test_segmaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def test_bool_arr_3d(self):
def test_boolean_masks(self):
# Test for #189 (boolean mask inputs into SegmentationMapsOnImage not
# working)
for dt in [bool, np.bool]:
for dt in [bool, bool]:
arr = np.array([
[0, 0, 0],
[0, 1, 0],
Expand Down
4 changes: 2 additions & 2 deletions test/test_imgaug.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class _Dummy(object):
np.zeros((1, 2), dtype=np.float16),
np.zeros((100,), dtype=np.float32),
np.zeros((1, 2), dtype=np.float64),
np.zeros((1, 2), dtype=np.bool)
np.zeros((1, 2), dtype=bool)
]
for value in values_true:
assert ia.is_integer_array(value) is True
Expand All @@ -250,7 +250,7 @@ class _Dummy(object):
np.zeros((1, 2), dtype=np.uint16),
np.zeros((1, 2), dtype=np.int32),
np.zeros((1, 2), dtype=np.int64),
np.zeros((1, 2), dtype=np.bool)
np.zeros((1, 2), dtype=bool)
]
for value in values_true:
assert ia.is_float_array(value) is True
Expand Down