Browse Source

!1561 Added transform list check to Python ComposeOp operation

Merge pull request !1561 from alashkari/ua-ops-v2
tags/v0.5.0-beta
mindspore-ci-bot Gitee 5 years ago
parent
commit
d71184471b
2 changed files with 24 additions and 1 deletions
  1. +2
    -1
      mindspore/dataset/transforms/vision/py_transforms.py
  2. +22
    -0
      mindspore/dataset/transforms/vision/validators.py

+ 2
- 1
mindspore/dataset/transforms/vision/py_transforms.py View File

@@ -32,7 +32,7 @@ from .validators import check_prob, check_crop, check_resize_interpolation, chec
check_normalize_py, check_random_crop, check_random_color_adjust, check_random_rotation, \ check_normalize_py, check_random_crop, check_random_color_adjust, check_random_rotation, \
check_transforms_list, check_random_apply, check_ten_crop, check_num_channels, check_pad, \ check_transforms_list, check_random_apply, check_ten_crop, check_num_channels, check_pad, \
check_random_perspective, check_random_erasing, check_cutout, check_linear_transform, check_random_affine, \ check_random_perspective, check_random_erasing, check_cutout, check_linear_transform, check_random_affine, \
check_mix_up, check_positive_degrees, check_uniform_augment_py
check_mix_up, check_positive_degrees, check_uniform_augment_py, check_compose_list
from .utils import Inter, Border from .utils import Inter, Border


DE_PY_INTER_MODE = {Inter.NEAREST: Image.NEAREST, DE_PY_INTER_MODE = {Inter.NEAREST: Image.NEAREST,
@@ -75,6 +75,7 @@ class ComposeOp:
>>> dataset = dataset.map(input_columns="image", operations=transform()) >>> dataset = dataset.map(input_columns="image", operations=transform())
""" """


@check_compose_list
def __init__(self, transforms): def __init__(self, transforms):
self.transforms = transforms self.transforms = transforms




+ 22
- 0
mindspore/dataset/transforms/vision/validators.py View File

@@ -907,3 +907,25 @@ def check_positive_degrees(method):
return method(self, **kwargs) return method(self, **kwargs)


return new_method return new_method


def check_compose_list(method):
"""Wrapper method to check the transform list of ComposeOp."""

@wraps(method)
def new_method(self, *args, **kwargs):
transforms = (list(args) + [None])[0]
if "transforms" in kwargs:
transforms = kwargs.get("transforms")
if transforms is None:
raise ValueError("transforms is not provided.")
if not transforms:
raise ValueError("transforms list is empty.")
if not isinstance(transforms, list):
raise TypeError("transforms is not a python list")

kwargs["transforms"] = transforms

return method(self, **kwargs)

return new_method

Loading…
Cancel
Save