diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_dp.cc b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_dp.cc index 2956886cc40ec8cb0eb9e63e07cbf29372b54fd5..b83c333cf2aa06edf73d5ce5a5ea25c0c4d05bb1 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_dp.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_dp.cc @@ -18,10 +18,22 @@ #include "minddata/dataset/kernels/image/soft_dvpp/utils/soft_dp_check.h" #include "minddata/dataset/kernels/image/soft_dvpp/utils/soft_jpegd.h" #include "minddata/dataset/kernels/image/soft_dvpp/utils/soft_vpc.h" - +#include const int32_t decodeSucc = 0; +const int32_t checkParamErr = 1; +const int32_t num2 = 2; uint32_t DecodeAndResizeJpeg(SoftDpProcsessInfo *soft_dp_process_info) { + if (soft_dp_process_info == nullptr || soft_dp_process_info->input_buffer == nullptr || + soft_dp_process_info->input_buffer_size <= 0 || soft_dp_process_info->output_buffer == nullptr || + soft_dp_process_info->output_buffer_size <= 0) { + API_LOGE("The input buffer or out buffer is null or size is 0"); + return checkParamErr; + } + if (soft_dp_process_info->output_width % 2 == 1 || soft_dp_process_info->output_height % 2 == 1) { + API_LOGE("odd width and height dose not support"); + return checkParamErr; + } VpcInfo vpc_input_info; SoftJpegd soft_handler; int32_t ret = soft_handler.JpegdSoftwareDecodeProcess(&vpc_input_info, soft_dp_process_info); @@ -47,6 +59,12 @@ uint32_t DecodeAndResizeJpeg(SoftDpProcsessInfo *soft_dp_process_info) { } uint32_t DecodeAndCropAndResizeJpeg(SoftDpProcsessInfo *soft_dp_process_info, const SoftDpCropInfo &crop_info) { + if (soft_dp_process_info == nullptr || soft_dp_process_info->input_buffer == nullptr || + soft_dp_process_info->input_buffer_size <= 0 || soft_dp_process_info->output_buffer == nullptr || + soft_dp_process_info->output_buffer_size <= 0) { + API_LOGE("The input buffer or out buffer is null or size is 0"); + return checkParamErr; + } VpcInfo vpc_input_info; SoftJpegd soft_handler; @@ -63,6 +81,15 @@ uint32_t DecodeAndCropAndResizeJpeg(SoftDpProcsessInfo *soft_dp_process_info, co output.height = soft_dp_process_info->output_height; SoftDpCropInfo crop = crop_info; + if ((vpc_input_info.real_width % num2 == 1) && ((uint32_t)vpc_input_info.real_width == crop.right)) { + API_LOGD("crop width is equal the real width."); + crop.right = vpc_input_info.real_width - 1; + } + + if ((vpc_input_info.real_height % num2 == 1) && ((uint32_t)vpc_input_info.real_height == crop.down)) { + API_LOGD("crop height is equal the real height."); + crop.down = vpc_input_info.real_height - 1; + } SoftVpc soft_vpc; ret = soft_vpc.Process(vpc_input_info, crop, output); return ret; diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_jpegd.cc b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_jpegd.cc index 031e77ac9fd9387fa62b08f15fb2a2893428eb1a..c0516be037400c27a6124e0a0235ed29c3b3e758 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_jpegd.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_jpegd.cc @@ -26,6 +26,7 @@ #include #include #include +#include const uint32_t yuv400UvValue = 0x80; const int32_t num2 = 2; @@ -129,13 +130,17 @@ uint32_t SoftJpegd::AllocOutputBuffer(struct VpcInfo *vpc_input_info, int32_t *w int32_t *sub_sample) { CheckInputParam(*height, *width); uint32_t output_size = tjBufSizeYUV2(*width, decodePadding, *height, *sub_sample); + JPEGD_LOGD("In this case the format= %d, output size=%d, real width=%d, the real height=%d, thread_id=%lu.", + vpc_input_info->format, output_size, *width, *height, std::this_thread::get_id()); if (output_size == zeroBufSize) { JPEGD_LOGE("get outbuffer size failed!"); return decodeErr; } if (vpc_input_info->is_fake420) { - output_size = output_size * channel3 / num2; + *width = AlignUp(*width, num2); + *height = AlignUp(*height, num2); + output_size = (*width) * (*height) * channel3 / num2; } soft_decode_out_buf_ = new (std::nothrow) uint8_t[output_size]; @@ -172,7 +177,8 @@ uint32_t SoftJpegd::ConfigVpcInputData(struct VpcInfo *vpc_input_info, int32_t * int32_t uv_size = vpc_input_info->width * vpc_input_info->height / num2; int32_t safe_ret = memset_s(reinterpret_cast((uintptr_t)u_start), uv_size, yuv400UvValue, uv_size); if (safe_ret != 0) { - JPEGD_LOGE("config yuv400 uv memory failed."); + JPEGD_LOGE("config yuv400 uv memory failed.addr = 0x%llx, thread id = %lu", soft_decode_out_buf_, + std::this_thread::get_id()); delete[] soft_decode_out_buf_; soft_decode_out_buf_ = nullptr; vpc_input_info->addr = nullptr; @@ -229,7 +235,8 @@ uint32_t SoftJpegd::JpegdSoftwareDecodeProcess(struct VpcInfo *vpc_input_info, tjDecompressToYUV2(handle, soft_dp_process_info->input_buffer, soft_dp_process_info->input_buffer_size, soft_decode_out_buf_, width, decodePadding, height, JDCT_ISLOW); if (decode_res != decodeSucc) { - JPEGD_LOGE("Decompress jpeg failed."); + JPEGD_LOGE("Decompress jpeg failed, addr is 0x%llx, thread id= %lu.", soft_decode_out_buf_, + std::this_thread::get_id()); delete[] soft_decode_out_buf_; soft_decode_out_buf_ = nullptr; DestoryLibjpegSource(&libjpeg_handler, handle); diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_vpc.cc b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_vpc.cc index e04a0ece15135cc1c79f813997f13fd88acba3fc..041803a6242152da2029a91f518adfa6b444c3cc 100755 --- a/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_vpc.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_vpc.cc @@ -109,21 +109,21 @@ int32_t SoftVpc::CheckParamter() { uint32_t out_width = out_width_; uint32_t out_height = out_height_; - bool flag = (out_width * 16 >= crop_width) ? true : false; // Up to 16x magnification + bool flag = (out_width * 32 >= crop_width) ? true : false; // A maximum of 32x zoom-out + VPC_CHECK_COND_FAIL_PRINT_RETURN(flag, dpFail, + "Max reduction multiple is 32. Please check left(%u), right(%u), out_width(%u).", + left_, right_, out_width); // Up to 16x magnification + flag = (crop_width * 16 >= out_width) ? true : false; VPC_CHECK_COND_FAIL_PRINT_RETURN(flag, dpFail, "Max magnification is 16. Please check left(%u), right(%u), out_width(%u).", left_, right_, out_width); - flag = (crop_width * 32 >= out_width) ? true : false; // A maximum of 32x zoom-out - VPC_CHECK_COND_FAIL_PRINT_RETURN(flag, dpFail, - "Max reduction multiple is 32. Please check left(%u), right(%u), out_width(%u).", - left_, right_, out_width); - flag = (out_height * 16 >= crop_height) ? true : false; // Up to 16x magnification - VPC_CHECK_COND_FAIL_PRINT_RETURN( - flag, dpFail, "Max magnification is 16. Please check up(%u), down(%u), out_height(%u).", up_, down_, out_height); - flag = (crop_height * 32 >= out_height) ? true : false; // A maximum of 32x zoom-out + flag = (out_height * 32 >= crop_height) ? true : false; // A maximum of 32x zoom-out VPC_CHECK_COND_FAIL_PRINT_RETURN(flag, dpFail, "Max reduction multiple is 32. Please check up(%u), down(%u), out_height(%u).", up_, down_, out_height); + flag = (crop_height * 16 >= out_height) ? true : false; // Up to 16x magnification + VPC_CHECK_COND_FAIL_PRINT_RETURN( + flag, dpFail, "Max magnification is 16. Please check up(%u), down(%u), out_height(%u).", up_, down_, out_height); return dpSucc; } diff --git a/mindspore/dataset/transforms/vision/c_transforms.py b/mindspore/dataset/transforms/vision/c_transforms.py index 7faf65c28575d944e4893eac3a466c7dbe3efa85..f87b1747bf81a6c3ccd0be80a5040f625c845157 100644 --- a/mindspore/dataset/transforms/vision/c_transforms.py +++ b/mindspore/dataset/transforms/vision/c_transforms.py @@ -980,6 +980,9 @@ class SoftDvppDecodeResizeJpeg(cde.SoftDvppDecodeResizeJpegOp): When training, the DVPP of the ascend chip is not used, and the DVPP of the ascend chip is used during inference, and the accuracy of inference is lower than the accuracy of training. + And the input image size should be in range [32*32, 8192*8192]. + The zoom-out and zoom-in multiples of the image length and width should in range [1/32, 16]. + Only images with an even resolution can be output. The output of odd resolution is not supported. Args: size (Union[int, sequence]): The output size of the resized image. @@ -1002,6 +1005,9 @@ class SoftDvppDecodeRandomCropResizeJpeg(cde.SoftDvppDecodeRandomCropResizeJpegO ascend series chip DVPP module. The usage scenario is consistent with SoftDvppDecodeReiszeJpeg. + And the input image size should be in range [32*32, 8192*8192]. + The zoom-out and zoom-in multiples of the image length and width should in range [1/32, 16]. + Only images with an even resolution can be output. The output of odd resolution is not supported. Args: size (Union[int, sequence]): The size of the output image. diff --git a/tests/ut/python/dataset/test_soft_dvpp.py b/tests/ut/python/dataset/test_soft_dvpp.py index 6a5c93b13f016d459c1406c0006389d03e94f6f2..8f1182bddf9ea0c5d0a97f9297aa015364e998d3 100644 --- a/tests/ut/python/dataset/test_soft_dvpp.py +++ b/tests/ut/python/dataset/test_soft_dvpp.py @@ -84,6 +84,7 @@ def test_soft_dvpp_decode_random_crop_resize_jpeg(plot=False): visualize_image(image1, image2, mse) num_iter += 1 + def test_soft_dvpp_decode_resize_jpeg_supplement(plot=False): """ Test SoftDvppDecodeResizeJpeg op @@ -93,12 +94,12 @@ def test_soft_dvpp_decode_resize_jpeg_supplement(plot=False): # First dataset data1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) decode_op = vision.Decode() - resize_op = vision.Resize(256) + resize_op = vision.Resize(1134) data1 = data1.map(input_columns=["image"], operations=[decode_op, resize_op]) # Second dataset data2 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) - soft_dvpp_decode_resize_op = vision.SoftDvppDecodeResizeJpeg(256) + soft_dvpp_decode_resize_op = vision.SoftDvppDecodeResizeJpeg(1134) data2 = data2.map(input_columns=["image"], operations=soft_dvpp_decode_resize_op) num_iter = 0 @@ -114,8 +115,8 @@ def test_soft_dvpp_decode_resize_jpeg_supplement(plot=False): visualize_image(image1, image2, mse) num_iter += 1 + if __name__ == "__main__": test_soft_dvpp_decode_resize_jpeg(plot=True) test_soft_dvpp_decode_random_crop_resize_jpeg(plot=True) test_soft_dvpp_decode_resize_jpeg_supplement(plot=True) - \ No newline at end of file