Skip to content

Rename features.SegmentationMask to features.Mask #6579

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

Merged
merged 6 commits into from
Sep 14, 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
6 changes: 3 additions & 3 deletions test/prototype_common_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def make_detection_mask(size=None, *, num_objects=None, extra_dims=(), dtype=tor
num_objects = num_objects if num_objects is not None else int(torch.randint(1, 11, ()))
shape = (*extra_dims, num_objects, *size)
data = make_tensor(shape, low=0, high=2, dtype=dtype)
return features.SegmentationMask(data)
return features.Mask(data)


def make_detection_masks(
Expand All @@ -207,7 +207,7 @@ def make_segmentation_mask(size=None, *, num_categories=None, extra_dims=(), dty
num_categories = num_categories if num_categories is not None else int(torch.randint(1, 11, ()))
shape = (*extra_dims, *size)
data = make_tensor(shape, low=0, high=num_categories, dtype=dtype)
return features.SegmentationMask(data)
return features.Mask(data)


def make_segmentation_masks(
Expand All @@ -224,7 +224,7 @@ def make_segmentation_masks(
yield make_segmentation_mask(size=sizes[0], num_categories=num_categories_, dtype=dtype, extra_dims=extra_dims_)


def make_detection_and_segmentation_masks(
def make_masks(
sizes=((16, 16), (7, 33), (31, 9)),
dtypes=(torch.uint8,),
extra_dims=((), (0,), (4,), (2, 3), (5, 0), (0, 5)),
Expand Down
42 changes: 21 additions & 21 deletions test/test_prototype_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
from prototype_common_utils import (
make_bounding_box,
make_bounding_boxes,
make_detection_and_segmentation_masks,
make_detection_mask,
make_image,
make_images,
make_label,
make_masks,
make_one_hot_labels,
make_segmentation_mask,
)
Expand Down Expand Up @@ -64,7 +64,7 @@ def parametrize_from_transforms(*transforms):
make_one_hot_labels,
make_vanilla_tensor_images,
make_pil_images,
make_detection_and_segmentation_masks,
make_masks,
]:
inputs = list(creation_fn())
try:
Expand Down Expand Up @@ -132,7 +132,7 @@ def test_mixup_cutmix(self, transform, input):
transform(input_copy)

# Check if we raise an error if sample contains bbox or mask or label
err_msg = "does not support bounding boxes, segmentation masks and plain labels"
err_msg = "does not support bounding boxes, masks and plain labels"
input_copy = dict(input)
for unsup_data in [
make_label(),
Expand Down Expand Up @@ -241,7 +241,7 @@ def test_convert_color_space_unsupported_types(self):
color_space=features.ColorSpace.RGB, old_color_space=features.ColorSpace.GRAY
)

for inpt in [make_bounding_box(format="XYXY"), make_detection_and_segmentation_masks()]:
for inpt in [make_bounding_box(format="XYXY"), make_masks()]:
output = transform(inpt)
assert output is inpt

Expand Down Expand Up @@ -278,13 +278,13 @@ def test_features_image(self, p):

assert_equal(features.Image(expected), actual)

def test_features_segmentation_mask(self, p):
def test_features_mask(self, p):
input, expected = self.input_expected_image_tensor(p)
transform = transforms.RandomHorizontalFlip(p=p)

actual = transform(features.SegmentationMask(input))
actual = transform(features.Mask(input))

assert_equal(features.SegmentationMask(expected), actual)
assert_equal(features.Mask(expected), actual)

def test_features_bounding_box(self, p):
input = features.BoundingBox([0, 0, 5, 5], format=features.BoundingBoxFormat.XYXY, image_size=(10, 10))
Expand Down Expand Up @@ -331,13 +331,13 @@ def test_features_image(self, p):

assert_equal(features.Image(expected), actual)

def test_features_segmentation_mask(self, p):
def test_features_mask(self, p):
input, expected = self.input_expected_image_tensor(p)
transform = transforms.RandomVerticalFlip(p=p)

actual = transform(features.SegmentationMask(input))
actual = transform(features.Mask(input))

assert_equal(features.SegmentationMask(expected), actual)
assert_equal(features.Mask(expected), actual)

def test_features_bounding_box(self, p):
input = features.BoundingBox([0, 0, 5, 5], format=features.BoundingBoxFormat.XYXY, image_size=(10, 10))
Expand Down Expand Up @@ -1253,7 +1253,7 @@ def test__transform(self, mocker):
torch.testing.assert_close(output_ohe_label, ohe_label[is_within_crop_area])

output_masks = output[4]
assert isinstance(output_masks, features.SegmentationMask)
assert isinstance(output_masks, features.Mask)
assert len(output_masks) == expected_within_targets


Expand Down Expand Up @@ -1372,10 +1372,10 @@ def test__extract_image_targets_assertion(self, mocker):
# labels, bboxes, masks
mocker.MagicMock(spec=features.Label),
mocker.MagicMock(spec=features.BoundingBox),
mocker.MagicMock(spec=features.SegmentationMask),
mocker.MagicMock(spec=features.Mask),
# labels, bboxes, masks
mocker.MagicMock(spec=features.BoundingBox),
mocker.MagicMock(spec=features.SegmentationMask),
mocker.MagicMock(spec=features.Mask),
]

with pytest.raises(TypeError, match="requires input sample to contain equal sized list of Images"):
Expand All @@ -1393,11 +1393,11 @@ def test__extract_image_targets(self, image_type, label_type, mocker):
# labels, bboxes, masks
mocker.MagicMock(spec=label_type),
mocker.MagicMock(spec=features.BoundingBox),
mocker.MagicMock(spec=features.SegmentationMask),
mocker.MagicMock(spec=features.Mask),
# labels, bboxes, masks
mocker.MagicMock(spec=label_type),
mocker.MagicMock(spec=features.BoundingBox),
mocker.MagicMock(spec=features.SegmentationMask),
mocker.MagicMock(spec=features.Mask),
]

images, targets = transform._extract_image_targets(flat_sample)
Expand All @@ -1413,7 +1413,7 @@ def test__extract_image_targets(self, image_type, label_type, mocker):
for target in targets:
for key, type_ in [
("boxes", features.BoundingBox),
("masks", features.SegmentationMask),
("masks", features.Mask),
("labels", label_type),
]:
assert key in target
Expand All @@ -1436,7 +1436,7 @@ def test__copy_paste(self, label_type):
"boxes": features.BoundingBox(
torch.tensor([[2.0, 3.0, 8.0, 9.0], [20.0, 20.0, 30.0, 30.0]]), format="XYXY", image_size=(32, 32)
),
"masks": features.SegmentationMask(masks),
"masks": features.Mask(masks),
"labels": label_type(labels),
}

Expand All @@ -1451,7 +1451,7 @@ def test__copy_paste(self, label_type):
"boxes": features.BoundingBox(
torch.tensor([[12.0, 13.0, 19.0, 18.0], [1.0, 15.0, 8.0, 19.0]]), format="XYXY", image_size=(32, 32)
),
"masks": features.SegmentationMask(paste_masks),
"masks": features.Mask(paste_masks),
"labels": label_type(paste_labels),
}

Expand Down Expand Up @@ -1586,7 +1586,7 @@ def test__transform_culling(self, mocker):
bounding_boxes = make_bounding_box(
format=features.BoundingBoxFormat.XYXY, image_size=image_size, extra_dims=(batch_size,)
)
segmentation_masks = make_detection_mask(size=image_size, extra_dims=(batch_size,))
masks = make_detection_mask(size=image_size, extra_dims=(batch_size,))
labels = make_label(size=(batch_size,))

transform = transforms.FixedSizeCrop((-1, -1))
Expand All @@ -1596,13 +1596,13 @@ def test__transform_culling(self, mocker):
output = transform(
dict(
bounding_boxes=bounding_boxes,
segmentation_masks=segmentation_masks,
masks=masks,
labels=labels,
)
)

assert_equal(output["bounding_boxes"], bounding_boxes[is_valid])
assert_equal(output["segmentation_masks"], segmentation_masks[is_valid])
assert_equal(output["masks"], masks[is_valid])
assert_equal(output["labels"], labels[is_valid])

def test__transform_bounding_box_clamping(self, mocker):
Expand Down
Loading