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] Deprecating old type alias due to new version of numpy #9537

Merged
merged 2 commits into from
Dec 30, 2022
Merged
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
4 changes: 2 additions & 2 deletions mmdet/datasets/transforms/augment_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class AutoAugment(RandomChoice):
- gt_bboxes (BaseBoxes[torch.float32]) (optional)
- gt_bboxes_labels (np.int64) (optional)
- gt_masks (BitmapMasks | PolygonMasks) (optional)
- gt_ignore_flags (np.bool) (optional)
- gt_ignore_flags (bool) (optional)
- gt_seg_map (np.uint8) (optional)

Modified Keys:
Expand Down Expand Up @@ -178,7 +178,7 @@ class RandAugment(RandomChoice):
- gt_bboxes (BaseBoxes[torch.float32]) (optional)
- gt_bboxes_labels (np.int64) (optional)
- gt_masks (BitmapMasks | PolygonMasks) (optional)
- gt_ignore_flags (np.bool) (optional)
- gt_ignore_flags (bool) (optional)
- gt_seg_map (np.uint8) (optional)

Modified Keys:
Expand Down
12 changes: 6 additions & 6 deletions mmdet/datasets/transforms/loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ class LoadAnnotations(MMCV_LoadAnnotations):
- gt_bboxes_labels (np.int64)
- gt_masks (BitmapMasks | PolygonMasks)
- gt_seg_map (np.uint8)
- gt_ignore_flags (np.bool)
- gt_ignore_flags (bool)

Args:
with_bbox (bool): Whether to parse and load the bbox annotation.
Expand Down Expand Up @@ -270,7 +270,7 @@ def _load_bboxes(self, results: dict) -> None:
else:
_, box_type_cls = get_box_type(self.box_type)
results['gt_bboxes'] = box_type_cls(gt_bboxes, dtype=torch.float32)
results['gt_ignore_flags'] = np.array(gt_ignore_flags, dtype=np.bool)
results['gt_ignore_flags'] = np.array(gt_ignore_flags, dtype=bool)

