From 02234b90c5fabf0e4e5c9b0712308f8be917f49b Mon Sep 17 00:00:00 2001 From: ms_yan Date: Tue, 28 Sep 2021 20:58:20 +0800 Subject: [PATCH] put check before resize operation --- .../dataset/kernels/image/image_utils.cc | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/image_utils.cc b/mindspore/ccsrc/minddata/dataset/kernels/image/image_utils.cc index 94efa3a7dcf..057abf98a07 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/image/image_utils.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/image_utils.cc @@ -144,21 +144,6 @@ Status Resize(const std::shared_ptr &input, std::shared_ptr *out } RETURN_IF_NOT_OK(ValidateImageRank("Resize", input_cv->Rank())); - if (mode == InterpolationMode::kCubicPil) { - LiteMat imIn, imOut; - std::shared_ptr output_tensor; - TensorShape new_shape = TensorShape({output_height, output_width, 3}); - RETURN_IF_NOT_OK(Tensor::CreateEmpty(new_shape, input_cv->type(), &output_tensor)); - uint8_t *buffer = reinterpret_cast(&(*output_tensor->begin())); - imOut.Init(output_width, output_height, input_cv->shape()[2], reinterpret_cast(buffer), LDataType::UINT8); - imIn.Init(input_cv->shape()[1], input_cv->shape()[0], input_cv->shape()[2], input_cv->mat().data, LDataType::UINT8); - if (ResizeCubic(imIn, imOut, output_width, output_height) == false) { - RETURN_STATUS_UNEXPECTED("Resize: failed to do resize, please check the error msg."); - } - *output = output_tensor; - return Status::OK(); - } - cv::Mat in_image = input_cv->mat(); const uint32_t kResizeShapeLimits = 1000; // resize image too large or too small, 1000 is arbitrarily chosen here to prevent open cv from segmentation fault @@ -174,6 +159,21 @@ Status Resize(const std::shared_ptr &input, std::shared_ptr *out std::string err_msg = "Resize: the resizing width or height is invalid, width or height is zero."; return Status(StatusCode::kMDShapeMisMatch, err_msg); } + + if (mode == InterpolationMode::kCubicPil) { + LiteMat imIn, imOut; + std::shared_ptr output_tensor; + TensorShape new_shape = TensorShape({output_height, output_width, 3}); + RETURN_IF_NOT_OK(Tensor::CreateEmpty(new_shape, input_cv->type(), &output_tensor)); + uint8_t *buffer = reinterpret_cast(&(*output_tensor->begin())); + imOut.Init(output_width, output_height, input_cv->shape()[2], reinterpret_cast(buffer), LDataType::UINT8); + imIn.Init(input_cv->shape()[1], input_cv->shape()[0], input_cv->shape()[2], input_cv->mat().data, LDataType::UINT8); + if (ResizeCubic(imIn, imOut, output_width, output_height) == false) { + RETURN_STATUS_UNEXPECTED("Resize: failed to do resize, please check the error msg."); + } + *output = output_tensor; + return Status::OK(); + } try { TensorShape shape{output_height, output_width}; int num_channels = input_cv->shape()[CHANNEL_INDEX];