From 6b09c038f07165ca55784cd30a66f47c93adae8d Mon Sep 17 00:00:00 2001 From: lyvette Date: Sat, 15 Aug 2020 10:48:58 +0800 Subject: [PATCH] supplement caffe permute parser supplement caffe permute parser --- .../converter/parser/caffe/CMakeLists.txt | 4 +- .../parser/caffe/caffe_permute_parser.cc | 46 +++++++++++++++++++ .../parser/caffe/caffe_permute_parser.h | 37 +++++++++++++++ 3 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 mindspore/lite/tools/converter/parser/caffe/caffe_permute_parser.cc create mode 100644 mindspore/lite/tools/converter/parser/caffe/caffe_permute_parser.h diff --git a/mindspore/lite/tools/converter/parser/caffe/CMakeLists.txt b/mindspore/lite/tools/converter/parser/caffe/CMakeLists.txt index 4562c24290..fb2efeb879 100644 --- a/mindspore/lite/tools/converter/parser/caffe/CMakeLists.txt +++ b/mindspore/lite/tools/converter/parser/caffe/CMakeLists.txt @@ -51,4 +51,6 @@ add_library(caffe_parser_mid OBJECT ${CMAKE_CURRENT_SOURCE_DIR}/caffe_inspector.cc ${CMAKE_CURRENT_SOURCE_DIR}/caffe_inspector.h ${CMAKE_CURRENT_SOURCE_DIR}/caffe_interp_parser.cc - ${CMAKE_CURRENT_SOURCE_DIR}/caffe_interp_parser.h) + ${CMAKE_CURRENT_SOURCE_DIR}/caffe_interp_parser.h + ${CMAKE_CURRENT_SOURCE_DIR}/caffe_permute_parser.cc + ${CMAKE_CURRENT_SOURCE_DIR}/caffe_permute_parser.h) diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_permute_parser.cc b/mindspore/lite/tools/converter/parser/caffe/caffe_permute_parser.cc new file mode 100644 index 0000000000..3e42c03ad6 --- /dev/null +++ b/mindspore/lite/tools/converter/parser/caffe/caffe_permute_parser.cc @@ -0,0 +1,46 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "mindspore/lite/tools/converter/parser/caffe/caffe_permute_parser.h" +#include + +namespace mindspore { +namespace lite { +STATUS CaffePermuteParser::Parse(const caffe::LayerParameter &proto, + const caffe::LayerParameter &weight, + schema::CNodeT *op, + std::vector *weightVec) { + op->name = proto.name(); + std::unique_ptr attr(new schema::TransposeT()); + const caffe::PermuteParameter permuteParam = proto.permute_param(); + + const int num_order_dims = permuteParam.order_size(); + attr->perm.resize(num_order_dims); + for (int i = 0; i < num_order_dims; ++i) { + attr->perm[i] = (int32_t)permuteParam.order()[i]; + } + attr->conjugate = false; + + op->primitive = std::make_unique(); + op->primitive->value.value = attr.release(); + op->primitive->value.type = schema::PrimitiveType_Transpose; + return RET_OK; +} + +CaffeNodeRegistrar g_caffePermuteParser("Permute", new CaffePermuteParser()); +} // namespace lite +} // namespace mindspore + diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_permute_parser.h b/mindspore/lite/tools/converter/parser/caffe/caffe_permute_parser.h new file mode 100644 index 0000000000..f61be5da38 --- /dev/null +++ b/mindspore/lite/tools/converter/parser/caffe/caffe_permute_parser.h @@ -0,0 +1,37 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MINDSPORE_CCSRC_TOOLS_LITE_CONVERTER_PARSER_CAFFE_CAFFE_PERMUTE_PARSER_H_ +#define MINDSPORE_CCSRC_TOOLS_LITE_CONVERTER_PARSER_CAFFE_CAFFE_PERMUTE_PARSER_H_ + +#include +#include "mindspore/lite/tools/converter/parser/caffe/caffe_node_parser.h" +#include "mindspore/lite/tools/converter/parser/caffe/caffe_node_parser_registry.h" + +namespace mindspore { +namespace lite { +class CaffePermuteParser : public CaffeNodeParser { + public: + CaffePermuteParser() : CaffeNodeParser("Permute") {} + + 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_PERMUTE_PARSER_H_ +