Beispiel #1
0
def check_size_scale_ration_max_attempts_paras(size, scale, ratio,
                                               max_attempts):
    """Wrapper method to check the parameters of RandomCropDecodeResize and SoftDvppDecodeRandomCropResizeJpeg."""

    check_crop_size(size)
    if scale is not None:
        type_check(scale, (tuple, list), "scale")
        if len(scale) != 2:
            raise TypeError("scale should be a list/tuple of length 2.")
        type_check_list(scale, (float, int), "scale")
        if scale[0] > scale[1]:
            raise ValueError(
                "scale should be in (min,max) format. Got (max,min).")
        check_range(scale, [0, FLOAT_MAX_INTEGER])
        check_positive(scale[1], "scale[1]")
    if ratio is not None:
        type_check(ratio, (tuple, list), "ratio")
        if len(ratio) != 2:
            raise TypeError("ratio should be a list/tuple of length 2.")
        type_check_list(ratio, (float, int), "ratio")
        if ratio[0] > ratio[1]:
            raise ValueError(
                "ratio should be in (min,max) format. Got (max,min).")
        check_range(ratio, [0, FLOAT_MAX_INTEGER])
        check_positive(ratio[0], "ratio[0]")
        check_positive(ratio[1], "ratio[1]")
    if max_attempts is not None:
        check_value(max_attempts, (1, FLOAT_MAX_INTEGER))
Beispiel #2
0
    def new_method(self, *args, **kwargs):
        [prob, scale, ratio, value, inplace, max_attempts], _ = parse_user_args(method, *args, **kwargs)

        type_check(prob, (float, int,), "prob")
        type_check_list(scale, (float, int,), "scale")
        if len(scale) != 2:
            raise TypeError("scale should be a list or tuple of length 2.")
        type_check_list(ratio, (float, int,), "ratio")
        if len(ratio) != 2:
            raise TypeError("ratio should be a list or tuple of length 2.")
        type_check(value, (int, list, tuple, str), "value")
        type_check(inplace, (bool,), "inplace")
        type_check(max_attempts, (int,), "max_attempts")
        check_erasing_value(value)

        check_value(prob, [0., 1.], "prob")
        if scale[0] > scale[1]:
            raise ValueError("scale should be in (min,max) format. Got (max,min).")
        check_range(scale, [0, FLOAT_MAX_INTEGER])
        check_positive(scale[1], "scale[1]")
        if ratio[0] > ratio[1]:
            raise ValueError("ratio should be in (min,max) format. Got (max,min).")
        check_value_ratio(ratio[0], [0, FLOAT_MAX_INTEGER])
        check_value_ratio(ratio[1], [0, FLOAT_MAX_INTEGER])
        if isinstance(value, int):
            check_value(value, (0, 255))
        if isinstance(value, (list, tuple)):
            for item in value:
                type_check(item, (int,), "value")
                check_value(item, [0, 255], "value")
        check_value(max_attempts, (1, FLOAT_MAX_INTEGER))

        return method(self, *args, **kwargs)
Beispiel #3
0
def check_random_color_adjust_param(value, input_name, center=1, bound=(0, FLOAT_MAX_INTEGER), non_negative=True):
    """Check the parameters in random color adjust operation."""
    type_check(value, (numbers.Number, list, tuple), input_name)
    if isinstance(value, numbers.Number):
        if value < 0:
            raise ValueError("The input value of {} cannot be negative.".format(input_name))
    elif isinstance(value, (list, tuple)) and len(value) == 2:
        check_range(value, bound)
        if value[0] > value[1]:
            raise ValueError("value should be in (min,max) format. Got (max,min).")
Beispiel #4
0
    def new_method(self, *args, **kwargs):
        [prob, scale, ratio, value, inplace, max_attempts], _ = parse_user_args(method, *args, **kwargs)

        check_value(prob, [0., 1.], "prob")
        check_range(scale, [0, FLOAT_MAX_INTEGER])
        check_range(ratio, [0, FLOAT_MAX_INTEGER])
        check_erasing_value(value)
        type_check(inplace, (bool,), "inplace")
        check_value(max_attempts, (1, FLOAT_MAX_INTEGER))

        return method(self, *args, **kwargs)
