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))
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)
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)
def check_degrees(degrees): """Check if the degrees is legal.""" type_check(degrees, (numbers.Number, list, tuple), "degrees") if isinstance(degrees, numbers.Number): check_value(degrees, (0, float("inf")), "degrees") elif isinstance(degrees, (list, tuple)): if len(degrees) == 2: type_check_list(degrees, (numbers.Number,), "degrees") if degrees[0] > degrees[1]: raise ValueError("degrees should be in (min,max) format. Got (max,min).") else: raise TypeError("If degrees is a sequence, the length must be 2.")
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)
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)
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.") parsed_transforms = [] for op in transforms: if op and getattr(op, 'parse', None): parsed_transforms.append(op.parse()) else: parsed_transforms.append(op) type_check_list(parsed_transforms, (TensorOp, TensorOperation), "transforms") return method(self, *args, **kwargs)
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)