提交 cf66e62e 编写于 作者: M mindspore-ci-bot 提交者: Gitee

!5545 fix tflite and caffe single operator question, add tflite custom parser

Merge pull request !5545 from 徐安越/master
......@@ -194,6 +194,7 @@ union PrimitiveType {
MakeTuple,
ToFormat,
Proposal,
Custom,
}
enum QuantType: int {
......
......@@ -472,6 +472,9 @@ table Neg {
}
table Exp {
base : float;
scale : float;
shift : float;
}
table Cos {
......@@ -896,3 +899,7 @@ table Proposal {
post_nms_topn : int;
nms_thresh : float;
}
table Custom {
custom : [ubyte];
}
\ No newline at end of file
......@@ -53,7 +53,7 @@ std::vector<int> SpaceToBatchND::GetPaddings() const {
int SpaceToBatchND::UnPackToFlatBuilder(const schema::Primitive *primitive, flatbuffers::FlatBufferBuilder *fbb) {
MS_ASSERT(nullptr != primitive);
MS_ASSERT(nullptr != fbb);
auto attr = primitive->value_as_SpaceToBatch();
auto attr = primitive->value_as_SpaceToBatchND();
if (attr == nullptr) {
MS_LOG(ERROR) << "value_as_SpaceToBatch return nullptr";
return RET_ERROR;
......@@ -71,7 +71,7 @@ int SpaceToBatchND::UnPackToFlatBuilder(const schema::Primitive *primitive, flat
}
}
auto val_offset = schema::CreateSpaceToBatchDirect(*fbb, &blockShape, &paddings);
auto prim_offset = schema::CreatePrimitive(*fbb, schema::PrimitiveType_SpaceToBatch, val_offset.o);
auto prim_offset = schema::CreatePrimitive(*fbb, schema::PrimitiveType_SpaceToBatchND, val_offset.o);
fbb->Finish(prim_offset);
return RET_OK;
}
......
......@@ -111,6 +111,7 @@
#include "src/ops/squared_difference.h"
#include "src/ops/ceil.h"
#include "src/ops/round.h"
#include "src/ops/sparse_to_dense.h"
#include "nnacl/op_base.h"
#include "nnacl/fp32/arg_min_max.h"
#include "nnacl/fp32/cast.h"
......@@ -167,6 +168,7 @@
#include "nnacl/fp32/embedding_lookup.h"
#include "nnacl/fp32/elu.h"
#include "nnacl/leaky_relu_parameter.h"
#include "nnacl/sparse_to_dense.h"
namespace mindspore::kernel {
......@@ -678,11 +680,11 @@ OpParameter *PopulateArithmetic(const mindspore::lite::PrimitiveC *primitive) {
break;
}
auto tmp_shape = ((lite::Arithmetic *)primitive)->InShape0();
(void)memcpy(arithmetic_param->in_shape0_, static_cast<void *>(tmp_shape.data()), tmp_shape.size() * sizeof(int));
memcpy(arithmetic_param->in_shape0_, static_cast<void *>(tmp_shape.data()), tmp_shape.size() * sizeof(int));
tmp_shape = ((lite::Arithmetic *)primitive)->InShape1();
(void)memcpy(arithmetic_param->in_shape1_, static_cast<void *>(tmp_shape.data()), tmp_shape.size() * sizeof(int));
memcpy(arithmetic_param->in_shape1_, static_cast<void *>(tmp_shape.data()), tmp_shape.size() * sizeof(int));
tmp_shape = ((lite::Arithmetic *)primitive)->OutputShape();
(void)memcpy(arithmetic_param->out_shape_, static_cast<void *>(tmp_shape.data()), tmp_shape.size() * sizeof(int));
memcpy(arithmetic_param->out_shape_, static_cast<void *>(tmp_shape.data()), tmp_shape.size() * sizeof(int));
return reinterpret_cast<OpParameter *>(arithmetic_param);
}
......@@ -1015,6 +1017,18 @@ OpParameter *PopulateSliceParameter(const mindspore::lite::PrimitiveC *primitive
return reinterpret_cast<OpParameter *>(slice_param);
}
OpParameter *PopulateSparseToDenseParameter(const mindspore::lite::PrimitiveC *primitive) {
SparseToDenseParameter *sparse_to_dense_param =
reinterpret_cast<SparseToDenseParameter *>(malloc(sizeof(SparseToDenseParameter)));
if (sparse_to_dense_param == nullptr) {
MS_LOG(ERROR) << "malloc SparseToDenseParameter failed.";
return nullptr;
}
memset(sparse_to_dense_param, 0, sizeof(SparseToDenseParameter));
sparse_to_dense_param->op_parameter_.type_ = primitive->Type();
return reinterpret_cast<OpParameter *>(sparse_to_dense_param);
}
OpParameter *PopulateBroadcastToParameter(const mindspore::lite::PrimitiveC *primitive) {
BroadcastToParameter *broadcast_param =
reinterpret_cast<BroadcastToParameter *>(malloc(sizeof(BroadcastToParameter)));
......@@ -1205,28 +1219,26 @@ OpParameter *PopulateSpaceToBatchParameter(const mindspore::lite::PrimitiveC *pr
}
memset(space_batch_param, 0, sizeof(SpaceToBatchParameter));
space_batch_param->op_parameter_.type_ = primitive->Type();
space_batch_param->op_parameter_.type_ = primitive->Type();
auto block_sizes = ((mindspore::lite::SpaceToBatch *)primitive)->BlockSizes();
(void)memcpy(space_batch_param->block_sizes_, (block_sizes.data()), block_sizes.size() * sizeof(int));
memcpy(space_batch_param->block_sizes_, (block_sizes.data()), block_sizes.size() * sizeof(int));
auto paddings = ((mindspore::lite::SpaceToBatch *)primitive)->Paddings();
(void)memcpy(space_batch_param->paddings_, (paddings.data()), paddings.size() * sizeof(int));
memcpy(space_batch_param->paddings_, (paddings.data()), paddings.size() * sizeof(int));
return reinterpret_cast<OpParameter *>(space_batch_param);
}
OpParameter *PopulateSpaceToBatchParameterND(const mindspore::lite::PrimitiveC *primitivec) {
auto *space_batch_param = new (std::nothrow) SpaceToBatchParameter();
if (space_batch_param == nullptr) {
OpParameter *PopulateSpaceToBatchNDParameter(const mindspore::lite::PrimitiveC *primitive) {
auto *space_batch_param_nd = new (std::nothrow) SpaceToBatchParameter();
if (space_batch_param_nd == nullptr) {
MS_LOG(ERROR) << "new SpaceToBatchParameter failed.";
return nullptr;
}
mindspore::lite::SpaceToBatchND *primitive = (mindspore::lite::SpaceToBatchND *)primitivec;
space_batch_param->op_parameter_.type_ = primitive->Type();
auto block_sizes = primitive->GetBlockShape();
(void)memcpy(space_batch_param->block_sizes_, (block_sizes.data()), block_sizes.size() * sizeof(int));
auto paddings = primitive->GetPaddings();
(void)memcpy(space_batch_param->paddings_, (paddings.data()), paddings.size() * sizeof(int));
return reinterpret_cast<OpParameter *>(space_batch_param);
space_batch_param_nd->op_parameter_.type_ = primitive->Type();
auto block_sizes = ((mindspore::lite::SpaceToBatchND *)primitive)->GetBlockShape();
memcpy(space_batch_param_nd->block_sizes_, (block_sizes.data()), block_sizes.size() * sizeof(int));
auto paddings = ((mindspore::lite::SpaceToBatchND *)primitive)->GetPaddings();
memcpy(space_batch_param_nd->paddings_, (paddings.data()), paddings.size() * sizeof(int));
return reinterpret_cast<OpParameter *>(space_batch_param_nd);
}
OpParameter *PopulateResizeParameter(const mindspore::lite::PrimitiveC *primitive) {
......@@ -1359,13 +1371,13 @@ OpParameter *PopulateStridedSliceParameter(const mindspore::lite::PrimitiveC *pr
auto n_dims = ((lite::StridedSlice *)primitive)->NDims();
strided_slice_param->num_axes_ = n_dims;
auto begin = ((lite::StridedSlice *)primitive)->GetBegins();
(void)memcpy(strided_slice_param->begins_, (begin.data()), begin.size() * sizeof(int));
memcpy(strided_slice_param->begins_, (begin.data()), begin.size() * sizeof(int));
auto end = ((lite::StridedSlice *)primitive)->GetEnds();
(void)memcpy(strided_slice_param->ends_, (end.data()), end.size() * sizeof(int));
memcpy(strided_slice_param->ends_, (end.data()), end.size() * sizeof(int));
auto stride = ((lite::StridedSlice *)primitive)->GetStrides();
(void)memcpy(strided_slice_param->strides_, (stride.data()), stride.size() * sizeof(int));
memcpy(strided_slice_param->strides_, (stride.data()), stride.size() * sizeof(int));
auto in_shape = ((lite::StridedSlice *)primitive)->GetInShape();
(void)memcpy(strided_slice_param->in_shape_, (in_shape.data()), in_shape.size() * sizeof(int));
memcpy(strided_slice_param->in_shape_, (in_shape.data()), in_shape.size() * sizeof(int));
return reinterpret_cast<OpParameter *>(strided_slice_param);
}
......@@ -1405,9 +1417,9 @@ OpParameter *PopulatePriorBoxParameter(const mindspore::lite::PrimitiveC *primit
return nullptr;
}
prior_box_param->max_sizes_size = prior_box_attr->GetMaxSizes().size();
(void)memcpy(prior_box_param->max_sizes, prior_box_attr->GetMaxSizes().data(),
memcpy(prior_box_param->max_sizes, prior_box_attr->GetMaxSizes().data(),
prior_box_attr->GetMaxSizes().size() * sizeof(int32_t));
(void)memcpy(prior_box_param->min_sizes, prior_box_attr->GetMinSizes().data(),
memcpy(prior_box_param->min_sizes, prior_box_attr->GetMinSizes().data(),
prior_box_attr->GetMinSizes().size() * sizeof(int32_t));
if (prior_box_attr->GetAspectRatios().size() > PRIOR_BOX_MAX_NUM) {
......@@ -1417,7 +1429,7 @@ OpParameter *PopulatePriorBoxParameter(const mindspore::lite::PrimitiveC *primit
return nullptr;
}
prior_box_param->aspect_ratios_size = prior_box_attr->GetAspectRatios().size();
(void)memcpy(prior_box_param->aspect_ratios, prior_box_attr->GetAspectRatios().data(),
memcpy(prior_box_param->aspect_ratios, prior_box_attr->GetAspectRatios().data(),
prior_box_attr->GetAspectRatios().size() * sizeof(float));
if (prior_box_attr->GetVariances().size() != PRIOR_BOX_VAR_NUM) {
MS_LOG(ERROR) << "PriorBox variances size should be " << PRIOR_BOX_VAR_NUM << ", got "
......@@ -1425,7 +1437,7 @@ OpParameter *PopulatePriorBoxParameter(const mindspore::lite::PrimitiveC *primit
free(prior_box_param);
return nullptr;
}
(void)memcpy(prior_box_param->variances, prior_box_attr->GetVariances().data(), PRIOR_BOX_VAR_NUM * sizeof(float));
memcpy(prior_box_param->variances, prior_box_attr->GetVariances().data(), PRIOR_BOX_VAR_NUM * sizeof(float));
prior_box_param->flip = prior_box_attr->GetFlip();
prior_box_param->clip = prior_box_attr->GetClip();
prior_box_param->offset = prior_box_attr->GetOffset();
......@@ -1501,6 +1513,7 @@ OpParameter *PopulateEluParameter(const mindspore::lite::PrimitiveC *primitive)
}
PopulateParameterRegistry::PopulateParameterRegistry() {
populate_parameter_funcs_[schema::PrimitiveType_SparseToDense] = PopulateSparseToDenseParameter;
populate_parameter_funcs_[schema::PrimitiveType_SoftMax] = PopulateSoftmaxParameter;
populate_parameter_funcs_[schema::PrimitiveType_Activation] = PopulateActivationParameter;
populate_parameter_funcs_[schema::PrimitiveType_Conv2D] = PopulateConvParameter;
......@@ -1578,7 +1591,7 @@ PopulateParameterRegistry::PopulateParameterRegistry() {
populate_parameter_funcs_[schema::PrimitiveType_BatchToSpace] = PopulateBatchToSpaceParameter;
populate_parameter_funcs_[schema::PrimitiveType_SpaceToDepth] = PopulateSpaceToDepthParameter;
populate_parameter_funcs_[schema::PrimitiveType_SpaceToBatch] = PopulateSpaceToBatchParameter;
populate_parameter_funcs_[schema::PrimitiveType_SpaceToBatchND] = PopulateSpaceToBatchParameterND;
populate_parameter_funcs_[schema::PrimitiveType_SpaceToBatchND] = PopulateSpaceToBatchNDParameter;
populate_parameter_funcs_[schema::PrimitiveType_Crop] = PopulateCropParameter;
populate_parameter_funcs_[schema::PrimitiveType_Unsqueeze] = PopulateUnsqueezeParameter;
populate_parameter_funcs_[schema::PrimitiveType_Flatten] = PopulateFlattenParameter;
......
......@@ -28,4 +28,5 @@ add_library(caffe_parser_mid OBJECT
${CMAKE_CURRENT_SOURCE_DIR}/caffe_interp_parser.cc
${CMAKE_CURRENT_SOURCE_DIR}/caffe_permute_parser.cc
${CMAKE_CURRENT_SOURCE_DIR}/caffe_tile_parser.cc
${CMAKE_CURRENT_SOURCE_DIR}/caffe_tanh_parser.cc)
${CMAKE_CURRENT_SOURCE_DIR}/caffe_tanh_parser.cc
${CMAKE_CURRENT_SOURCE_DIR}/caffe_exp_parser.cc)
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "mindspore/lite/tools/converter/parser/caffe/caffe_argmax_parser.h"
#include "tools/converter/parser/caffe/caffe_argmax_parser.h"
#include <memory>
namespace mindspore {
......
......@@ -18,8 +18,8 @@
#define MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_CAFFE_CAFFE_ARGMAX_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"
#include "tools/converter/parser/caffe/caffe_node_parser.h"
#include "tools/converter/parser/caffe/caffe_node_parser_registry.h"
namespace mindspore {
namespace lite {
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "mindspore/lite/tools/converter/parser/caffe/caffe_batchnorm_parser.h"
#include "tools/converter/parser/caffe/caffe_batchnorm_parser.h"
#include <cmath>
#include <memory>
#include "tools/common/tensor_util.h"
......
......@@ -18,8 +18,8 @@
#define MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_CAFFE_CAFFE_BATCHNORM_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"
#include "tools/converter/parser/caffe/caffe_node_parser.h"
#include "tools/converter/parser/caffe/caffe_node_parser_registry.h"
namespace mindspore {
namespace lite {
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "mindspore/lite/tools/converter/parser/caffe/caffe_concat_parser.h"
#include "tools/converter/parser/caffe/caffe_concat_parser.h"
#include <memory>
const int32_t CONCAT_DEFAULT_AXIS = 1;
......
......@@ -18,8 +18,8 @@
#define MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_CAFFE_CAFFE_CONCAT_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"
#include "tools/converter/parser/caffe/caffe_node_parser.h"
#include "tools/converter/parser/caffe/caffe_node_parser_registry.h"
namespace mindspore {
namespace lite {
......
......@@ -19,8 +19,8 @@
#include <string>
#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"
#include "tools/converter/parser/caffe/caffe_node_parser.h"
#include "tools/converter/parser/caffe/caffe_node_parser_registry.h"
namespace mindspore {
namespace lite {
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "mindspore/lite/tools/converter/parser/caffe/caffe_converter.h"
#include "tools/converter/parser/caffe/caffe_converter.h"
namespace mindspore {
namespace lite {
......
......@@ -19,9 +19,9 @@
#include <string>
#include <memory>
#include "mindspore/lite/tools/converter/converter.h"
#include "mindspore/lite/tools/converter/parser/caffe/caffe_model_parser.h"
#include "mindspore/lite/tools/converter/graphdef_transform.h"
#include "tools/converter/converter.h"
#include "tools/converter/parser/caffe/caffe_model_parser.h"
#include "tools/converter/graphdef_transform.h"
namespace mindspore::lite {
class CaffeConverter : public Converter {
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "mindspore/lite/tools/converter/parser/caffe/caffe_convolution_parser.h"
#include "tools/converter/parser/caffe/caffe_convolution_parser.h"
#include <memory>
namespace mindspore {
......
......@@ -18,9 +18,9 @@
#define MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_CAFFE_CAFFE_CONVOLUTION_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"
#include "mindspore/lite/tools/converter/parser/caffe/caffe_conv_base_parser.h"
#include "tools/converter/parser/caffe/caffe_node_parser.h"
#include "tools/converter/parser/caffe/caffe_node_parser_registry.h"
#include "tools/converter/parser/caffe/caffe_conv_base_parser.h"
namespace mindspore {
namespace lite {
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "mindspore/lite/tools/converter/parser/caffe/caffe_crop_parser.h"
#include "tools/converter/parser/caffe/caffe_crop_parser.h"
#include <memory>
const int32_t CROP_AXIS = 2;
......
......@@ -18,8 +18,8 @@
#define MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_CAFFE_CAFFE_CROP_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"
#include "tools/converter/parser/caffe/caffe_node_parser.h"
#include "tools/converter/parser/caffe/caffe_node_parser_registry.h"
namespace mindspore {
namespace lite {
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "mindspore/lite/tools/converter/parser/caffe/caffe_deconvolution_parser.h"
#include "tools/converter/parser/caffe/caffe_deconvolution_parser.h"
#include <memory>
namespace mindspore {
......
......@@ -18,9 +18,9 @@
#define MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_CAFFE_CAFFE_DECONVOLUTION_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"
#include "mindspore/lite/tools/converter/parser/caffe/caffe_conv_base_parser.h"
#include "tools/converter/parser/caffe/caffe_node_parser.h"
#include "tools/converter/parser/caffe/caffe_node_parser_registry.h"
#include "tools/converter/parser/caffe/caffe_conv_base_parser.h"
namespace mindspore {
namespace lite {
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "mindspore/lite/tools/converter/parser/caffe/caffe_eltwise_parser.h"
#include "tools/converter/parser/caffe/caffe_eltwise_parser.h"
#include <cmath>
#include <memory>
......
......@@ -18,8 +18,8 @@
#define MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_CAFFE_CAFFE_ELTWISE_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"
#include "tools/converter/parser/caffe/caffe_node_parser.h"
#include "tools/converter/parser/caffe/caffe_node_parser_registry.h"
namespace mindspore {
namespace lite {
......
/**
* 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 "tools/converter/parser/caffe/caffe_exp_parser.h"
#include <memory>
#include <vector>
namespace mindspore {
namespace lite {
STATUS CaffeExpParser::Parse(const caffe::LayerParameter &proto,
const caffe::LayerParameter &weight,
schema::CNodeT *op,
std::vector<schema::TensorT *> *weightVec) {
MS_LOG(DEBUG) << "parse ExpParser";
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::ExpT> attr = std::make_unique<schema::ExpT>();
if (attr == nullptr) {
MS_LOG(ERROR) << "new op failed";
return RET_NULL_PTR;
}
const caffe::ExpParameter exp_param = proto.exp_param();
if (exp_param.has_base()) {
attr->base = exp_param.base();
} else {
attr->base = -1; // -1 represent base = e
}
if (exp_param.has_scale()) {
attr->scale = exp_param.scale();
} else {
attr->scale = 1;
}
if (exp_param.has_shift()) {
attr->shift = exp_param.shift();
} else {
attr->shift = 0;
}
op->primitive->value.type = schema::PrimitiveType_Exp;
op->primitive->value.value = attr.release();
return RET_OK;
}
CaffeNodeRegistrar g_caffeExpParser("Exp", new CaffeExpParser());
} // namespace lite
} // namespace mindspore
/**
* 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_LITE_TOOLS_CONVERTER_PARSER_CAFFE_CAFFE_EXP_PARSER_H
#define MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_CAFFE_CAFFE_EXP_PARSER_H
#include <vector>
#include "tools/converter/parser/caffe/caffe_node_parser.h"
#include "tools/converter/parser/caffe/caffe_node_parser_registry.h"
namespace mindspore {
namespace lite {
class CaffeExpParser : public CaffeNodeParser {
public:
CaffeExpParser() : CaffeNodeParser("exp") {}
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_LITE_TOOLS_CONVERTER_PARSER_CAFFE_CAFFE_EXP_PARSER_H
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "mindspore/lite/tools/converter/parser/caffe/caffe_flatten_parser.h"
#include "tools/converter/parser/caffe/caffe_flatten_parser.h"
#include <memory>
namespace mindspore {
......
......@@ -18,8 +18,8 @@
#define MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_CAFFE_CAFFE_FLATTEN_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"
#include "tools/converter/parser/caffe/caffe_node_parser.h"
#include "tools/converter/parser/caffe/caffe_node_parser_registry.h"
namespace mindspore {
namespace lite {
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "mindspore/lite/tools/converter/parser/caffe/caffe_innerproduct_parser.h"
#include "tools/converter/parser/caffe/caffe_innerproduct_parser.h"
#include <memory>
namespace mindspore {
......
......@@ -18,8 +18,8 @@
#define MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_CAFFE_CAFFE_INNERPRODUCT_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"
#include "tools/converter/parser/caffe/caffe_node_parser.h"
#include "tools/converter/parser/caffe/caffe_node_parser_registry.h"
namespace mindspore {
namespace lite {
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "mindspore/lite/tools/converter/parser/caffe/caffe_inspector.h"
#include "tools/converter/parser/caffe/caffe_inspector.h"
#include "utils/log_adapter.h"
namespace mindspore {
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "mindspore/lite/tools/converter/parser/caffe/caffe_interp_parser.h"
#include "tools/converter/parser/caffe/caffe_interp_parser.h"
#include <memory>
namespace mindspore {
......
......@@ -18,8 +18,8 @@
#define MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_CAFFE_CAFFE_INTERP_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"
#include "tools/converter/parser/caffe/caffe_node_parser.h"
#include "tools/converter/parser/caffe/caffe_node_parser_registry.h"
namespace mindspore {
namespace lite {
......
......@@ -91,7 +91,12 @@ schema::MetaGraphT *CaffeModelParser::ParseToFb(const std::string &modelFile, co
STATUS CaffeModelParser::SetOpInputIdx(const caffe::LayerParameter &layer, schema::CNodeT *op,
TensorCache *tensorCache) {
for (int i = 0; i < layer.bottom_size(); i++) {
int index = tensorCache->FindTensor(layer.bottom(i));
int index = -1;
if (splitLayer.find(layer.bottom(i)) != splitLayer.end()) {
index = tensorCache->FindTensor(splitLayer.find(layer.bottom(i))->second);
} else {
index = tensorCache->FindTensor(layer.bottom(i));
}
if (index >= 0) {
op->inputIndex.emplace_back(index);
} else {
......@@ -193,6 +198,10 @@ STATUS CaffeModelParser::ParseLayer(const caffe::NetParameter &proto, const caff
std::unique_ptr<schema::CNodeT> op = std::make_unique<schema::CNodeT>();
op->name = layer.name();
if (layer.type() == "Split") {
splitLayer.emplace(layer.name(), layer.bottom(0));
continue;
}
auto status = SetOpInputIdx(layer, op.get(), tensorCache);
if (status != RET_OK) {
MS_LOG(ERROR) << "Set Op " << layer.name() << " Input Index Failed!";
......
......@@ -21,7 +21,8 @@
#include <vector>
#include <memory>
#include <set>
#include "mindspore/lite/tools/converter/model_parser.h"
#include <unordered_map>
#include "tools/converter/model_parser.h"
#include "tools/converter/parser/caffe/caffe.pb.h"
#include "tools/common/tensor_util.h"
......@@ -55,6 +56,8 @@ class CaffeModelParser : public ModelParser {
STATUS GetModelInput(const caffe::NetParameter &proto, TensorCache *tensorCache);
static const std::set<std::string> skipedLayerType;
std::unordered_map<std::string, std::string> splitLayer;
};
} // namespace lite
} // namespace mindspore
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "mindspore/lite/tools/converter/parser/caffe/caffe_node_parser.h"
#include "tools/converter/parser/caffe/caffe_node_parser.h"
#include <memory>
#include "securec/include/securec.h"
#include "ir/dtype/type_id.h"
......
......@@ -20,9 +20,9 @@
#include <string>
#include <vector>
#include "google/protobuf/message.h"
#include "mindspore/lite/schema/inner/model_generated.h"
#include "schema/inner/model_generated.h"
#include "tools/converter/parser/caffe/caffe.pb.h"
#include "mindspore/lite/tools/converter/parser/caffe/caffe_node_parser.h"
#include "tools/converter/parser/caffe/caffe_node_parser.h"
#include "include/errorcode.h"
#include "utils/log_adapter.h"
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "mindspore/lite/tools/converter/parser/caffe/caffe_node_parser_registry.h"
#include "tools/converter/parser/caffe/caffe_node_parser_registry.h"
namespace mindspore {
namespace lite {
......
......@@ -19,7 +19,7 @@
#include <string>
#include <unordered_map>
#include "mindspore/lite/tools/converter/parser/caffe/caffe_node_parser.h"
#include "tools/converter/parser/caffe/caffe_node_parser.h"
#include "tools/converter/parser/caffe/caffe.pb.h"
namespace mindspore::lite {
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "mindspore/lite/tools/converter/parser/caffe/caffe_permute_parser.h"
#include "tools/converter/parser/caffe/caffe_permute_parser.h"
#include <memory>
namespace mindspore {
......
......@@ -18,8 +18,8 @@
#define MINDSPORE_LITE_TOOLS_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"
#include "tools/converter/parser/caffe/caffe_node_parser.h"
#include "tools/converter/parser/caffe/caffe_node_parser_registry.h"
namespace mindspore {
namespace lite {
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "mindspore/lite/tools/converter/parser/caffe/caffe_pooling_parser.h"
#include "tools/converter/parser/caffe/caffe_pooling_parser.h"
#include <memory>
const uint32_t INNERPRODUCT_WINDOW_DEFAULT_VALUE = 0;
......
......@@ -18,8 +18,8 @@
#define MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_CAFFE_CAFFE_POOLING_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"
#include "tools/converter/parser/caffe/caffe_node_parser.h"
#include "tools/converter/parser/caffe/caffe_node_parser_registry.h"
namespace mindspore {
namespace lite {
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "mindspore/lite/tools/converter/parser/caffe/caffe_power_parser.h"
#include "tools/converter/parser/caffe/caffe_power_parser.h"
#include <memory>
#include <vector>
......
......@@ -18,8 +18,8 @@
#define MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_CAFFE_CAFFE_POWER_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"
#include "tools/converter/parser/caffe/caffe_node_parser.h"
#include "tools/converter/parser/caffe/caffe_node_parser_registry.h"
namespace mindspore {
namespace lite {
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "mindspore/lite/tools/converter/parser/caffe/caffe_prelu_parser.h"
#include "tools/converter/parser/caffe/caffe_prelu_parser.h"
#include <memory>
namespace mindspore {
......
......@@ -18,8 +18,8 @@
#define MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_CAFFE_CAFFE_PRELU_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"
#include "tools/converter/parser/caffe/caffe_node_parser.h"
#include "tools/converter/parser/caffe/caffe_node_parser_registry.h"
namespace mindspore {
namespace lite {
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "mindspore/lite/tools/converter/parser/caffe/caffe_relu6_parser.h"
#include "tools/converter/parser/caffe/caffe_relu6_parser.h"
#include <memory>
namespace mindspore {
......
......@@ -17,8 +17,8 @@
#define MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_CAFFE_CAFFE_RELU6_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"
#include "tools/converter/parser/caffe/caffe_node_parser.h"
#include "tools/converter/parser/caffe/caffe_node_parser_registry.h"
namespace mindspore {
namespace lite {
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "mindspore/lite/tools/converter/parser/caffe/caffe_relu_parser.h"
#include "tools/converter/parser/caffe/caffe_relu_parser.h"
#include <memory>
namespace mindspore {
......
......@@ -18,8 +18,8 @@
#define MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_CAFFE_CAFFE_RELU_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"
#include "tools/converter/parser/caffe/caffe_node_parser.h"
#include "tools/converter/parser/caffe/caffe_node_parser_registry.h"
namespace mindspore {
namespace lite {
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "mindspore/lite/tools/converter/parser/caffe/caffe_reshape_parser.h"
#include "tools/converter/parser/caffe/caffe_reshape_parser.h"
#include <memory>
namespace mindspore {
......
......@@ -18,8 +18,8 @@
#define MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_CAFFE_CAFFE_RESHAPE_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"
#include "tools/converter/parser/caffe/caffe_node_parser.h"
#include "tools/converter/parser/caffe/caffe_node_parser_registry.h"
namespace mindspore {
namespace lite {
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "mindspore/lite/tools/converter/parser/caffe/caffe_scale_parser.h"
#include "tools/converter/parser/caffe/caffe_scale_parser.h"
#include <memory>
const int32_t NCHW_DIM_C = 1;
......
......@@ -18,8 +18,8 @@
#define MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_CAFFE_CAFFE_SCALE_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"
#include "tools/converter/parser/caffe/caffe_node_parser.h"
#include "tools/converter/parser/caffe/caffe_node_parser_registry.h"
namespace mindspore {
namespace lite {
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "mindspore/lite/tools/converter/parser/caffe/caffe_sigmoid_parser.h"
#include "tools/converter/parser/caffe/caffe_sigmoid_parser.h"
#include <memory>
namespace mindspore {
......
......@@ -18,8 +18,8 @@
#define MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_CAFFE_CAFFE_SIGMOID_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"
#include "tools/converter/parser/caffe/caffe_node_parser.h"
#include "tools/converter/parser/caffe/caffe_node_parser_registry.h"
namespace mindspore {
namespace lite {
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "mindspore/lite/tools/converter/parser/caffe/caffe_softmax_parser.h"
#include "tools/converter/parser/caffe/caffe_softmax_parser.h"
#include <memory>
static const int32_t CAFFE_SOFTMAX_DEFAULT_AXIS = 1;
......
......@@ -18,8 +18,8 @@
#define MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_CAFFE_CAFFE_SOFTMAX_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"
#include "tools/converter/parser/caffe/caffe_node_parser.h"
#include "tools/converter/parser/caffe/caffe_node_parser_registry.h"
namespace mindspore {
namespace lite {
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "mindspore/lite/tools/converter/parser/caffe/caffe_tile_parser.h"
#include "tools/converter/parser/caffe/caffe_tile_parser.h"
#include <memory>
#include <vector>
......
......@@ -18,8 +18,8 @@
#define MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_CAFFE_CAFFE_TILE_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"
#include "tools/converter/parser/caffe/caffe_node_parser.h"
#include "tools/converter/parser/caffe/caffe_node_parser_registry.h"
namespace mindspore {
namespace lite {
......
......@@ -212,6 +212,9 @@ STATUS TfliteSingleInputOpParser::Parse(const std::unique_ptr<tflite::OperatorT>
} else if (std::strcmp(node_name, "Exp") == 0) {
MS_LOG(DEBUG) << "parse TfliteExpParser";
auto attr = std::make_unique<schema::ExpT>();
attr->base = -1; // -1 represent base = e
attr->scale = 1;
attr->shift = 0;
if (attr == nullptr) {
MS_LOG(ERROR) << "new op failed";
return RET_NULL_PTR;
......
/**
* 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 "tools/converter/parser/tflite/tflite_custom_parser.h"
#include <vector>
#include <memory>
#include <map>
namespace mindspore {
namespace lite {
STATUS TfliteCustomParser::Parse(const std::unique_ptr<tflite::OperatorT> &tflite_op,
const std::vector<std::unique_ptr<tflite::TensorT>> &tflite_tensors,
const std::vector<std::unique_ptr<tflite::BufferT>> &tflite_model_buffer,
schema::CNodeT *op,
std::vector<int32_t> *tensors_id,
std::vector<schema::Format> *tensors_format,
std::map<int, int> *tensors_id_map) {
MS_LOG(DEBUG) << "parse TfliteCustomParser";
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::CustomT> attr = std::make_unique<schema::CustomT>();
if (attr == nullptr) {
MS_LOG(ERROR) << "new op failed";
return RET_NULL_PTR;
}
const auto &custom_attr = tflite_op->custom_options;
attr->custom = custom_attr;
op->primitive->value.type = schema::PrimitiveType_Custom;
op->primitive->value.value = attr.release();
for (size_t i = 0; i < tflite_op->inputs.size(); ++i) {
AddOpInput(op, tensors_id, tensors_format, tensors_id_map,
tflite_op->inputs[i], tensors_id->size(), tflite_tensors.size(), schema::Format_NHWC);
}
for (size_t i = 0; i < tflite_op->outputs.size(); ++i) {
AddOpOutput(op, tensors_id, tensors_format, tensors_id_map,
tflite_op->outputs[i], tensors_id->size(), tflite_tensors.size(), schema::Format_NHWC);
}
return RET_OK;
}
TfliteNodeRegister g_tfliteCustomParser("Custom", new TfliteCustomParser());
} // namespace lite
} // namespace mindspore
/**
* 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_LITE_TOOLS_CONVERTER_PARSER_TFLITE_CUSTOM_PARSER_H
#define MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_TFLITE_CUSTOM_PARSER_H
#include <memory>
#include <vector>
#include <map>
#include "tools/converter/parser/tflite/tflite_node_parser.h"
#include "tools/converter/parser/tflite/tflite_node_parser_registry.h"
namespace mindspore {
namespace lite {
class TfliteCustomParser : public TfliteNodeParser {
public:
TfliteCustomParser() : TfliteNodeParser("Custom") {}
STATUS Parse(const std::unique_ptr<tflite::OperatorT> &tflite_op,
const std::vector<std::unique_ptr<tflite::TensorT>> &tflite_tensors,
const std::vector<std::unique_ptr<tflite::BufferT>> &tflite_model_buffer,
schema::CNodeT *op,
std::vector<int32_t> *tensors_id,
std::vector<schema::Format> *tensors_format,
std::map<int, int> *tensors_id_map) override;
};
} // namespace lite
} // namespace mindspore
#endif // MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_TFLITE_CUSTOM_PARSER_H
......@@ -66,6 +66,12 @@ STATUS TfliteSparseToDenseParser::Parse(const std::unique_ptr<tflite::OperatorT>
AddOpInput(op, tensors_id, tensors_format, tensors_id_map,
tflite_op->inputs[0], tensors_id->size(), tflite_tensors.size(), schema::Format_NHWC);
AddOpInput(op, tensors_id, tensors_format, tensors_id_map,
tflite_op->inputs[1], tensors_id->size(), tflite_tensors.size(), schema::Format_NHWC);
AddOpInput(op, tensors_id, tensors_format, tensors_id_map,
tflite_op->inputs[2], tensors_id->size(), tflite_tensors.size(), schema::Format_NHWC);
AddOpInput(op, tensors_id, tensors_format, tensors_id_map,
tflite_op->inputs[3], tensors_id->size(), tflite_tensors.size(), schema::Format_NHWC);
AddOpOutput(op, tensors_id, tensors_format, tensors_id_map,
tflite_op->outputs[0], tensors_id->size(), tflite_tensors.size(), schema::Format_NHWC);
return RET_OK;
......
......@@ -116,6 +116,7 @@ std::map<tflite::BuiltinOperator, std::string> tfMsOpTypeMap{
{tflite::BuiltinOperator_REVERSE_SEQUENCE, "ReverseSequence"},
{tflite::BuiltinOperator_UNIQUE, "Unique"},
{tflite::BuiltinOperator_UNPACK, "Unstack"},
{tflite::BuiltinOperator_CUSTOM, "Custom"},
};
std::map<tflite::ActivationFunctionType, schema::ActivationType> tfMsActivationFunctionMap{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册