Beispiel #5
0
def check_random_color_adjust_param(value, input_name, center=1, bound=(0, FLOAT_MAX_INTEGER), non_negative=True):
    """Check the parameters in random color adjust operation."""
    type_check(value, (numbers.Number, list, tuple), input_name)
    if isinstance(value, numbers.Number):
        if value < 0:
            raise ValueError("The input value of {} cannot be negative.".format(input_name))
    elif isinstance(value, (list, tuple)):
        if len(value) != 2:
            raise TypeError("If {0} is a sequence, the length must be 2.".format(input_name))
        if value[0] > value[1]:
            raise ValueError("{0} value should be in (min,max) format. Got ({1}, {2}).".format(input_name,
                                                                                               value[0], value[1]))
        check_range(value, bound)
Beispiel #6
0
    def new_method(self, *args, **kwargs):
        [degrees, translate, scale, shear, resample,
         fill_value], _ = parse_user_args(method, *args, **kwargs)
        check_degrees(degrees)

        if translate is not None:
            type_check(translate, (list, tuple), "translate")
            type_check_list(translate, (int, float), "translate")
            if len(translate) != 2 and len(translate) != 4:
                raise TypeError(
                    "translate should be a list or tuple of length 2 or 4.")
            for i, t in enumerate(translate):
                check_value(t, [-1.0, 1.0], "translate at {0}".format(i))

        if scale is not None:
            type_check(scale, (tuple, list), "scale")
            type_check_list(scale, (int, float), "scale")
            if len(scale) == 2:
                if scale[0] > scale[1]:
                    raise ValueError(
                        "Input scale[1] must be equal to or greater than scale[0]."
                    )
                check_range(scale, [0, FLOAT_MAX_INTEGER])
                check_positive(scale[1], "scale[1]")
            else:
                raise TypeError("scale should be a list or tuple of length 2.")

        if shear is not None:
            type_check(shear, (numbers.Number, tuple, list), "shear")
            if isinstance(shear, numbers.Number):
                check_positive(shear, "shear")
            else:
                type_check_list(shear, (int, float), "shear")
                if len(shear) not in (2, 4):
                    raise TypeError("shear must be of length 2 or 4.")
                if len(shear) == 2 and shear[0] > shear[1]:
                    raise ValueError(
                        "Input shear[1] must be equal to or greater than shear[0]"
                    )
                if len(shear) == 4 and (shear[0] > shear[1]
                                        or shear[2] > shear[3]):
                    raise ValueError(
                        "Input shear[1] must be equal to or greater than shear[0] and "
                        "shear[3] must be equal to or greater than shear[2].")

        type_check(resample, (Inter, ), "resample")

        if fill_value is not None:
            check_fill_value(fill_value)

        return method(self, *args, **kwargs)
Beispiel #7
0
 def new_method(self, *args, **kwargs):
     [bits], _ = parse_user_args(method, *args, **kwargs)
     if bits is not None:
         type_check(bits, (list, tuple, int), "bits")
     if isinstance(bits, int):
         check_value(bits, [1, 8])
     if isinstance(bits, (list, tuple)):
         if len(bits) != 2:
             raise TypeError("Size of bits should be a single integer or a list/tuple (min, max) of length 2.")
         for item in bits:
             check_uint8(item, "bits")
         # also checks if min <= max
         check_range(bits, [1, 8])
     return method(self, *args, **kwargs)
Beispiel #8
0
    def new_method(self, *args, **kwargs):
        [prob, scale, ratio, value, inplace, max_attempts], _ = parse_user_args(method, *args, **kwargs)

        check_value(prob, [0., 1.], "prob")
        if scale[0] > scale[1]:
            raise ValueError("scale should be in (min,max) format. Got (max,min).")
        check_range(scale, [0, FLOAT_MAX_INTEGER])
        check_positive(scale[1], "scale[1]")
        if ratio[0] > ratio[1]:
            raise ValueError("ratio should be in (min,max) format. Got (max,min).")
        check_range(ratio, [0, FLOAT_MAX_INTEGER])
        check_positive(ratio[0], "ratio[0]")
        check_positive(ratio[1], "ratio[1]")
        check_erasing_value(value)
        type_check(inplace, (bool,), "inplace")
        check_value(max_attempts, (1, FLOAT_MAX_INTEGER))

        return method(self, *args, **kwargs)