def _load_labels(self, results: dict) -> None:
"""Private function to load label annotations.
Expand Down Expand Up @@ -356,7 +356,7 @@ def _process_masks(self, results: dict) -> list:
gt_masks.append(gt_mask)
# re-process gt_ignore_flags
gt_ignore_flags.append(instance['ignore_flag'])
results['gt_ignore_flags'] = np.array(gt_ignore_flags, dtype=np.bool)
results['gt_ignore_flags'] = np.array(gt_ignore_flags, dtype=bool)
return gt_masks

def _load_masks(self, results: dict) -> None:
Expand Down Expand Up @@ -485,7 +485,7 @@ class LoadPanopticAnnotations(LoadAnnotations):
- gt_bboxes_labels (np.int64)
- gt_masks (BitmapMasks | PolygonMasks)
- gt_seg_map (np.uint8)
- gt_ignore_flags (np.bool)
- gt_ignore_flags (bool)

Args:
with_bbox (bool): Whether to parse and load the bbox annotation.
Expand Down Expand Up @@ -667,7 +667,7 @@ class FilterAnnotations(BaseTransform):
- gt_bboxes (BaseBoxes[torch.float32]) (optional)
- gt_bboxes_labels (np.int64) (optional)
- gt_masks (BitmapMasks | PolygonMasks) (optional)
- gt_ignore_flags (np.bool) (optional)
- gt_ignore_flags (bool) (optional)

Modified Keys:

Expand Down Expand Up @@ -758,7 +758,7 @@ class LoadEmptyAnnotations(BaseTransform):
- gt_bboxes_labels (np.int64)
- gt_masks (BitmapMasks | PolygonMasks)
- gt_seg_map (np.uint8)
- gt_ignore_flags (np.bool)
- gt_ignore_flags (bool)

Args:
with_bbox (bool): Whether to load the pseudo bbox annotation.
Expand Down
28 changes: 14 additions & 14 deletions mmdet/datasets/transforms/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,14 +419,14 @@ class RandomShift(BaseTransform):
- img
- gt_bboxes (BaseBoxes[torch.float32])
- gt_bboxes_labels (np.int64)
- gt_ignore_flags (np.bool) (optional)
- gt_ignore_flags (bool) (optional)

Modified Keys:

- img
- gt_bboxes
- gt_bboxes_labels
- gt_ignore_flags (np.bool) (optional)
- gt_ignore_flags (bool) (optional)

Args:
prob (float): Probability of shifts. Defaults to 0.5.
Expand Down Expand Up @@ -611,7 +611,7 @@ class RandomCrop(BaseTransform):
- gt_bboxes (BaseBoxes[torch.float32]) (optional)
- gt_bboxes_labels (np.int64) (optional)
- gt_masks (BitmapMasks | PolygonMasks) (optional)
- gt_ignore_flags (np.bool) (optional)
- gt_ignore_flags (bool) (optional)
- gt_seg_map (np.uint8) (optional)

Modified Keys:
Expand Down Expand Up @@ -1157,7 +1157,7 @@ class MinIoURandomCrop(BaseTransform):
- gt_bboxes (BaseBoxes[torch.float32]) (optional)
- gt_bboxes_labels (np.int64) (optional)
- gt_masks (BitmapMasks | PolygonMasks) (optional)
- gt_ignore_flags (np.bool) (optional)
- gt_ignore_flags (bool) (optional)
- gt_seg_map (np.uint8) (optional)

Modified Keys:
Expand Down Expand Up @@ -1554,7 +1554,7 @@ def _postprocess_results(
if 'gt_ignore_flags' in results and isinstance(
results['gt_ignore_flags'], list):
results['gt_ignore_flags'] = np.array(
results['gt_ignore_flags'], dtype=np.bool)
results['gt_ignore_flags'], dtype=bool)

if 'bboxes' in results:
if isinstance(results['bboxes'], list):
Expand Down Expand Up @@ -1656,15 +1656,15 @@ class RandomCenterCropPad(BaseTransform):
- img_shape (tuple)
- gt_bboxes (BaseBoxes[torch.float32]) (optional)
- gt_bboxes_labels (np.int64) (optional)
- gt_ignore_flags (np.bool) (optional)
- gt_ignore_flags (bool) (optional)

Modified Keys:

- img (np.float32)
- img_shape (tuple)
- gt_bboxes (BaseBoxes[torch.float32]) (optional)
- gt_bboxes_labels (np.int64) (optional)
- gt_ignore_flags (np.bool) (optional)
- gt_ignore_flags (bool) (optional)

Args:
crop_size (tuple, optional): expected size after crop, final size will
Expand Down Expand Up @@ -2094,7 +2094,7 @@ class Mosaic(BaseTransform):
- img
- gt_bboxes (BaseBoxes[torch.float32]) (optional)
- gt_bboxes_labels (np.int64) (optional)
- gt_ignore_flags (np.bool) (optional)
- gt_ignore_flags (bool) (optional)
- mix_results (List[dict])

Modified Keys:
Expand Down Expand Up @@ -2347,7 +2347,7 @@ class MixUp(BaseTransform):
- img
- gt_bboxes (BaseBoxes[torch.float32]) (optional)
- gt_bboxes_labels (np.int64) (optional)
- gt_ignore_flags (np.bool) (optional)
- gt_ignore_flags (bool) (optional)
- mix_results (List[dict])


Expand Down Expand Up @@ -2549,7 +2549,7 @@ class RandomAffine(BaseTransform):
- img
- gt_bboxes (BaseBoxes[torch.float32]) (optional)
- gt_bboxes_labels (np.int64) (optional)
- gt_ignore_flags (np.bool) (optional)
- gt_ignore_flags (bool) (optional)

Modified Keys:

Expand Down Expand Up @@ -2791,7 +2791,7 @@ class CopyPaste(BaseTransform):
- img
- gt_bboxes (BaseBoxes[torch.float32]) (optional)
- gt_bboxes_labels (np.int64) (optional)
- gt_ignore_flags (np.bool) (optional)
- gt_ignore_flags (bool) (optional)
- gt_masks (BitmapMasks) (optional)

Modified Keys:
Expand Down Expand Up @@ -2971,7 +2971,7 @@ class RandomErasing(BaseTransform):
- img
- gt_bboxes (HorizontalBoxes[torch.float32]) (optional)
- gt_bboxes_labels (np.int64) (optional)
- gt_ignore_flags (np.bool) (optional)
- gt_ignore_flags (bool) (optional)
- gt_masks (BitmapMasks) (optional)

Modified Keys:
Expand Down Expand Up @@ -3156,7 +3156,7 @@ class CachedMosaic(Mosaic):
- img
- gt_bboxes (np.float32) (optional)
- gt_bboxes_labels (np.int64) (optional)
- gt_ignore_flags (np.bool) (optional)
- gt_ignore_flags (bool) (optional)

Modified Keys:

Expand Down Expand Up @@ -3385,7 +3385,7 @@ class CachedMixUp(BaseTransform):
- img
- gt_bboxes (np.float32) (optional)
- gt_bboxes_labels (np.int64) (optional)
- gt_ignore_flags (np.bool) (optional)
- gt_ignore_flags (bool) (optional)
- mix_results (List[dict])


Expand Down
14 changes: 7 additions & 7 deletions mmdet/evaluation/functional/mean_ap.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ def tpfp_imagenet(det_bboxes,

# an indicator of ignored gts
gt_ignore_inds = np.concatenate(
(np.zeros(gt_bboxes.shape[0], dtype=np.bool),
np.ones(gt_bboxes_ignore.shape[0], dtype=np.bool)))
(np.zeros(gt_bboxes.shape[0],
dtype=bool), np.ones(gt_bboxes_ignore.shape[0], dtype=bool)))
# stack gt_bboxes and gt_bboxes_ignore for convenience
gt_bboxes = np.vstack((gt_bboxes, gt_bboxes_ignore))

Expand Down Expand Up @@ -202,8 +202,8 @@ def tpfp_default(det_bboxes,

# an indicator of ignored gts
gt_ignore_inds = np.concatenate(
(np.zeros(gt_bboxes.shape[0], dtype=np.bool),
np.ones(gt_bboxes_ignore.shape[0], dtype=np.bool)))
(np.zeros(gt_bboxes.shape[0],
dtype=bool), np.ones(gt_bboxes_ignore.shape[0], dtype=bool)))
# stack gt_bboxes and gt_bboxes_ignore for convenience
gt_bboxes = np.vstack((gt_bboxes, gt_bboxes_ignore))

Expand Down Expand Up @@ -317,8 +317,8 @@ def tpfp_openimages(det_bboxes,

# an indicator of ignored gts
gt_ignore_inds = np.concatenate(
(np.zeros(gt_bboxes.shape[0], dtype=np.bool),
np.ones(gt_bboxes_ignore.shape[0], dtype=np.bool)))
(np.zeros(gt_bboxes.shape[0],
dtype=bool), np.ones(gt_bboxes_ignore.shape[0], dtype=bool)))
# stack gt_bboxes and gt_bboxes_ignore for convenience
gt_bboxes = np.vstack((gt_bboxes, gt_bboxes_ignore))

Expand Down Expand Up @@ -517,7 +517,7 @@ def get_cls_group_ofs(annotations, class_id):
if ann.get('gt_is_group_ofs', None) is not None:
gt_group_ofs.append(ann['gt_is_group_ofs'][gt_inds])
else:
gt_group_ofs.append(np.empty((0, 1), dtype=np.bool))
gt_group_ofs.append(np.empty((0, 1), dtype=bool))

return gt_group_ofs

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def sample_via_interval(self, max_overlaps, full_set, num_expected):
tmp_sampled_set = self.random_choice(tmp_inds,
per_num_expected)
else:
tmp_sampled_set = np.array(tmp_inds, dtype=np.int)
tmp_sampled_set = np.array(tmp_inds, dtype=np.int64)
sampled_inds.append(tmp_sampled_set)

sampled_inds = np.concatenate(sampled_inds)
Expand Down Expand Up @@ -138,13 +138,13 @@ def _sample_neg(self, assign_result, num_expected, **kwargs):
iou_sampling_neg_inds, num_expected_iou_sampling)
else:
iou_sampled_inds = np.array(
iou_sampling_neg_inds, dtype=np.int)
iou_sampling_neg_inds, dtype=np.int64)
num_expected_floor = num_expected - len(iou_sampled_inds)
if len(floor_neg_inds) > num_expected_floor:
sampled_floor_inds = self.random_choice(
floor_neg_inds, num_expected_floor)
else:
sampled_floor_inds = np.array(floor_neg_inds, dtype=np.int)
sampled_floor_inds = np.array(floor_neg_inds, dtype=np.int64)
sampled_inds = np.concatenate(
(sampled_floor_inds, iou_sampled_inds))
if len(sampled_inds) < num_expected:
Expand Down
4 changes: 2 additions & 2 deletions mmdet/structures/mask/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class BitmapMasks(BaseInstanceMasks):
>>> from mmdet.data_elements.mask.structures import * # NOQA
>>> num_masks, H, W = 3, 32, 32
>>> rng = np.random.RandomState(0)
>>> masks = (rng.rand(num_masks, H, W) > 0.1).astype(np.int)
>>> masks = (rng.rand(num_masks, H, W) > 0.1).astype(np.int64)
>>> self = BitmapMasks(masks, height=H, width=W)

>>> # demo crop_and_resize
Expand Down Expand Up @@ -824,7 +824,7 @@ def translate(self,
"""Translate the PolygonMasks.

