Skip to content

Commit

Permalink
Replace np.bool with np.bool_
Browse files Browse the repository at this point in the history
  • Loading branch information
ishaan-upadhyay committed Nov 23, 2023
1 parent e4547fb commit 6535f8d
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions mrcnn/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1270,14 +1270,14 @@ def hook(images, augmenter, parents, default):
# Make augmenters deterministic to apply similarly to images and masks
det = augmentation.to_deterministic()
image = det.augment_image(image)
# Change mask to np.uint8 because imgaug doesn't support np.bool
# Change mask to np.uint8 because imgaug doesn't support bool
mask = det.augment_image(mask.astype(np.uint8),
hooks=imgaug.HooksImages(activator=hook))
# Verify that shapes didn't change
assert image.shape == image_shape, "Augmentation shouldn't change image size"
assert mask.shape == mask_shape, "Augmentation shouldn't change mask size"
# Change mask back to bool
mask = mask.astype(np.bool)
mask = mask.astype(bool)

# Note that some boxes might be all zeros if the corresponding mask got cropped out.
# and here is to filter them out
Expand Down
8 changes: 4 additions & 4 deletions mrcnn/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ def minimize_mask(bbox, mask, mini_shape):
raise Exception("Invalid bounding box with area of zero")
# Resize with bilinear interpolation
m = resize(m, mini_shape)
mini_mask[:, :, i] = np.around(m).astype(np.bool)
mini_mask[:, :, i] = np.around(m).astype(bool)
return mini_mask


Expand All @@ -549,7 +549,7 @@ def expand_mask(bbox, mini_mask, image_shape):
w = x2 - x1
# Resize with bilinear interpolation
m = resize(m, (h, w))
mask[y1:y2, x1:x2, i] = np.around(m).astype(np.bool)
mask[y1:y2, x1:x2, i] = np.around(m).astype(bool)
return mask


Expand All @@ -569,10 +569,10 @@ def unmold_mask(mask, bbox, image_shape):
threshold = 0.5
y1, x1, y2, x2 = bbox
mask = resize(mask, (y2 - y1, x2 - x1))
mask = np.where(mask >= threshold, 1, 0).astype(np.bool)
mask = np.where(mask >= threshold, 1, 0).astype(bool)

# Put the mask in the right location.
full_mask = np.zeros(image_shape[:2], dtype=np.bool)
full_mask = np.zeros(image_shape[:2], dtype=bool)
full_mask[y1:y2, x1:x2] = mask
return full_mask

Expand Down
2 changes: 1 addition & 1 deletion samples/balloon/balloon.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def load_mask(self, image_id):

# Return mask, and array of class IDs of each instance. Since we have
# one class ID only, we return an array of 1s
return mask.astype(np.bool), np.ones([mask.shape[-1]], dtype=np.int32)
return mask.astype(bool), np.ones([mask.shape[-1]], dtype=np.int32)

def image_reference(self, image_id):
"""Return the path of the image."""
Expand Down
2 changes: 1 addition & 1 deletion samples/coco/coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def load_mask(self, image_id):

# Pack instance masks into an array
if class_ids:
mask = np.stack(instance_masks, axis=2).astype(np.bool)
mask = np.stack(instance_masks, axis=2).astype(bool)
class_ids = np.array(class_ids, dtype=np.int32)
return mask, class_ids
else:
Expand Down
4 changes: 2 additions & 2 deletions samples/nucleus/nucleus.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def load_mask(self, image_id):
mask = []
for f in next(os.walk(mask_dir))[2]:
if f.endswith(".png"):
m = skimage.io.imread(os.path.join(mask_dir, f)).astype(np.bool)
m = skimage.io.imread(os.path.join(mask_dir, f)).astype(bool)
mask.append(m)
mask = np.stack(mask, axis=-1)
# Return mask, and array of class IDs of each instance. Since we have
Expand Down Expand Up @@ -322,7 +322,7 @@ def rle_decode(rle, shape):
rle = np.array(rle, dtype=np.int32).reshape([-1, 2])
rle[:, 1] += rle[:, 0]
rle -= 1
mask = np.zeros([shape[0] * shape[1]], np.bool)
mask = np.zeros([shape[0] * shape[1]], bool)
for s, e in rle:
assert 0 <= s < mask.shape[0]
assert 1 <= e <= mask.shape[0], "shape: {} s {} e {}".format(shape, s, e)
Expand Down
2 changes: 1 addition & 1 deletion samples/shapes/train_shapes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@
" occlusion = np.logical_and(occlusion, np.logical_not(mask[:, :, i]))\n",
" # Map class names to class IDs.\n",
" class_ids = np.array([self.class_names.index(s[0]) for s in shapes])\n",
" return mask.astype(np.bool), class_ids.astype(np.int32)\n",
" return mask.astype(bool), class_ids.astype(np.int32)\n",
"\n",
" def draw_shape(self, image, shape, dims, color):\n",
" \"\"\"Draws a shape from the given specs.\"\"\"\n",
Expand Down

0 comments on commit 6535f8d

Please sign in to comment.