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)
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)
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): [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)
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 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)
def new_method(self, *args, **kwargs): [transforms, num_ops], _ = parse_user_args(method, *args, **kwargs) type_check(transforms, (list,), "transforms") if not transforms: raise ValueError("transforms list is empty.") for transform in transforms: if isinstance(transform, TensorOp): raise ValueError("transform list only accepts Python operations.") type_check(num_ops, (int,), "num_ops") check_positive(num_ops, "num_ops") if num_ops > len(transforms): raise ValueError("num_ops cannot be greater than the length of transforms list.") 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): [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(parsed_transforms, (list, tuple,), "transforms") for index, arg in enumerate(parsed_transforms): if not isinstance(arg, (TensorOp, TensorOperation)): raise TypeError("Type of Transforms[{0}] must be c_transform, but got {1}".format(index, type(arg))) return method(self, *args, **kwargs)
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) 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)