diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/image_process.cc b/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/image_process.cc index f240b6b1a2..0e90b4888d 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/image_process.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/image_process.cc @@ -1412,21 +1412,21 @@ void CalculationMatrix(int n, int m, std::vector &W, LiteMat &A, LiteMat } for (int i = 0; i < n - 1; i++) { - int j = i; - for (int k = i + 1; k < n; k++) { - if (W[j] < W[k]) { - j = k; + int mid = i; + for (int j = i + 1; j < n; j++) { + if (W[mid] < W[j]) { + mid = j; } } - if (i != j) { - std::swap(W[i], W[j]); - for (int k = 0; k < m; k++) { - std::swap(A.ptr(i)[k], A.ptr(j)[k]); + if (i != mid) { + std::swap(W[i], W[mid]); + for (int j = 0; j < m; j++) { + std::swap(A.ptr(i)[j], A.ptr(mid)[j]); } - for (int k = 0; k < n; k++) { - std::swap(V.ptr(i)[k], V.ptr(j)[k]); + for (int j = 0; j < n; j++) { + std::swap(V.ptr(i)[j], V.ptr(mid)[j]); } } } @@ -1451,8 +1451,8 @@ void JacobiSVD(LiteMat &A, LiteMat &_W, LiteMat &V) { std::uniform_int_distribution dis(0, 4294967294); for (int i = 0; i < urows; i++) { - double sd = i < n ? W[i] : 0; - for (int ii = 0; ii < 100 && sd <= min_val; ii++) { + double mid = i < n ? W[i] : 0; + for (int ii = 0; ii < 100 && mid <= min_val; ii++) { const T val0 = (T)(1. / m); for (int k = 0; k < m; k++) { unsigned int rng = dis(gen); @@ -1460,15 +1460,15 @@ void JacobiSVD(LiteMat &A, LiteMat &_W, LiteMat &V) { A.ptr(i)[k] = val; } - for (int iter = 0; iter < 2; iter++) { + for (int inner = 0; inner < 2; inner++) { for (int j = 0; j < i; j++) { - sd = 0; + mid = 0; for (int k = 0; k < m; k++) { - sd += A.ptr(i)[k] * A.ptr(j)[k]; + mid += A.ptr(i)[k] * A.ptr(j)[k]; } T asum = 0; for (int k = 0; k < m; k++) { - T t = (T)(A.ptr(i)[k] - sd * A.ptr(j)[k]); + T t = (T)(A.ptr(i)[k] - mid * A.ptr(j)[k]); A.ptr(i)[k] = t; asum += std::abs(t); } @@ -1480,15 +1480,15 @@ void JacobiSVD(LiteMat &A, LiteMat &_W, LiteMat &V) { } } - sd = 0; + mid = 0; for (int k = 0; k < m; k++) { T t = A.ptr(i)[k]; - sd += static_cast(t * t); + mid += static_cast(t * t); } - sd = std::sqrt(sd); + mid = std::sqrt(mid); } - T s = (T)(sd > min_val ? 1 / sd : 0.); + T s = (T)(mid > min_val ? 1 / mid : 0.); for (int k = 0; k < m; k++) { A.ptr(i)[k] *= s; } diff --git a/mindspore/dataset/vision/py_transforms.py b/mindspore/dataset/vision/py_transforms.py index f98c5ef765..f50e1116ec 100644 --- a/mindspore/dataset/vision/py_transforms.py +++ b/mindspore/dataset/vision/py_transforms.py @@ -33,6 +33,7 @@ from .validators import check_prob, check_crop, check_resize_interpolation, chec 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_auto_contrast from .utils import Inter, Border +from .py_transforms_util import is_pil DE_PY_INTER_MODE = {Inter.NEAREST: Image.NEAREST, Inter.ANTIALIAS: Image.ANTIALIAS, @@ -964,6 +965,8 @@ class RandomPerspective: Returns: img (PIL image), Image after being perspectively transformed randomly. """ + if not is_pil(img): + raise ValueError("Input image should be a Pillow image.") if self.prob > random.random(): start_points, end_points = util.get_perspective_params(img, self.distortion_scale) return util.perspective(img, start_points, end_points, self.interpolation) diff --git a/mindspore/dataset/vision/validators.py b/mindspore/dataset/vision/validators.py index 0ba3f2a52d..3984663bda 100644 --- a/mindspore/dataset/vision/validators.py +++ b/mindspore/dataset/vision/validators.py @@ -458,6 +458,8 @@ def check_random_perspective(method): def new_method(self, *args, **kwargs): [distortion_scale, prob, interpolation], _ = parse_user_args(method, *args, **kwargs) + type_check(distortion_scale, (float,), "distortion_scale") + type_check(prob, (float,), "prob") check_value(distortion_scale, [0., 1.], "distortion_scale") check_value(prob, [0., 1.], "prob") type_check(interpolation, (Inter,), "interpolation")