Exemple #1
0
    def new_method(self, *args, **kwargs):
        [size, scale, ratio, interpolation, max_attempts], _ = parse_user_args(method, *args, **kwargs)
        if interpolation is not None:
            type_check(interpolation, (Inter,), "interpolation")
        check_size_scale_ration_max_attempts_paras(size, scale, ratio, max_attempts)

        return method(self, *args, **kwargs)
Exemple #2
0
    def new_method(self, *args, **kwargs):
        [padding, fill_value, padding_mode], _ = parse_user_args(method, *args, **kwargs)
        check_padding(padding)
        check_fill_value(fill_value)
        type_check(padding_mode, (Border,), "padding_mode")

        return method(self, *args, **kwargs)
Exemple #3
0
    def new_method(self, *args, **kwargs):
        [size, scale, ratio,
         max_attempts], _ = parse_user_args(method, *args, **kwargs)
        check_size_scale_ration_max_attempts_paras(size, scale, ratio,
                                                   max_attempts)

        return method(self, *args, **kwargs)
Exemple #4
0
    def new_method(self, *args, **kwargs):
        [length, num_patches], _ = parse_user_args(method, *args, **kwargs)

        check_value(length, (1, FLOAT_MAX_INTEGER))
        check_value(num_patches, (1, FLOAT_MAX_INTEGER))

        return method(self, *args, **kwargs)
Exemple #5
0
 def new_method(self, *args, **kwargs):
     [image_batch_format, alpha, prob], _ = parse_user_args(method, *args, **kwargs)
     type_check(image_batch_format, (ImageBatchFormat,), "image_batch_format")
     check_pos_float32(alpha)
     check_positive(alpha, "alpha")
     check_value(prob, [0, 1], "prob")
     return method(self, *args, **kwargs)
Exemple #6
0
    def new_method(self, *args, **kwargs):
        [kernel_size, sigma], _ = parse_user_args(method, *args, **kwargs)

        type_check(kernel_size, (int, list, tuple), "kernel_size")
        if isinstance(kernel_size, int):
            check_value(kernel_size, (1, FLOAT_MAX_INTEGER), "kernel_size")
            check_odd(kernel_size, "kernel_size")
        elif isinstance(kernel_size, (list, tuple)) and len(kernel_size) == 2:
            for index, value in enumerate(kernel_size):
                type_check(value, (int, ), "kernel_size[{}]".format(index))
                check_value(value, (1, FLOAT_MAX_INTEGER), "kernel_size")
                check_odd(value, "kernel_size[{}]".format(index))
        else:
            raise TypeError(
                "Kernel size should be a single integer or a list/tuple (kernel_width, kernel_height) of length 2."
            )

        if sigma is not None:
            type_check(sigma, (numbers.Number, list, tuple), "sigma")
            if isinstance(sigma, numbers.Number):
                check_value(sigma, (0, FLOAT_MAX_INTEGER), "sigma")
            elif isinstance(sigma, (list, tuple)) and len(sigma) == 2:
                for index, value in enumerate(sigma):
                    type_check(value, (numbers.Number, ),
                               "size[{}]".format(index))
                    check_value(value, (0, FLOAT_MAX_INTEGER), "sigma")
            else:
                raise TypeError(
                    "Sigma should be a single number or a list/tuple of length 2 for width and height."
                )

        return method(self, *args, **kwargs)
Exemple #7
0
    def new_method(self, *args, **kwargs):
        [alpha], _ = parse_user_args(method, *args, **kwargs)
        type_check(alpha, (int, float), "alpha")
        check_positive(alpha, "alpha")
        check_pos_float32(alpha)

        return method(self, *args, **kwargs)
Exemple #8
0
    def new_method(self, *args, **kwargs):
        [size, interpolation], _ = parse_user_args(method, *args, **kwargs)
        check_resize_size(size)
        if interpolation is not None:
            type_check(interpolation, (Inter,), "interpolation")

        return method(self, *args, **kwargs)
Exemple #9
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)
Exemple #10
0
 def new_method(self, *args, **kwargs):
     [transform, ratio], _ = parse_user_args(method, *args, **kwargs)
     type_check(ratio, (float, int), "ratio")
     check_value(ratio, [0., 1.], "ratio")
     if transform and getattr(transform, 'parse', None):
         transform = transform.parse()
     type_check(transform, (TensorOp, TensorOperation), "transform")
     return method(self, *args, **kwargs)
