| @@ -14,14 +14,32 @@ | |||
| * limitations under the License. | |||
| */ | |||
| #include <memory> | |||
| #include "mindspore/lite/tools/converter/parser/caffe/caffe_relu6_parser.h" | |||
| #include <memory> | |||
| namespace mindspore { | |||
| namespace lite { | |||
| STATUS CaffeRelu6Parser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight, | |||
| schema::CNodeT *op, std::vector<schema::TensorT *> *weightVec) { | |||
| STATUS CaffeRelu6Parser::Parse(const caffe::LayerParameter &proto, | |||
| const caffe::LayerParameter &weight, | |||
| schema::CNodeT *op, | |||
| std::vector<schema::TensorT *> *weightVec) { | |||
| MS_LOG(DEBUG) << "parse CaffeRelu6Parser"; | |||
| if (op == nullptr) { | |||
| MS_LOG(ERROR) << "op is null"; | |||
| return RET_NULL_PTR; | |||
| } | |||
| op->primitive = std::make_unique<schema::PrimitiveT>(); | |||
| if (op->primitive == nullptr) { | |||
| MS_LOG(ERROR) << "op->primitive is null"; | |||
| return RET_NULL_PTR; | |||
| } | |||
| std::unique_ptr<schema::ActivationT> 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<schema::PrimitiveT>(); | |||
| 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; | |||
| } | |||
| @@ -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 <vector> | |||
| #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<schema::TensorT *> *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_ | |||
| @@ -24,11 +24,27 @@ STATUS CaffeTanhParser::Parse(const caffe::LayerParameter &proto, | |||
| const caffe::LayerParameter &weight, | |||
| schema::CNodeT *op, | |||
| std::vector<schema::TensorT *> *weightVec) { | |||
| MS_LOG(DEBUG) << "parse CaffeTanhParser"; | |||
| if (op == nullptr) { | |||
| MS_LOG(ERROR) << "op is null"; | |||
| return RET_NULL_PTR; | |||
| } | |||
| op->primitive = std::make_unique<schema::PrimitiveT>(); | |||
| if (op->primitive == nullptr) { | |||
| MS_LOG(ERROR) << "op->primitive is null"; | |||
| return RET_NULL_PTR; | |||
| } | |||
| std::unique_ptr<schema::ActivationT> attr(new schema::ActivationT()); | |||
| if (attr == nullptr) { | |||
| MS_LOG(ERROR) << "new op failed"; | |||
| return RET_NULL_PTR; | |||
| } | |||
| attr->type = schema::ActivationType_TANH; | |||
| op->primitive = std::make_unique<schema::PrimitiveT>(); | |||
| 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; | |||
| } | |||
| @@ -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 <vector> | |||
| #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<schema::TensorT *> *weightVec) override; | |||
| }; | |||
| } // namespace lite | |||
| } // namespace mindspore | |||
| #endif // LITE_CAFFE_TANH_PARSER_H | |||
| #endif // MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_CAFFE_CAFFE_TANH_PARSER_H | |||