supplement caffe permute parser

supplement caffe permute parser
This commit is contained in:
lyvette 2020-08-15 10:48:58 +08:00
parent b34b7973be
commit 6b09c038f0
3 changed files with 86 additions and 1 deletions

View File

@ -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)

View File

@ -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 <memory>
namespace mindspore {
namespace lite {
STATUS CaffePermuteParser::Parse(const caffe::LayerParameter &proto,
const caffe::LayerParameter &weight,
schema::CNodeT *op,
std::vector<schema::TensorT *> *weightVec) {
op->name = proto.name();
std::unique_ptr<schema::TransposeT> 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<schema::PrimitiveT>();
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

View File

@ -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 <vector>
#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<schema::TensorT *> *weightVec) override;
};
} // namespace lite
} // namespace mindspore
#endif // MINDSPORE_CCSRC_TOOLS_LITE_CONVERTER_PARSER_CAFFE_CAFFE_PERMUTE_PARSER_H_