From 02f3c47ef63c44fb01174c2447d1cf29ea1e5cd6 Mon Sep 17 00:00:00 2001 From: wangzhe Date: Thu, 19 Nov 2020 17:25:53 +0800 Subject: [PATCH] add onnx model & dpp memory leak check and use const input data --- .../kernel/arm/base/detection_post_process_base.cc | 10 ++++++++++ .../kernel/arm/fp32/detection_post_process_fp32.cc | 4 ++-- .../kernel/arm/int8/detection_post_process_int8.cc | 2 +- .../models_with_several_inputs_or_without_outputs.cfg | 1 + 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/mindspore/lite/src/runtime/kernel/arm/base/detection_post_process_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/detection_post_process_base.cc index 4d0f8eea9b..05b34447f5 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/detection_post_process_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/detection_post_process_base.cc @@ -133,6 +133,16 @@ void DetectionPostProcessBaseCPUKernel::FreeAllocatedBuffer() { context_->allocator->Free(params_->selected_); params_->selected_ = nullptr; } + if (desc_.data_type == kNumberTypeInt8) { + if (input_boxes_ != nullptr) { + context_->allocator->Free(input_boxes_); + input_boxes_ = nullptr; + } + if (input_scores_ != nullptr) { + context_->allocator->Free(input_scores_); + input_scores_ = nullptr; + } + } } int DetectionPostProcessBaseCPUKernel::Run() { diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/detection_post_process_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/detection_post_process_fp32.cc index e4da8296ad..7102d8cc3b 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/detection_post_process_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/detection_post_process_fp32.cc @@ -33,8 +33,8 @@ int DetectionPostProcessCPUKernel::GetInputData() { MS_LOG(ERROR) << "Input data type error"; return RET_ERROR; } - input_boxes_ = reinterpret_cast(in_tensors_.at(0)->MutableData()); - input_scores_ = reinterpret_cast(in_tensors_.at(1)->MutableData()); + input_boxes_ = reinterpret_cast(in_tensors_.at(0)->data_c()); + input_scores_ = reinterpret_cast(in_tensors_.at(1)->data_c()); return RET_OK; } diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/detection_post_process_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/detection_post_process_int8.cc index 7290eae7c2..2a0a9787a2 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/detection_post_process_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/detection_post_process_int8.cc @@ -50,7 +50,7 @@ int DequantizeInt8ToFp32Run(void *cdata, int task_id) { } int DetectionPostProcessInt8CPUKernel::Dequantize(lite::Tensor *tensor, float **data) { - data_int8_ = reinterpret_cast(tensor->MutableData()); + data_int8_ = reinterpret_cast(tensor->data_c()); *data = reinterpret_cast(context_->allocator->Malloc(tensor->ElementsNum() * sizeof(float))); if (*data == nullptr) { MS_LOG(ERROR) << "Malloc data failed."; diff --git a/mindspore/lite/test/models_with_several_inputs_or_without_outputs.cfg b/mindspore/lite/test/models_with_several_inputs_or_without_outputs.cfg index 2b396d4c34..18c9dc96eb 100644 --- a/mindspore/lite/test/models_with_several_inputs_or_without_outputs.cfg +++ b/mindspore/lite/test/models_with_several_inputs_or_without_outputs.cfg @@ -24,3 +24,4 @@ efficientnet_lite3_int8_2.tflite efficientnet_lite4_int8_2.tflite mtk_transformer_encoder.tflite mtk_transformer_decoder_joint.tflite +ml_ei_facedetection.onnx