Example:
>>> self = PolygonMasks.random(dtype=np.int)
>>> self = PolygonMasks.random(dtype=np.int64)
>>> out_shape = (self.height, self.width)
>>> new = self.translate(out_shape, 4., direction='horizontal')
>>> assert np.all(new.masks[0][0][1::2] == self.masks[0][0][1::2])
Expand Down
2 changes: 1 addition & 1 deletion mmdet/testing/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def _rand_masks(rng, num_boxes, bboxes, img_w, img_h):
for i, bbox in enumerate(bboxes):
bbox = bbox.astype(np.int32)
mask = (rng.rand(1, bbox[3] - bbox[1], bbox[2] - bbox[0]) >
0.3).astype(np.int)
0.3).astype(np.int64)
masks[i:i + 1, bbox[1]:bbox[3], bbox[0]:bbox[2]] = mask
return BitmapMasks(masks, height=img_h, width=img_w)

Expand Down
2 changes: 1 addition & 1 deletion mmdet/visualization/local_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def _draw_instances(self, image: np.ndarray, instances: ['InstanceData'],
elif isinstance(masks, (PolygonMasks, BitmapMasks)):
masks = masks.to_ndarray()

masks = masks.astype(np.bool)
masks = masks.astype(bool)

max_label = int(max(labels) if len(labels) > 0 else 0)
mask_color = palette if self.mask_color is None \
Expand Down
2 changes: 1 addition & 1 deletion tests/test_datasets/test_transforms/test_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def setUp(self):
'gt_masks':
BitmapMasks(rng.rand(3, 300, 400), height=300, width=400),
'gt_bboxes_labels': rng.rand(3, ),
'gt_ignore_flags': np.array([0, 0, 1], dtype=np.bool),
'gt_ignore_flags': np.array([0, 0, 1], dtype=bool),
'proposals': rng.rand(2, 4),
'proposals_scores': rng.rand(2, )
}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_datasets/test_transforms/test_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_load_bboxes(self):
self.assertEqual(results['gt_bboxes'].dtype, np.float32)
self.assertTrue((results['gt_ignore_flags'] == np.array([0, 0,
1])).all())
self.assertEqual(results['gt_ignore_flags'].dtype, np.bool)
self.assertEqual(results['gt_ignore_flags'].dtype, bool)

