From c432bc7207639c4285595541dc3138b3c03a03e0 Mon Sep 17 00:00:00 2001 From: yefeng Date: Tue, 30 Mar 2021 09:29:02 +0800 Subject: [PATCH] fix_issue_to_r1.2 --- mindspore/lite/nnacl/fp32/arithmetic_fp32.c | 8 +++++ mindspore/lite/nnacl/fp32/arithmetic_fp32.h | 1 + mindspore/lite/nnacl/infer/transpose_infer.c | 3 ++ .../kernel/arm/fp32/arithmetic_fp32.cc | 5 +-- .../parser/tf/tf_activation_parser.cc | 31 ++++++------------- .../parser/tf/tf_activation_parser.h | 10 ------ 6 files changed, 24 insertions(+), 34 deletions(-) diff --git a/mindspore/lite/nnacl/fp32/arithmetic_fp32.c b/mindspore/lite/nnacl/fp32/arithmetic_fp32.c index bdae1dc197..e16af7f61c 100644 --- a/mindspore/lite/nnacl/fp32/arithmetic_fp32.c +++ b/mindspore/lite/nnacl/fp32/arithmetic_fp32.c @@ -145,6 +145,14 @@ int ElementLogicalOr(const float *in0, const float *in1, float *out, int size) { return NNACL_OK; } +int ElementLogicalOrBool(const bool *in0, const bool *in1, bool *out, int size) { + int index = 0; + for (; index < size; index++) { + out[index] = (in0[index]) | (in1[index]); + } + return NNACL_OK; +} + int ElementMaximum(const float *in0, const float *in1, float *out, int size) { int index = 0; #ifdef ENABLE_NEON diff --git a/mindspore/lite/nnacl/fp32/arithmetic_fp32.h b/mindspore/lite/nnacl/fp32/arithmetic_fp32.h index 1580ea3b9f..b329bf6908 100644 --- a/mindspore/lite/nnacl/fp32/arithmetic_fp32.h +++ b/mindspore/lite/nnacl/fp32/arithmetic_fp32.h @@ -42,6 +42,7 @@ int ElementLogicalAndBool(const bool *in0, const bool *in1, bool *out, int size) /* logical or */ int ElementLogicalOr(const float *in0, const float *in1, float *out, int size); +int ElementLogicalOrBool(const bool *in0, const bool *in1, bool *out, int size); /* max min */ int ElementMaximum(const float *in0, const float *in1, float *out, int size); diff --git a/mindspore/lite/nnacl/infer/transpose_infer.c b/mindspore/lite/nnacl/infer/transpose_infer.c index 8b52e8dade..24e974a36d 100644 --- a/mindspore/lite/nnacl/infer/transpose_infer.c +++ b/mindspore/lite/nnacl/infer/transpose_infer.c @@ -49,6 +49,9 @@ int TransposeInferShape(const TensorC *const *inputs, size_t inputs_size, Tensor if (perm_tensor->shape_size_ == 0) { return NNACL_INFER_INVALID; } + if (perms_num != 0 && perm_data == NULL) { + return NNACL_INFER_INVALID; + } int perm[MAX_SHAPE_SIZE]; size_t perm_size = 0; for (size_t i = 0; i < perms_num; i++) { diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic_fp32.cc index 5b6cd6588e..6c3e0e3d4b 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic_fp32.cc @@ -213,8 +213,8 @@ void ArithmeticCPUKernel::InitRunFunction(int primitive_type) { ElementOptDivInt}, {PrimitiveType_LogicalAnd, schema::ActivationType_NO_ACTIVATION, ElementLogicalAnd, ElementLogicalAndInt, ElementLogicalAndBool, nullptr, nullptr}, - {PrimitiveType_LogicalOr, schema::ActivationType_NO_ACTIVATION, ElementLogicalOr, nullptr, nullptr, nullptr, - nullptr}, + {PrimitiveType_LogicalOr, schema::ActivationType_NO_ACTIVATION, ElementLogicalOr, nullptr, ElementLogicalOrBool, + nullptr, nullptr}, {PrimitiveType_Maximum, schema::ActivationType_NO_ACTIVATION, ElementMaximum, ElementMaximumInt, nullptr, nullptr, nullptr}, {PrimitiveType_Minimum, schema::ActivationType_NO_ACTIVATION, ElementMinimum, ElementMinimumInt, nullptr, nullptr, @@ -435,6 +435,7 @@ REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_LogicalAnd, LiteKernelCreator REG_KERNEL(kCPU, kNumberTypeBool, PrimitiveType_LogicalAnd, LiteKernelCreator) REG_KERNEL(kCPU, kNumberTypeInt32, PrimitiveType_LogicalAnd, LiteKernelCreator) REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_LogicalOr, LiteKernelCreator) +REG_KERNEL(kCPU, kNumberTypeBool, PrimitiveType_LogicalOr, LiteKernelCreator) REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Maximum, LiteKernelCreator) REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Minimum, LiteKernelCreator) REG_KERNEL(kCPU, kNumberTypeInt32, PrimitiveType_Maximum, LiteKernelCreator) diff --git a/mindspore/lite/tools/converter/parser/tf/tf_activation_parser.cc b/mindspore/lite/tools/converter/parser/tf/tf_activation_parser.cc index 3e000499a2..df1acd9f6f 100644 --- a/mindspore/lite/tools/converter/parser/tf/tf_activation_parser.cc +++ b/mindspore/lite/tools/converter/parser/tf/tf_activation_parser.cc @@ -41,6 +41,14 @@ ops::PrimitiveC *TFActivationParser::Parse(const tensorflow::NodeDef &tf_op, prim->set_activation_type(mindspore::ActivationType::SELU); } else if (tf_op.op() == "Softplus") { prim->set_activation_type(mindspore::ActivationType::SOFTPLUS); + } else if (tf_op.op() == "LeakyRelu") { + prim->set_activation_type(mindspore::ActivationType::LEAKY_RELU); + tensorflow::AttrValue attr_value; + if (!TensorFlowUtils::FindAttrValue(tf_op, "alpha", &attr_value)) { + MS_LOG(ERROR) << "The attribute alpha should be specified."; + return nullptr; + } + prim->set_alpha(attr_value.f()); } else { MS_LOG(ERROR) << "unsupported activation type:" << tf_op.op(); return nullptr; @@ -55,33 +63,12 @@ ops::PrimitiveC *TFActivationParser::Parse(const tensorflow::NodeDef &tf_op, return prim.release(); } -ops::PrimitiveC *TFLeakyReluParser::Parse(const tensorflow::NodeDef &tf_op, - const std::map &tf_node_map, - std::vector *inputs, int *output_size) { - auto prim = std::make_unique(); - - tensorflow::AttrValue attr_value; - if (!TensorFlowUtils::FindAttrValue(tf_op, "alpha", &attr_value)) { - MS_LOG(ERROR) << "The attribute alpha should be specified."; - return nullptr; - } - prim->set_negative_slope(attr_value.f()); - - *output_size = 1; - if (AddOpInput(tf_op, 0, inputs) != RET_OK) { - MS_LOG(ERROR) << "add op input failed"; - return nullptr; - } - - return prim.release(); -} - TFNodeRegistrar g_tfReluParser("Relu", new TFActivationParser()); TFNodeRegistrar g_tfRelu6Parser("Relu6", new TFActivationParser()); TFNodeRegistrar g_tfSigmoidParser("Sigmoid", new TFActivationParser()); TFNodeRegistrar g_tfTanhParser("Tanh", new TFActivationParser()); TFNodeRegistrar g_tfSeLUParser("Selu", new TFActivationParser()); -TFNodeRegistrar g_tfLeakyReluParser("LeakyRelu", new TFLeakyReluParser()); +TFNodeRegistrar g_tfLeakyReluParser("LeakyRelu", new TFActivationParser()); TFNodeRegistrar g_tfSoftplusParser("Softplus", new TFActivationParser()); } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tf/tf_activation_parser.h b/mindspore/lite/tools/converter/parser/tf/tf_activation_parser.h index 87dce5e6de..ece8aee5fd 100644 --- a/mindspore/lite/tools/converter/parser/tf/tf_activation_parser.h +++ b/mindspore/lite/tools/converter/parser/tf/tf_activation_parser.h @@ -33,16 +33,6 @@ class TFActivationParser : public TFNodeParser { const std::map &tf_node_map, std::vector *inputs, int *output_size) override; }; - -class TFLeakyReluParser : public TFNodeParser { - public: - TFLeakyReluParser() = default; - ~TFLeakyReluParser() override = default; - - ops::PrimitiveC *Parse(const tensorflow::NodeDef &tf_op, - const std::map &tf_node_map, - std::vector *inputs, int *output_size) override; -}; } // namespace lite } // namespace mindspore