From 1990cfb83c2146f445efd83009cd3510e7af8b04 Mon Sep 17 00:00:00 2001 From: wang_shaocong Date: Thu, 22 Apr 2021 14:45:28 +0800 Subject: [PATCH] [MSLITE] Fix bug of fp16subgraph preprocess. --- .../backend/kernel_compiler/cpu/nnacl/infer/where_infer.c | 2 ++ mindspore/lite/src/runtime/kernel/arm/fp32/where_fp32.cc | 1 - mindspore/lite/src/sub_graph_kernel.cc | 7 ++++--- mindspore/lite/test/models_onnx_fp16.cfg | 1 + 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/infer/where_infer.c b/mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/infer/where_infer.c index 5c4830178ce..b76f3031900 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/infer/where_infer.c +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/infer/where_infer.c @@ -31,6 +31,8 @@ int WhereInferShape(const TensorC *const *inputs, size_t inputs_size, TensorC ** // Need to dynamically allocate at runtime. if (inputs_size == 1) { + output->data_type_ = kNumberTypeInt32; + output->format_ = input->format_; return NNACL_INFER_INVALID; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/where_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/where_fp32.cc index 8fcc69dafde..5c6a1e64181 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/where_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/where_fp32.cc @@ -89,7 +89,6 @@ int WhereCPUKernel::RunWithSingleInput() { } } } - out_tensors_.at(0)->set_data_type(kNumberTypeInt32); std::vector output_shape = {true_num, where_param_->rank_}; out_tensors_.at(0)->set_shape(output_shape); out_tensors_.at(0)->FreeData(); diff --git a/mindspore/lite/src/sub_graph_kernel.cc b/mindspore/lite/src/sub_graph_kernel.cc index 1392652772b..d2fa37fd35a 100644 --- a/mindspore/lite/src/sub_graph_kernel.cc +++ b/mindspore/lite/src/sub_graph_kernel.cc @@ -226,12 +226,13 @@ int CpuFp16SubGraph::Float32TensorToFloat16Tensor(lite::Tensor *tensor) { MS_ASSERT(tensor != nullptr); auto float32_data = tensor->data_c(); auto own_data = tensor->own_data(); + tensor->set_data_type(TypeId::kNumberTypeFloat16); if (float32_data == nullptr) { - MS_LOG(ERROR) << "tensor data is null."; - return lite::RET_NULL_PTR; + // the input data may be nullptr of merge. + MS_LOG(INFO) << "tensor data is null."; + return lite::RET_OK; } tensor->set_data(nullptr); - tensor->set_data_type(TypeId::kNumberTypeFloat16); auto ret = tensor->MallocData(); if (RET_OK != ret) { MS_LOG(ERROR) << "malloc data failed"; diff --git a/mindspore/lite/test/models_onnx_fp16.cfg b/mindspore/lite/test/models_onnx_fp16.cfg index d20fe7943bc..531419c82c5 100644 --- a/mindspore/lite/test/models_onnx_fp16.cfg +++ b/mindspore/lite/test/models_onnx_fp16.cfg @@ -79,3 +79,4 @@ Q_face_recognition.onnx 2 ml_video_edit_enhance_update_tmp.onnx 0.5 Q888_face_recognition.onnx 3.5 Q888_iris_detect.onnx 0.5 +ssd_mobilenet_v1_10.onnx;1,383,640,3 0.5