Skip to content

Commit

Permalink
Updated conditions for _BaseMixupCutmix
Browse files Browse the repository at this point in the history
  • Loading branch information
vfdev-5 committed Jul 8, 2022
1 parent 3ce23ef commit 883a525
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
14 changes: 0 additions & 14 deletions test/test_prototype_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,6 @@ def test_common(self, transform, input):
def test_mixup_cutmix(self, transform, input):
transform(input)

@pytest.mark.parametrize("transform", [transforms.RandomMixup(alpha=1.0), transforms.RandomCutmix(alpha=1.0)])
def test_mixup_cutmix_assertions(self, transform):
for bbox in make_bounding_boxes():
with pytest.raises(TypeError, match="does not support"):
transform(bbox)
break
for mask in make_segmentation_masks():
with pytest.raises(TypeError, match="does not support"):
transform(mask)
break
label = make_label()
with pytest.raises(TypeError, match="does not support"):
transform(label)

@parametrize(
[
(
Expand Down
4 changes: 3 additions & 1 deletion torchvision/prototype/transforms/_augment.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from torchvision.prototype.transforms import Transform, functional as F

from ._transform import _RandomApplyTransform
from ._utils import query_image, get_image_dimensions, has_any
from ._utils import query_image, get_image_dimensions, has_any, has_all


class RandomErasing(_RandomApplyTransform):
Expand Down Expand Up @@ -106,6 +106,8 @@ def __init__(self, *, alpha: float) -> None:

def forward(self, *inpts: Any) -> Any:
sample = inpts if len(inpts) > 1 else inpts[0]
if not has_all(sample, features.Image, features.OneHotLabel):
raise TypeError(f"{type(self).__name__}() is only defined for Image's *and* OneHotLabel's.")
if has_any(sample, features.BoundingBox, features.SegmentationMask, features.Label):
raise TypeError(
f"{type(self).__name__}() does not support bounding boxes, segmentation masks and plain labels."
Expand Down

0 comments on commit 883a525

Please sign in to comment.