def test_load_labels(self):
transform = LoadAnnotations(
Expand Down
4 changes: 2 additions & 2 deletions tests/test_datasets/test_transforms/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ def test_transform(self):
def test_transform_with_no_gt(self):
self.results['gt_bboxes'] = np.empty((0, 4), dtype=np.float32)
self.results['gt_bboxes_labels'] = np.empty((0, ), dtype=np.int64)
self.results['gt_ignore_flags'] = np.empty((0, ), dtype=np.bool)
self.results['gt_ignore_flags'] = np.empty((0, ), dtype=bool)
transform = Mosaic(img_scale=(12, 10))
self.results['mix_results'] = [copy.deepcopy(self.results)] * 3
results = transform(copy.deepcopy(self.results))
Expand Down Expand Up @@ -1532,7 +1532,7 @@ def test_transform(self):
results = albu_transform(results)
self.assertEqual(results['img'].dtype, np.float64)
self.assertEqual(results['gt_bboxes'].dtype, np.float32)
self.assertEqual(results['gt_ignore_flags'].dtype, np.bool)
self.assertEqual(results['gt_ignore_flags'].dtype, bool)
self.assertEqual(results['gt_bboxes_labels'].dtype, np.int64)

@unittest.skipIf(albumentations is None, 'albumentations is not installed')
Expand Down
2 changes: 1 addition & 1 deletion tests/test_models/test_dense_heads/test_boxinst_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def _rand_masks(num_items, bboxes, img_w, img_h):
for i, bbox in enumerate(bboxes):
bbox = bbox.astype(np.int32)
mask = (rng.rand(1, bbox[3] - bbox[1], bbox[2] - bbox[0]) >
0.3).astype(np.int)
0.3).astype(np.int64)
masks[i:i + 1, bbox[1]:bbox[3], bbox[0]:bbox[2]] = mask
return BitmapMasks(masks, height=img_h, width=img_w)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_models/test_dense_heads/test_condinst_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def _rand_masks(num_items, bboxes, img_w, img_h):
for i, bbox in enumerate(bboxes):
bbox = bbox.astype(np.int32)
mask = (rng.rand(1, bbox[3] - bbox[1], bbox[2] - bbox[0]) >
0.3).astype(np.int)
0.3).astype(np.int64)
masks[i:i + 1, bbox[1]:bbox[3], bbox[0]:bbox[2]] = mask
return BitmapMasks(masks, height=img_h, width=img_w)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_models/test_dense_heads/test_solo_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def _rand_masks(num_items, bboxes, img_w, img_h):
for i, bbox in enumerate(bboxes):
bbox = bbox.astype(np.int32)
mask = (rng.rand(1, bbox[3] - bbox[1], bbox[2] - bbox[0]) >
0.3).astype(np.int)
0.3).astype(np.int64)
masks[i:i + 1, bbox[1]:bbox[3], bbox[0]:bbox[2]] = mask
return BitmapMasks(masks, height=img_h, width=img_w)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_models/test_dense_heads/test_solov2_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def _rand_masks(num_items, bboxes, img_w, img_h):
for i, bbox in enumerate(bboxes):
bbox = bbox.astype(np.int32)
mask = (rng.rand(1, bbox[3] - bbox[1], bbox[2] - bbox[0]) >
0.3).astype(np.int)
0.3).astype(np.int64)
masks[i:i + 1, bbox[1]:bbox[3], bbox[0]:bbox[2]] = mask
return BitmapMasks(masks, height=img_h, width=img_w)

Expand Down
3 changes: 1 addition & 2 deletions tools/analysis_tools/browse_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import argparse
import os.path as osp

import numpy as np
from mmengine.config import Config, DictAction
from mmengine.utils import ProgressBar

Expand Down Expand Up @@ -71,7 +70,7 @@ def main():
gt_masks = gt_instances.get('masks', None)
if gt_masks is not None:
masks = mask2ndarray(gt_masks)
gt_instances.masks = masks.astype(np.bool)
gt_instances.masks = masks.astype(bool)
data_sample.gt_instances = gt_instances

visualizer.add_datasample(
Expand Down