From 312f247ca3a014c270af3ccf4c6cd6efb0db9b80 Mon Sep 17 00:00:00 2001 From: lyvette Date: Tue, 25 Aug 2020 16:54:19 +0800 Subject: [PATCH] modify caffe relu6 & tanh parser format --- .../parser/caffe/caffe_relu6_parser.cc | 29 +++++++++++++++---- .../parser/caffe/caffe_relu6_parser.h | 10 ++++--- .../parser/caffe/caffe_tanh_parser.cc | 22 ++++++++++++-- .../parser/caffe/caffe_tanh_parser.h | 10 ++++--- 4 files changed, 55 insertions(+), 16 deletions(-) diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_relu6_parser.cc b/mindspore/lite/tools/converter/parser/caffe/caffe_relu6_parser.cc index 207f7ec963b..0ad8a4a1946 100644 --- a/mindspore/lite/tools/converter/parser/caffe/caffe_relu6_parser.cc +++ b/mindspore/lite/tools/converter/parser/caffe/caffe_relu6_parser.cc @@ -14,14 +14,32 @@ * limitations under the License. */ -#include #include "mindspore/lite/tools/converter/parser/caffe/caffe_relu6_parser.h" +#include namespace mindspore { namespace lite { -STATUS CaffeRelu6Parser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight, - schema::CNodeT *op, std::vector *weightVec) { +STATUS CaffeRelu6Parser::Parse(const caffe::LayerParameter &proto, + const caffe::LayerParameter &weight, + schema::CNodeT *op, + std::vector *weightVec) { + MS_LOG(DEBUG) << "parse CaffeRelu6Parser"; + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + std::unique_ptr attr(new schema::ActivationT()); + if (attr == nullptr) { + MS_LOG(ERROR) << "new op failed"; + return RET_NULL_PTR; + } + attr->type = schema::ActivationType_RELU6; // relu: negative_slope = 0, no parameter; // leakyrelu: negative_slope != 0; @@ -32,9 +50,10 @@ STATUS CaffeRelu6Parser::Parse(const caffe::LayerParameter &proto, const caffe:: attr->alpha = negative_slope; } } - op->primitive = std::make_unique(); - op->primitive->value.value = attr.release(); + + op->name = proto.name(); op->primitive->value.type = schema::PrimitiveType_Activation; + op->primitive->value.value = attr.release(); return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_relu6_parser.h b/mindspore/lite/tools/converter/parser/caffe/caffe_relu6_parser.h index 3c347c232ed..bb6e948ffea 100644 --- a/mindspore/lite/tools/converter/parser/caffe/caffe_relu6_parser.h +++ b/mindspore/lite/tools/converter/parser/caffe/caffe_relu6_parser.h @@ -13,8 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef MINDSPORE_CCSRC_TOOLS_LITE_CONVERTER_PARSER_CAFFE_CAFFE_RELU6_PARSER_H_ -#define MINDSPORE_CCSRC_TOOLS_LITE_CONVERTER_PARSER_CAFFE_CAFFE_RELU6_PARSER_H_ +#ifndef MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_CAFFE_CAFFE_RELU6_PARSER_H_ +#define MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_CAFFE_CAFFE_RELU6_PARSER_H_ #include #include "mindspore/lite/tools/converter/parser/caffe/caffe_node_parser.h" @@ -26,10 +26,12 @@ class CaffeRelu6Parser : public CaffeNodeParser { public: CaffeRelu6Parser() : CaffeNodeParser("relu6") {} - STATUS Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight, schema::CNodeT *op, + STATUS Parse(const caffe::LayerParameter &proto, + const caffe::LayerParameter &weight, + schema::CNodeT *op, std::vector *weightVec) override; }; } // namespace lite } // namespace mindspore -#endif // MINDSPORE_CCSRC_TOOLS_LITE_CONVERTER_PARSER_CAFFE_CAFFE_RELU_PARSER_H_ +#endif // MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_CAFFE_CAFFE_RELU6_PARSER_H_ diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_tanh_parser.cc b/mindspore/lite/tools/converter/parser/caffe/caffe_tanh_parser.cc index fef40348924..2dc46593ff4 100644 --- a/mindspore/lite/tools/converter/parser/caffe/caffe_tanh_parser.cc +++ b/mindspore/lite/tools/converter/parser/caffe/caffe_tanh_parser.cc @@ -24,11 +24,27 @@ STATUS CaffeTanhParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight, schema::CNodeT *op, std::vector *weightVec) { - std::unique_ptr attr(new schema::ActivationT()); - attr->type = schema::ActivationType_TANH; + MS_LOG(DEBUG) << "parse CaffeTanhParser"; + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } op->primitive = std::make_unique(); - op->primitive->value.value = attr.release(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + + std::unique_ptr attr(new schema::ActivationT()); + if (attr == nullptr) { + MS_LOG(ERROR) << "new op failed"; + return RET_NULL_PTR; + } + attr->type = schema::ActivationType_TANH; + + op->name = proto.name(); op->primitive->value.type = schema::PrimitiveType_Activation; + op->primitive->value.value = attr.release(); return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_tanh_parser.h b/mindspore/lite/tools/converter/parser/caffe/caffe_tanh_parser.h index 7e5e0da6ab5..bcd8366f892 100644 --- a/mindspore/lite/tools/converter/parser/caffe/caffe_tanh_parser.h +++ b/mindspore/lite/tools/converter/parser/caffe/caffe_tanh_parser.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef LITE_CAFFE_TANH_PARSER_H -#define LITE_CAFFE_TANH_PARSER_H +#ifndef MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_CAFFE_CAFFE_TANH_PARSER_H +#define MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_CAFFE_CAFFE_TANH_PARSER_H #include #include "tools/converter/parser/caffe/caffe_node_parser.h" @@ -27,10 +27,12 @@ class CaffeTanhParser : public CaffeNodeParser { public: CaffeTanhParser() : CaffeNodeParser("tanh") {} - STATUS Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight, schema::CNodeT *op, + STATUS Parse(const caffe::LayerParameter &proto, + const caffe::LayerParameter &weight, + schema::CNodeT *op, std::vector *weightVec) override; }; } // namespace lite } // namespace mindspore -#endif // LITE_CAFFE_TANH_PARSER_H +#endif // MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_CAFFE_CAFFE_TANH_PARSER_H