Exemple #11
0
    def new_method(self, *args, **kwargs):
        [rescale, shift], _ = parse_user_args(method, *args, **kwargs)
        type_check(rescale, (numbers.Number, ), "rescale")
        type_check(shift, (numbers.Number, ), "shift")
        check_float32(rescale)
        check_float32(shift)

        return method(self, *args, **kwargs)
Exemple #12
0
    def new_method(self, *args, **kwargs):
        [size, interpolation], _ = parse_user_args(method, *args, **kwargs)
        if interpolation is None:
            raise KeyError("Interpolation should not be None")
        check_resize_size(size)
        type_check(interpolation, (Inter, ), "interpolation")

        return method(self, *args, **kwargs)
Exemple #13
0
    def new_method(self, *args, **kwargs):
        [brightness, contrast, saturation, hue], _ = parse_user_args(method, *args, **kwargs)
        check_random_color_adjust_param(brightness, "brightness")
        check_random_color_adjust_param(contrast, "contrast")
        check_random_color_adjust_param(saturation, "saturation")
        check_random_color_adjust_param(hue, 'hue', center=0, bound=(-0.5, 0.5), non_negative=False)

        return method(self, *args, **kwargs)
Exemple #14
0
    def new_method(self, *args, **kwargs):
        [distortion_scale, prob, interpolation], _ = parse_user_args(method, *args, **kwargs)

        check_value(distortion_scale, [0., 1.], "distortion_scale")
        check_value(prob, [0., 1.], "prob")
        type_check(interpolation, (Inter,), "interpolation")

        return method(self, *args, **kwargs)
Exemple #15
0
    def new_method(self, *args, **kwargs):
        [num_output_channels], _ = parse_user_args(method, *args, **kwargs)
        if num_output_channels is not None:
            if num_output_channels not in (1, 3):
                raise ValueError("Number of channels of the output grayscale image"
                                 "should be either 1 or 3. Got {0}.".format(num_output_channels))

        return method(self, *args, **kwargs)
Exemple #16
0
    def new_method(self, *args, **kwargs):
        [size, use_vertical_flip], _ = parse_user_args(method, *args, **kwargs)
        check_crop_size(size)

        if use_vertical_flip is not None:
            type_check(use_vertical_flip, (bool,), "use_vertical_flip")

        return method(self, *args, **kwargs)
Exemple #17
0
    def new_method(self, *args, **kwargs):
        [batch_size, alpha, is_single], _ = parse_user_args(method, *args, **kwargs)

        check_value(batch_size, (1, FLOAT_MAX_INTEGER))
        check_positive(alpha, "alpha")
        type_check(is_single, (bool,), "is_single")

        return method(self, *args, **kwargs)
Exemple #18
0
    def new_method(self, *args, **kwargs):
        [prob], _ = parse_user_args(method, *args, **kwargs)
        type_check(prob, (
            float,
            int,
        ), "prob")
        check_value(prob, [0., 1.], "prob")

        return method(self, *args, **kwargs)
Exemple #19
0
    def new_method(self, *args, **kwargs):
        [mean, std, dtype], _ = parse_user_args(method, *args, **kwargs)
        check_normalize_py_param(mean, std)
        if not isinstance(dtype, str):
            raise TypeError("dtype should be string.")
        if dtype not in ["float32", "float16"]:
            raise ValueError("dtype only support float32 or float16.")

        return method(self, *args, **kwargs)
Exemple #20
0
    def new_method(self, *args, **kwargs):
        [transforms, num_ops], _ = parse_user_args(method, *args, **kwargs)
        type_check(num_ops, (int,), "num_ops")
        check_positive(num_ops, "num_ops")

        if num_ops > len(transforms):
            raise ValueError("num_ops is greater than transforms list size.")
        type_check_list(transforms, (TensorOp,), "tensor_ops")

        return method(self, *args, **kwargs)
Exemple #21
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)
Exemple #22
0
    def new_method(self, *args, **kwargs):
        [size, padding, pad_if_needed, fill_value, padding_mode], _ = parse_user_args(method, *args, **kwargs)
        check_crop_size(size)
        type_check(pad_if_needed, (bool,), "pad_if_needed")
        if padding is not None:
            check_padding(padding)
        if fill_value is not None:
            check_fill_value(fill_value)
        if padding_mode is not None:
            type_check(padding_mode, (Border,), "padding_mode")

        return method(self, *args, **kwargs)
Exemple #23
0
    def new_method(self, *args, **kwargs):
        [threshold], _ = parse_user_args(method, *args, **kwargs)

        type_check(threshold, (tuple,), "threshold")
        type_check_list(threshold, (int,), "threshold")
        if len(threshold) != 2:
            raise ValueError("threshold must be a sequence of two numbers.")
        for element in threshold:
            check_value(element, (0, UINT8_MAX))
        if threshold[1] < threshold[0]:
            raise ValueError("threshold must be in min max format numbers.")

        return method(self, *args, **kwargs)
Exemple #24
0
 def new_method(self, *args, **kwargs):
     [cutoff, ignore], _ = parse_user_args(method, *args, **kwargs)
     type_check(cutoff, (int, float), "cutoff")
     check_value(cutoff, [0, 100], "cutoff")
     if ignore is not None:
         type_check(ignore, (list, tuple, int), "ignore")
     if isinstance(ignore, int):
         check_value(ignore, [0, 255], "ignore")
     if isinstance(ignore, (list, tuple)):
         for item in ignore:
             type_check(item, (int,), "item")
             check_value(item, [0, 255], "ignore")
     return method(self, *args, **kwargs)
Exemple #25
0
    def new_method(self, *args, **kwargs):
        [transformation_matrix, mean_vector], _ = parse_user_args(method, *args, **kwargs)
        type_check(transformation_matrix, (np.ndarray,), "transformation_matrix")
        type_check(mean_vector, (np.ndarray,), "mean_vector")

        if transformation_matrix.shape[0] != transformation_matrix.shape[1]:
            raise ValueError("transformation_matrix should be a square matrix. "
                             "Got shape {} instead.".format(transformation_matrix.shape))
        if mean_vector.shape[0] != transformation_matrix.shape[0]:
            raise ValueError("mean_vector length {0} should match either one dimension of the square"
                             "transformation_matrix {1}.".format(mean_vector.shape[0], transformation_matrix.shape))

        return method(self, *args, **kwargs)
Exemple #26
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)
Exemple #27
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)
Exemple #28
0
    def new_method(self, *args, **kwargs):
        [degrees, resample, expand, center, fill_value], _ = parse_user_args(method, *args, **kwargs)
        check_degrees(degrees)

        if resample is not None:
            type_check(resample, (Inter,), "resample")
        if expand is not None:
            type_check(expand, (bool,), "expand")
        if center is not None:
            check_2tuple(center, "center")
        if fill_value is not None:
            check_fill_value(fill_value)

        return method(self, *args, **kwargs)
Exemple #29
0
    def new_method(self, *args, **kwargs):
        [policy], _ = parse_user_args(method, *args, **kwargs)
        type_check(policy, (list,), "policy")
        if not policy:
            raise ValueError("policy can not be empty.")
        for sub_ind, sub in enumerate(policy):
            type_check(sub, (list,), "policy[{0}]".format([sub_ind]))
            if not sub:
                raise ValueError("policy[{0}] can not be empty.".format(sub_ind))
            for op_ind, tp in enumerate(sub):
                check_2tuple(tp, "policy[{0}][{1}]".format(sub_ind, op_ind))
                check_tensor_op(tp[0], "op of (op, prob) in policy[{0}][{1}]".format(sub_ind, op_ind))
                check_value(tp[1], (0, 1), "prob of (op, prob) policy[{0}][{1}]".format(sub_ind, op_ind))

        return method(self, *args, **kwargs)
Exemple #30
0
    def new_method(self, *args, **kwargs):
        [degrees], _ = parse_user_args(method, *args, **kwargs)

        if degrees is not None:
            if not isinstance(degrees, (list, tuple)):
                raise TypeError("degrees must be either a tuple or a list.")
            type_check_list(degrees, (int, float), "degrees")
            if len(degrees) != 2:
                raise ValueError("degrees must be a sequence with length 2.")
            for degree in degrees:
                check_value(degree, (0, FLOAT_MAX_INTEGER))
            if degrees[0] > degrees[1]:
                raise ValueError("degrees should be in (min,max) format. Got (max,min).")

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