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

!4640 fix fullyconnected tflite parser bug

Merge pull request !4640 from lyvette/parser
......@@ -27,6 +27,7 @@ class TestTfliteParserL2Norm : public TestTfliteParser {
TEST_F(TestTfliteParserL2Norm, OpType) {
ASSERT_NE(meta_graph, nullptr);
ASSERT_GT(meta_graph->nodes.size(), 0);
ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr);
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_L2Norm) << "wrong Op Type";
}
......
......@@ -38,7 +38,7 @@ STATUS TfliteActivationParser::Parse(const std::unique_ptr<tflite::OperatorT> &t
MS_LOG(ERROR) << "op->primitive is null";
return RET_NULL_PTR;
}
std::unique_ptr<schema::ActivationT> attr(new schema::ActivationT());
std::unique_ptr<schema::ActivationT> attr = std::make_unique<schema::ActivationT>();
std::vector<std::string> node_name_str;
Split(op->name, &node_name_str, "-");
......@@ -89,7 +89,7 @@ STATUS TflitePreluParser::Parse(const std::unique_ptr<tflite::OperatorT> &tflite
MS_LOG(ERROR) << "op->primitive is null";
return RET_NULL_PTR;
}
std::unique_ptr<schema::PreluT> attr(new schema::PreluT());
std::unique_ptr<schema::PreluT> attr = std::make_unique<schema::PreluT>();
if (GetTfliteData(tflite_op->inputs[1], tflite_tensors, tflite_model_buffer, attr->slope)) {
MS_LOG(ERROR) << "get pRelu -> slope failed";
......@@ -124,7 +124,7 @@ STATUS TfliteLeakyReluParser::Parse(const std::unique_ptr<tflite::OperatorT> &tf
return RET_NULL_PTR;
}
std::unique_ptr<schema::LeakyReLUT> attr(new schema::LeakyReLUT());
std::unique_ptr<schema::LeakyReLUT> attr = std::make_unique<schema::LeakyReLUT>();
const auto &tflite_attr = tflite_op->builtin_options.AsLeakyReluOptions();
if (tflite_attr == nullptr) {
......
......@@ -42,7 +42,7 @@ STATUS TfliteAddNParser::Parse(const std::unique_ptr<tflite::OperatorT> &tflite_
return RET_NULL_PTR;
}
std::unique_ptr<schema::AddNT> attr(new schema::AddNT());
std::unique_ptr<schema::AddNT> attr = std::make_unique<schema::AddNT>();
attr->N = tflite_tensors.size() - 1;
op->primitive->value.type = schema::PrimitiveType_AddN;
......
......@@ -40,7 +40,7 @@ STATUS TfliteArgmaxParser::Parse(const std::unique_ptr<tflite::OperatorT> &tflit
return RET_NULL_PTR;
}
std::unique_ptr<schema::ArgMaxT> attr(new schema::ArgMaxT());
std::unique_ptr<schema::ArgMaxT> attr = std::make_unique<schema::ArgMaxT>();
attr->outMaxValue = false;
attr->topK = 1;
......
......@@ -40,7 +40,7 @@ STATUS TfliteArgminParser::Parse(const std::unique_ptr<tflite::OperatorT> &tflit
return RET_NULL_PTR;
}
std::unique_ptr<schema::ArgMinT> attr(new schema::ArgMinT());
std::unique_ptr<schema::ArgMinT> attr = std::make_unique<schema::ArgMinT>();
attr->outMaxValue = false;
attr->topK = 1;
......
......@@ -44,7 +44,7 @@ STATUS TfliteDoubleInputOpParser::Parse(const std::unique_ptr<tflite::OperatorT>
const char *node_name = node_name_str.data()->c_str();
if (std::strcmp(node_name, "Add") == 0) {
MS_LOG(DEBUG) << "parse TfliteAddParser";
std::unique_ptr<schema::AddT> attr(new schema::AddT());
std::unique_ptr<schema::AddT> attr = std::make_unique<schema::AddT>();
const auto &tfliteAttr = tflite_op->builtin_options.AsAddOptions();
if (nullptr == tfliteAttr) {
MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed";
......@@ -55,7 +55,7 @@ STATUS TfliteDoubleInputOpParser::Parse(const std::unique_ptr<tflite::OperatorT>
op->primitive->value.value = attr.release();
} else if (std::strcmp(node_name, "Sub") == 0) {
MS_LOG(DEBUG) << "parse TfliteSubParser";
std::unique_ptr<schema::SubT> attr(new schema::SubT());
std::unique_ptr<schema::SubT> attr = std::make_unique<schema::SubT>();
const auto &tfliteAttr = tflite_op->builtin_options.AsSubOptions();
if (nullptr == tfliteAttr) {
MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed";
......@@ -66,7 +66,7 @@ STATUS TfliteDoubleInputOpParser::Parse(const std::unique_ptr<tflite::OperatorT>
op->primitive->value.value = attr.release();
} else if (std::strcmp(node_name, "Mul") == 0) {
MS_LOG(DEBUG) << "parse TfliteMulParser";
std::unique_ptr<schema::MulT> attr(new schema::MulT());
std::unique_ptr<schema::MulT> attr = std::make_unique<schema::MulT>();
const auto &tfliteAttr = tflite_op->builtin_options.AsMulOptions();
if (nullptr == tfliteAttr) {
MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed";
......@@ -77,7 +77,7 @@ STATUS TfliteDoubleInputOpParser::Parse(const std::unique_ptr<tflite::OperatorT>
op->primitive->value.value = attr.release();
} else if (std::strcmp(node_name, "Div") == 0) {
MS_LOG(DEBUG) << "parse TfliteDivParser";
std::unique_ptr<schema::DivT> attr(new schema::DivT());
std::unique_ptr<schema::DivT> attr = std::make_unique<schema::DivT>();
const auto &tfliteAttr = tflite_op->builtin_options.AsDivOptions();
if (nullptr == tfliteAttr) {
MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed";
......@@ -88,27 +88,27 @@ STATUS TfliteDoubleInputOpParser::Parse(const std::unique_ptr<tflite::OperatorT>
op->primitive->value.value = attr.release();
} else if (std::strcmp(node_name, "FloorDiv") == 0) {
MS_LOG(DEBUG) << "parse TfliteFloorDivParser";
std::unique_ptr<schema::FloorDivT> attr(new schema::FloorDivT());
std::unique_ptr<schema::FloorDivT> attr = std::make_unique<schema::FloorDivT>();
op->primitive->value.type = schema::PrimitiveType_FloorDiv;
op->primitive->value.value = attr.release();
} else if (std::strcmp(node_name, "FloorMod") == 0) {
MS_LOG(DEBUG) << "parse TfliteFloorModParser";
std::unique_ptr<schema::FloorModT> attr(new schema::FloorModT());
std::unique_ptr<schema::FloorModT> attr = std::make_unique<schema::FloorModT>();
op->primitive->value.type = schema::PrimitiveType_FloorMod;
op->primitive->value.value = attr.release();
} else if (std::strcmp(node_name, "RealDiv") == 0) {
MS_LOG(DEBUG) << "parse TfliteRealDivParser";
std::unique_ptr<schema::RealDivT> attr(new schema::RealDivT());
std::unique_ptr<schema::RealDivT> attr = std::make_unique<schema::RealDivT>();
op->primitive->value.type = schema::PrimitiveType_Div;
op->primitive->value.value = attr.release();
} else if (std::strcmp(node_name, "SquaredDifference") == 0) {
MS_LOG(DEBUG) << "parse TfliteSquaredDifferenceParser";
std::unique_ptr<schema::SquaredDifferenceT> attr(new schema::SquaredDifferenceT());
std::unique_ptr<schema::SquaredDifferenceT> attr = std::make_unique<schema::SquaredDifferenceT>();
op->primitive->value.type = schema::PrimitiveType_SquaredDifference;
op->primitive->value.value = attr.release();
} else if (std::strcmp(node_name, "Pow") == 0) {
MS_LOG(DEBUG) << "parse TflitePowParser";
std::unique_ptr<schema::PowerT> attr(new schema::PowerT());
std::unique_ptr<schema::PowerT> attr = std::make_unique<schema::PowerT>();
attr->power = 0.0f;
attr->scale = 1.0f;
attr->shift = 0.0f;
......@@ -116,12 +116,12 @@ STATUS TfliteDoubleInputOpParser::Parse(const std::unique_ptr<tflite::OperatorT>
op->primitive->value.value = attr.release();
} else if (std::strcmp(node_name, "Maximum") == 0) {
MS_LOG(DEBUG) << "parse TfliteMaximumParser";
std::unique_ptr<schema::MaximumT> attr(new schema::MaximumT());
std::unique_ptr<schema::MaximumT> attr = std::make_unique<schema::MaximumT>();
op->primitive->value.type = schema::PrimitiveType_Maximum;
op->primitive->value.value = attr.release();
} else if (std::strcmp(node_name, "Minimum") == 0) {
MS_LOG(DEBUG) << "parse TfliteMinimumParser";
std::unique_ptr<schema::MinimumT> attr(new schema::MinimumT());
std::unique_ptr<schema::MinimumT> attr = std::make_unique<schema::MinimumT>();
op->primitive->value.type = schema::PrimitiveType_Minimum;
op->primitive->value.value = attr.release();
}
......@@ -158,57 +158,57 @@ STATUS TfliteSingleInputOpParser::Parse(const std::unique_ptr<tflite::OperatorT>
const char *node_name = node_name_str.data()->c_str();
if (std::strcmp(node_name, "Abs") == 0) {
MS_LOG(DEBUG) << "parse TfliteAbsParser";
std::unique_ptr<schema::AbsT> attr(new schema::AbsT());
std::unique_ptr<schema::AbsT> attr = std::make_unique<schema::AbsT>();
op->primitive->value.type = schema::PrimitiveType_Abs;
op->primitive->value.value = attr.release();
} else if (std::strcmp(node_name, "Exp") == 0) {
MS_LOG(DEBUG) << "parse TfliteExpParser";
std::unique_ptr<schema::ExpT> attr(new schema::ExpT());
std::unique_ptr<schema::ExpT> attr = std::make_unique<schema::ExpT>();
op->primitive->value.type = schema::PrimitiveType_Exp;
op->primitive->value.value = attr.release();
} else if (std::strcmp(node_name, "Sqrt") == 0) {
MS_LOG(DEBUG) << "parse TfliteSqrtParser";
std::unique_ptr<schema::SqrtT> attr(new schema::SqrtT());
std::unique_ptr<schema::SqrtT> attr = std::make_unique<schema::SqrtT>();
op->primitive->value.type = schema::PrimitiveType_Sqrt;
op->primitive->value.value = attr.release();
} else if (std::strcmp(node_name, "Rsqrt") == 0) {
MS_LOG(DEBUG) << "parse TfliteRsqrtParser";
std::unique_ptr<schema::RsqrtT> attr(new schema::RsqrtT());
std::unique_ptr<schema::RsqrtT> attr = std::make_unique<schema::RsqrtT>();
op->primitive->value.type = schema::PrimitiveType_Rsqrt;
op->primitive->value.value = attr.release();
} else if (std::strcmp(node_name, "Square") == 0) {
MS_LOG(DEBUG) << "parse TfliteSquareParser";
std::unique_ptr<schema::SquareT> attr(new schema::SquareT());
std::unique_ptr<schema::SquareT> attr = std::make_unique<schema::SquareT>();
op->primitive->value.type = schema::PrimitiveType_Square;
op->primitive->value.value = attr.release();
} else if (std::strcmp(node_name, "Sin") == 0) {
MS_LOG(DEBUG) << "parse TfliteSinParser";
std::unique_ptr<schema::SinT> attr(new schema::SinT());
std::unique_ptr<schema::SinT> attr = std::make_unique<schema::SinT>();
op->primitive->value.type = schema::PrimitiveType_Sin;
op->primitive->value.value = attr.release();
} else if (std::strcmp(node_name, "Cos") == 0) {
MS_LOG(DEBUG) << "parse TfliteCosParser";
std::unique_ptr<schema::CosT> attr(new schema::CosT());
std::unique_ptr<schema::CosT> attr = std::make_unique<schema::CosT>();
op->primitive->value.type = schema::PrimitiveType_Cos;
op->primitive->value.value = attr.release();
} else if (std::strcmp(node_name, "Log") == 0) {
MS_LOG(DEBUG) << "parse TfliteLogParser";
std::unique_ptr<schema::LogT> attr(new schema::LogT());
std::unique_ptr<schema::LogT> attr = std::make_unique<schema::LogT>();
op->primitive->value.type = schema::PrimitiveType_Log;
op->primitive->value.value = attr.release();
} else if (std::strcmp(node_name, "Round") == 0) {
MS_LOG(DEBUG) << "parse TfliteRoundParser";
std::unique_ptr<schema::RoundT> attr(new schema::RoundT());
std::unique_ptr<schema::RoundT> attr = std::make_unique<schema::RoundT>();
op->primitive->value.type = schema::PrimitiveType_Round;
op->primitive->value.value = attr.release();
} else if (std::strcmp(node_name, "Ceil") == 0) {
MS_LOG(DEBUG) << "parse TfliteCeilParser";
std::unique_ptr<schema::CeilT> attr(new schema::CeilT());
std::unique_ptr<schema::CeilT> attr = std::make_unique<schema::CeilT>();
op->primitive->value.type = schema::PrimitiveType_Ceil;
op->primitive->value.value = attr.release();
} else if (std::strcmp(node_name, "flOOR") == 0) {
MS_LOG(DEBUG) << "parse TfliteFloorParser";
std::unique_ptr<schema::FloorT> attr(new schema::FloorT());
std::unique_ptr<schema::FloorT> attr = std::make_unique<schema::FloorT>();
op->primitive->value.type = schema::PrimitiveType_Floor;
op->primitive->value.value = attr.release();
}
......@@ -242,32 +242,32 @@ STATUS TfliteCompareOpParser::Parse(const std::unique_ptr<tflite::OperatorT> &tf
const char *node_name = node_name_str.data()->c_str();
if (std::strcmp(node_name, "Equal") == 0) {
MS_LOG(DEBUG) << "parse TfliteEqualParser";
std::unique_ptr<schema::EqualT> attr(new schema::EqualT());
std::unique_ptr<schema::EqualT> attr = std::make_unique<schema::EqualT>();
op->primitive->value.type = schema::PrimitiveType_Equal;
op->primitive->value.value = attr.release();
} else if (std::strcmp(node_name, "NotEqual") == 0) {
MS_LOG(DEBUG) << "parse TfliteNotEqualParser";
std::unique_ptr<schema::NotEqualT> attr(new schema::NotEqualT());
std::unique_ptr<schema::NotEqualT> attr = std::make_unique<schema::NotEqualT>();
op->primitive->value.type = schema::PrimitiveType_NotEqual;
op->primitive->value.value = attr.release();
} else if (std::strcmp(node_name, "Greater") == 0) {
MS_LOG(DEBUG) << "parse TfliteGreaterParser";
std::unique_ptr<schema::GreaterT> attr(new schema::GreaterT());
std::unique_ptr<schema::GreaterT> attr = std::make_unique<schema::GreaterT>();
op->primitive->value.type = schema::PrimitiveType_Greater;
op->primitive->value.value = attr.release();
} else if (std::strcmp(node_name, "GreaterEqual") == 0) {
MS_LOG(DEBUG) << "parse TfliteGreaterEqualParser";
std::unique_ptr<schema::GreaterEqualT> attr(new schema::GreaterEqualT());
std::unique_ptr<schema::GreaterEqualT> attr = std::make_unique<schema::GreaterEqualT>();
op->primitive->value.type = schema::PrimitiveType_GreaterEqual;
op->primitive->value.value = attr.release();
} else if (std::strcmp(node_name, "Less") == 0) {
MS_LOG(DEBUG) << "parse TfliteLessParser";
std::unique_ptr<schema::LessT> attr(new schema::LessT());
std::unique_ptr<schema::LessT> attr = std::make_unique<schema::LessT>();
op->primitive->value.type = schema::PrimitiveType_Less;
op->primitive->value.value = attr.release();
} else if (std::strcmp(node_name, "LessEqual") == 0) {
MS_LOG(DEBUG) << "parse TfliteLessEqualParser";
std::unique_ptr<schema::LessEqualT> attr(new schema::LessEqualT());
std::unique_ptr<schema::LessEqualT> attr = std::make_unique<schema::LessEqualT>();
op->primitive->value.type = schema::PrimitiveType_LessEqual;
op->primitive->value.value = attr.release();
}
......
......@@ -49,7 +49,7 @@ STATUS TfliteBatchToSpaceParser::Parse(const std::unique_ptr<tflite::OperatorT>
MS_LOG(DEBUG) << "parse TfliteBatchToSpaceNDParser";
}
std::unique_ptr<schema::BatchToSpaceT> attr(new schema::BatchToSpaceT());
std::unique_ptr<schema::BatchToSpaceT> attr = std::make_unique<schema::BatchToSpaceT>();
if (GetTfliteData(tflite_op->inputs[1], tflite_tensors, tflite_model_buffer, attr->blockShape)) {
MS_LOG(ERROR) << "get batchToSpace -> blockShape failed";
......
......@@ -41,7 +41,7 @@ STATUS TfliteBroadcastToParser::Parse(const std::unique_ptr<tflite::OperatorT> &
return RET_NULL_PTR;
}
std::unique_ptr<schema::BroadcastToT> attr(new schema::BroadcastToT());
std::unique_ptr<schema::BroadcastToT> attr = std::make_unique<schema::BroadcastToT>();
if (GetTfliteData(tflite_op->inputs[1], tflite_tensors, tflite_model_buffer, attr->dst_shape)) {
MS_LOG(ERROR) << "get broadCastTo -> dst_shape failed";
......
......@@ -40,7 +40,7 @@ STATUS TfliteCastParser::Parse(const std::unique_ptr<tflite::OperatorT> &tflite_
return RET_NULL_PTR;
}
std::unique_ptr<schema::CastT> attr(new schema::CastT());
std::unique_ptr<schema::CastT> attr = std::make_unique<schema::CastT>();
const auto &in_tensor = tflite_tensors[tflite_op->inputs[0]];
if (in_tensor == nullptr) {
......
......@@ -41,7 +41,7 @@ STATUS TfliteConcatParser::Parse(const std::unique_ptr<tflite::OperatorT> &tflit
return RET_NULL_PTR;
}
std::unique_ptr<schema::ConcatT> attr(new schema::ConcatT());
std::unique_ptr<schema::ConcatT> attr = std::make_unique<schema::ConcatT>();
const auto &tfliteAttr = tflite_op->builtin_options.AsConcatenationOptions();
if (tfliteAttr == nullptr) {
......
......@@ -40,7 +40,7 @@ STATUS TfliteConvParser::Parse(const std::unique_ptr<tflite::OperatorT> &tflite_
return RET_NULL_PTR;
}
std::unique_ptr<schema::Conv2DT> attr(new schema::Conv2DT());
std::unique_ptr<schema::Conv2DT> attr = std::make_unique<schema::Conv2DT>();
const auto &tflite_attr = tflite_op->builtin_options.AsConv2DOptions();
if (tflite_attr == nullptr) {
MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed";
......
......@@ -40,7 +40,7 @@ STATUS TfliteDeConvParser::Parse(const std::unique_ptr<tflite::OperatorT> &tflit
return RET_NULL_PTR;
}
std::unique_ptr<schema::DeConv2DT> attr(new schema::DeConv2DT());
std::unique_ptr<schema::DeConv2DT> attr = std::make_unique<schema::DeConv2DT>();
const auto &tflite_attr = tflite_op->builtin_options.AsTransposeConvOptions();
if (tflite_attr == nullptr) {
MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed";
......
......@@ -41,7 +41,7 @@ STATUS TfliteDepthToSpaceParser::Parse(const std::unique_ptr<tflite::OperatorT>
return RET_NULL_PTR;
}
std::unique_ptr<schema::DepthToSpaceT> attr(new schema::DepthToSpaceT());
std::unique_ptr<schema::DepthToSpaceT> attr = std::make_unique<schema::DepthToSpaceT>();
const auto &tflite_attr = tflite_op->builtin_options.AsDepthToSpaceOptions();
if (tflite_attr == nullptr) {
......
......@@ -41,7 +41,7 @@ STATUS TfliteDepthwiseConv2DParser::Parse(const std::unique_ptr<tflite::Operator
return RET_NULL_PTR;
}
std::unique_ptr<schema::DepthwiseConv2DT> attr(new schema::DepthwiseConv2DT());
std::unique_ptr<schema::DepthwiseConv2DT> attr = std::make_unique<schema::DepthwiseConv2DT>();
const auto &tflite_attr = tflite_op->builtin_options.AsDepthwiseConv2DOptions();
if (tflite_attr == nullptr) {
MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed";
......
......@@ -40,7 +40,7 @@ STATUS TfliteDequantizeParser::Parse(const std::unique_ptr<tflite::OperatorT> &t
return RET_NULL_PTR;
}
std::unique_ptr<schema::CastT> attr(new schema::CastT);
std::unique_ptr<schema::CastT> attr = std::make_unique<schema::CastT>();
// get the dequantize input tensor
const auto &in_tensor = tflite_tensors[tflite_op->inputs[0]];
......
......@@ -28,6 +28,8 @@ STATUS TfliteExpandDimsParser::Parse(const std::unique_ptr<tflite::OperatorT> &t
std::vector<int32_t> *tensors_id,
std::vector<schema::Format> *tensors_format,
std::map<int, int> *tensors_id_map) {
MS_LOG(DEBUG) << "parse TfliteExpandDimsParser";
if (op == nullptr) {
MS_LOG(ERROR) << "op is null";
return RET_NULL_PTR;
......@@ -38,8 +40,7 @@ STATUS TfliteExpandDimsParser::Parse(const std::unique_ptr<tflite::OperatorT> &t
return RET_NULL_PTR;
}
MS_LOG(DEBUG) << "parse TfliteExpandDimsParser";
std::unique_ptr<schema::ExpandDimsT> attr(new schema::ExpandDimsT());
std::unique_ptr<schema::ExpandDimsT> attr = std::make_unique<schema::ExpandDimsT>();
const auto &tflite_attr = tflite_op->builtin_options.AsExpandDimsOptions();
if (tflite_attr == nullptr) {
......
......@@ -40,7 +40,7 @@ STATUS TfliteFillParser::Parse(const std::unique_ptr<tflite::OperatorT> &tflite_
return RET_NULL_PTR;
}
std::unique_ptr<schema::FillT> attr(new schema::FillT());
std::unique_ptr<schema::FillT> attr = std::make_unique<schema::FillT>();
if (tflite_op->inputs.size() > 1) {
if (GetTfliteData(tflite_op->inputs[1], tflite_tensors, tflite_model_buffer, attr->dims)) {
......
......@@ -47,7 +47,7 @@ STATUS TfliteFullyConnectedParser::Parse(const std::unique_ptr<tflite::OperatorT
} else if (std::strcmp(node_name, "FakeQuant") == 0) {
MS_LOG(DEBUG) << "parse TfliteFakeQuantParser";
}
std::unique_ptr<schema::FullConnectionT> attr(new schema::FullConnectionT());
std::unique_ptr<schema::FullConnectionT> attr = std::make_unique<schema::FullConnectionT>();
const auto &tflite_attr = tflite_op->builtin_options.AsFullyConnectedOptions();
if (tflite_attr == nullptr) {
......@@ -55,7 +55,9 @@ STATUS TfliteFullyConnectedParser::Parse(const std::unique_ptr<tflite::OperatorT
return RET_NULL_PTR;
}
attr->hasBias = true;
bool hasBias = tflite_op->inputs.size() > 2 && tflite_op->inputs[2] != -1;
attr->hasBias = hasBias;
attr->axis = 1;
attr->useAxis = false;
attr->activationType = GetActivationFunctionType(tflite_attr->fused_activation_function);
......@@ -67,8 +69,10 @@ STATUS TfliteFullyConnectedParser::Parse(const std::unique_ptr<tflite::OperatorT
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_KHWC);
AddOpInput(op, tensors_id, tensors_format, tensors_id_map,
tflite_op->inputs[2], tensors_id->size(), tflite_tensors.size(), schema::Format_NHWC);
if (hasBias) {
AddOpInput(op, tensors_id, tensors_format, tensors_id_map,
tflite_op->inputs[2], 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;
......
......@@ -40,7 +40,7 @@ STATUS TfliteGatherNdParser::Parse(const std::unique_ptr<tflite::OperatorT> &tfl
return RET_NULL_PTR;
}
std::unique_ptr<schema::GatherNdT> attr(new schema::GatherNdT());
std::unique_ptr<schema::GatherNdT> attr = std::make_unique<schema::GatherNdT>();
attr->batchDims = 0;
op->primitive->value.type = schema::PrimitiveType_GatherNd;
......
......@@ -41,7 +41,7 @@ STATUS TfliteGatherParser::Parse(const std::unique_ptr<tflite::OperatorT> &tflit
return RET_NULL_PTR;
}
std::unique_ptr<schema::GatherT> attr(new schema::GatherT());
std::unique_ptr<schema::GatherT> attr = std::make_unique<schema::GatherT>();
const auto &tflite_attr = tflite_op->builtin_options.AsGatherOptions();
if (tflite_attr == nullptr) {
......
......@@ -42,8 +42,16 @@ STATUS TfliteL2NormParser::Parse(const std::unique_ptr<tflite::OperatorT> &tflit
return RET_NULL_PTR;
}
std::unique_ptr<schema::L2NormT> attr(new schema::L2NormT());
std::unique_ptr<schema::L2NormT> attr = std::make_unique<schema::L2NormT>();
if (tflite_op->inputs.empty()) {
MS_LOG(ERROR) << "the input is null";
return RET_NULL_PTR;
}
auto data_index = tflite_op->inputs[0];
if (tflite_op->inputs.size() <= data_index) {
MS_LOG(ERROR) << "the size of input should be greater than " << data_index;
return RET_ERROR;
}
const auto &data_tensor = tflite_tensors[data_index];
if (data_tensor == nullptr) {
MS_LOG(ERROR) << "the input tensor is null";
......
......@@ -44,17 +44,17 @@ STATUS TfliteLogicalParser::Parse(const std::unique_ptr<tflite::OperatorT> &tfli
const char *node_name = node_name_str.data()->c_str();
if (std::strcmp(node_name, "LogicalAnd") == 0) {
MS_LOG(DEBUG) << "parse TfliteLogicalAndParser";
std::unique_ptr<schema::LogicalAndT> attr(new schema::LogicalAndT());
std::unique_ptr<schema::LogicalAndT> attr = std::make_unique<schema::LogicalAndT>();
op->primitive->value.type = schema::PrimitiveType_LogicalAnd;
op->primitive->value.value = attr.release();
} else if (std::strcmp(node_name, "LogicalNot") == 0) {
MS_LOG(DEBUG) << "parse TfliteLogicalNotParser";
std::unique_ptr<schema::LogicalNotT> attr(new schema::LogicalNotT());
std::unique_ptr<schema::LogicalNotT> attr = std::make_unique<schema::LogicalNotT>();
op->primitive->value.type = schema::PrimitiveType_LogicalNot;
op->primitive->value.value = attr.release();
} else if (std::strcmp(node_name, "LogicalOr") == 0) {
MS_LOG(DEBUG) << "parse TfliteLogicalOrParser";
std::unique_ptr<schema::LogicalOrT> attr(new schema::LogicalOrT());
std::unique_ptr<schema::LogicalOrT> attr = std::make_unique<schema::LogicalOrT>();
op->primitive->value.type = schema::PrimitiveType_LogicalOr;
op->primitive->value.value = attr.release();
}
......
......@@ -41,7 +41,7 @@ STATUS TfliteLRNParser::Parse(const std::unique_ptr<tflite::OperatorT> &tflite_o
return RET_NULL_PTR;
}
std::unique_ptr<schema::LocalResponseNormalizationT> attr(new schema::LocalResponseNormalizationT());
std::unique_ptr<schema::LocalResponseNormalizationT> attr = std::make_unique<schema::LocalResponseNormalizationT>();
const auto &tflite_attr = tflite_op->builtin_options.AsLocalResponseNormalizationOptions();
if (tflite_attr == nullptr) {
......
......@@ -43,7 +43,8 @@ std::unique_ptr<tflite::ModelT> TfliteModelParser::ReadTfliteModel(const char *m
}
STATUS TfliteModelParser::CopyConstTensorData(const std::vector<std::unique_ptr<tflite::BufferT>> &tflite_model_buffer,
const tflite::TensorT *tflite_tensor, schema::TensorT *tensor) {
const tflite::TensorT *tflite_tensor,
schema::TensorT *tensor) {
auto count = 1;
std::for_each(tflite_tensor->shape.begin(), tflite_tensor->shape.end(), [&](int32_t sha) { count *= sha; });
auto data_size = count * GetDataTypeSize(TypeId(tensor->dataType));
......@@ -91,7 +92,8 @@ void TfliteModelParser::SetTensorQuantParam(const std::unique_ptr<tflite::Tensor
STATUS TfliteModelParser::ConvertOp(const std::unique_ptr<tflite::ModelT> &tflite_model,
const std::unique_ptr<tflite::SubGraphT> &tflite_subgraph,
const QuantType &quant_type, schema::MetaGraphT *sub_graph) {
const QuantType &quant_type,
schema::MetaGraphT *sub_graph) {
int idx = 0;
for (const auto &tflite_op : tflite_subgraph->operators) {
auto tflite_op_type = (tflite_model->operator_codes[tflite_op->opcode_index])->builtin_code;
......@@ -293,7 +295,8 @@ STATUS TfliteModelParser::ConvertGroupDepthwiseOp(schema::MetaGraphT* sub_graph)
return RET_OK;
}
MetaGraphT *TfliteModelParser::Parse(const std::string &model_file, const std::string &weight_file,
MetaGraphT *TfliteModelParser::Parse(const std::string &model_file,
const std::string &weight_file,
const QuantType &quant_type) {
std::unique_ptr<schema::MetaGraphT> sub_graph(new schema::MetaGraphT);
sub_graph->name = "MS_model converted by TF-Lite";
......
......@@ -58,14 +58,14 @@ class TfliteModelParser : public ModelParser {
STATUS ConvertOp(const std::unique_ptr<tflite::ModelT> &tflite_model,
const std::unique_ptr<tflite::SubGraphT> &tflite_subgraph,
const QuantType &quant_type,
schema::MetaGraphT* sub_graph);
schema::MetaGraphT *sub_graph);
STATUS ConvertTensor(const std::unique_ptr<tflite::SubGraphT> &tflite_subgraph,
const std::vector<std::unique_ptr<tflite::BufferT>> &tflite_model_buffer,
schema::MetaGraphT* sub_graph);
schema::MetaGraphT *sub_graph);
STATUS GetGraphInfo(const std::unique_ptr<tflite::SubGraphT> &tflite_subgraph,
schema::MetaGraphT* sub_graph);
schema::MetaGraphT *sub_graph);
STATUS ConvertGroupDepthwiseOp(schema::MetaGraphT* sub_graph);
......
......@@ -40,7 +40,7 @@ STATUS TfliteOneHotParser::Parse(const std::unique_ptr<tflite::OperatorT> &tflit
return RET_NULL_PTR;
}
std::unique_ptr<schema::OneHotT> attr(new schema::OneHotT());
std::unique_ptr<schema::OneHotT> attr = std::make_unique<schema::OneHotT>();
const auto &tflite_attr = tflite_op->builtin_options.AsOneHotOptions();
if (tflite_attr == nullptr) {
......
......@@ -40,7 +40,7 @@ STATUS TflitePadParser::Parse(const std::unique_ptr<tflite::OperatorT> &tflite_o
return RET_NULL_PTR;
}
std::unique_ptr<schema::PadT> attr(new schema::PadT());
std::unique_ptr<schema::PadT> attr = std::make_unique<schema::PadT>();
const auto &tflite_attr = tflite_op->builtin_options.AsPadOptions();
if (tflite_attr == nullptr) {
......
......@@ -39,7 +39,7 @@ STATUS TflitePoolingParser::Parse(const std::unique_ptr<tflite::OperatorT> &tfli
return RET_NULL_PTR;
}
std::unique_ptr<schema::PoolingT> attr(new schema::PoolingT());
std::unique_ptr<schema::PoolingT> attr = std::make_unique<schema::PoolingT>();
std::vector<std::string> node_name_str;
Split(op->name, &node_name_str, "-");
......
......@@ -40,7 +40,7 @@ STATUS TfliteRangeParser::Parse(const std::unique_ptr<tflite::OperatorT> &tflite
return RET_NULL_PTR;
}
std::unique_ptr<schema::RangeT> attr(new schema::RangeT());
std::unique_ptr<schema::RangeT> attr = std::make_unique<schema::RangeT>();
attr->dType = 0;
// attr->start
......
......@@ -40,7 +40,7 @@ STATUS TfliteRankParser::Parse(const std::unique_ptr<tflite::OperatorT> &tflite_
return RET_NULL_PTR;
}
std::unique_ptr<schema::RankT> attr(new schema::RankT());
std::unique_ptr<schema::RankT> attr = std::make_unique<schema::RankT>();
op->primitive->value.type = schema::PrimitiveType_Rank;
op->primitive->value.value = attr.release();
......
......@@ -40,7 +40,7 @@ STATUS TfliteReduceParser::Parse(const std::unique_ptr<tflite::OperatorT> &tflit
return RET_NULL_PTR;
}
std::unique_ptr<schema::ReduceT> attr(new schema::ReduceT());
std::unique_ptr<schema::ReduceT> attr = std::make_unique<schema::ReduceT>();
// auto tflite_tensors = tflite_subgraph->tensors;
const auto &tflite_attr = tflite_op->builtin_options.AsReducerOptions();
......
......@@ -40,7 +40,7 @@ STATUS TfliteReshapeParser::Parse(const std::unique_ptr<tflite::OperatorT> &tfli
return RET_NULL_PTR;
}
std::unique_ptr<schema::ReshapeT> attr(new schema::ReshapeT());
std::unique_ptr<schema::ReshapeT> attr = std::make_unique<schema::ReshapeT>();
const auto &tfliteAttr = tflite_op->builtin_options.AsReshapeOptions();
if (tfliteAttr == nullptr) {
......
......@@ -39,7 +39,7 @@ STATUS TfliteResizeParser::Parse(const std::unique_ptr<tflite::OperatorT> &tflit
return RET_NULL_PTR;
}
std::unique_ptr<schema::ResizeT> attr(new schema::ResizeT());
std::unique_ptr<schema::ResizeT> attr = std::make_unique<schema::ResizeT>();
std::vector<std::string> node_name_str;
Split(op->name.data(), &node_name_str, "-");
......
......@@ -40,7 +40,7 @@ STATUS TfliteReverseParser::Parse(const std::unique_ptr<tflite::OperatorT> &tfli
return RET_NULL_PTR;
}
std::unique_ptr<schema::ReverseT> attr(new schema::ReverseT());
std::unique_ptr<schema::ReverseT> attr = std::make_unique<schema::ReverseT>();
if (GetTfliteData(tflite_op->inputs[1], tflite_tensors, tflite_model_buffer, attr->axis)) {
MS_LOG(ERROR) << "get reverse -> axis failed";
......
......@@ -42,7 +42,7 @@ STATUS TfliteReverseSequenceParser::Parse(const std::unique_ptr<tflite::Operator
return RET_NULL_PTR;
}
std::unique_ptr<schema::ReverseSequenceT> attr(new schema::ReverseSequenceT());
std::unique_ptr<schema::ReverseSequenceT> attr = std::make_unique<schema::ReverseSequenceT>();
const auto &tflite_attr = tflite_op->builtin_options.AsReverseSequenceOptions();
if (tflite_attr == nullptr) {
......
......@@ -41,7 +41,7 @@ STATUS TfliteScatterNdParser::Parse(const std::unique_ptr<tflite::OperatorT> &tf
return RET_NULL_PTR;
}
std::unique_ptr<schema::ScatterNDT> attr(new schema::ScatterNDT());
std::unique_ptr<schema::ScatterNDT> attr = std::make_unique<schema::ScatterNDT>();
const auto &tflite_attr = tflite_op->builtin_options.AsScatterNdOptions();
if (tflite_attr == nullptr) {
......
......@@ -40,7 +40,7 @@ STATUS TfliteShapeParser::Parse(const std::unique_ptr<tflite::OperatorT> &tflite
return RET_NULL_PTR;
}
std::unique_ptr<schema::ShapeT> attr(new schema::ShapeT());
std::unique_ptr<schema::ShapeT> attr = std::make_unique<schema::ShapeT>();
op->primitive->value.type = schema::PrimitiveType_Shape;
op->primitive->value.value = attr.release();
......
......@@ -41,7 +41,7 @@ STATUS TfliteSliceParser::Parse(const std::unique_ptr<tflite::OperatorT> &tflite
return RET_NULL_PTR;
}
std::unique_ptr<schema::SliceT> attr(new schema::SliceT());
std::unique_ptr<schema::SliceT> attr = std::make_unique<schema::SliceT>();
attr->format = schema::Format_NHWC;
......
......@@ -40,7 +40,7 @@ STATUS TfliteSoftmaxParser::Parse(const std::unique_ptr<tflite::OperatorT> &tfli
return RET_NULL_PTR;
}
std::unique_ptr<schema::SoftMaxT> attr(new schema::SoftMaxT());
std::unique_ptr<schema::SoftMaxT> attr = std::make_unique<schema::SoftMaxT>();
attr->axis = -1;
......
......@@ -41,7 +41,7 @@ STATUS TfliteSpaceToBatchNDParser::Parse(const std::unique_ptr<tflite::OperatorT
return RET_NULL_PTR;
}
std::unique_ptr<schema::SpaceToBatchNDT> attr(new schema::SpaceToBatchNDT());
std::unique_ptr<schema::SpaceToBatchNDT> attr = std::make_unique<schema::SpaceToBatchNDT>();
if (GetTfliteData(tflite_op->inputs[1], tflite_tensors, tflite_model_buffer, attr->blockShape)) {
MS_LOG(ERROR) << "get spaceToBatchND -> blockShape failed";
......
......@@ -41,7 +41,7 @@ STATUS TfliteSpaceToDepthParser::Parse(const std::unique_ptr<tflite::OperatorT>
return RET_NULL_PTR;
}
std::unique_ptr<schema::SpaceToDepthT> attr(new schema::SpaceToDepthT());
std::unique_ptr<schema::SpaceToDepthT> attr = std::make_unique<schema::SpaceToDepthT>();
const auto &tflite_attr = tflite_op->builtin_options.AsSpaceToDepthOptions();
if (tflite_attr == nullptr) {
......
......@@ -41,7 +41,7 @@ STATUS TfliteSparseToDenseParser::Parse(const std::unique_ptr<tflite::OperatorT>
return RET_NULL_PTR;
}
std::unique_ptr<schema::SparseToDenseT> attr(new schema::SparseToDenseT());
std::unique_ptr<schema::SparseToDenseT> attr = std::make_unique<schema::SparseToDenseT>();
attr->validateIndices = false;
......
......@@ -41,7 +41,7 @@ STATUS TfliteSplitParser::Parse(const std::unique_ptr<tflite::OperatorT> &tflite
return RET_NULL_PTR;
}
std::unique_ptr<schema::SplitT> attr(new schema::SplitT());
std::unique_ptr<schema::SplitT> attr = std::make_unique<schema::SplitT>();
const auto &tflite_attr = tflite_op->builtin_options.AsSplitOptions();
if (tflite_attr == nullptr) {
......
......@@ -39,7 +39,7 @@ STATUS TfliteSplitVParser::Parse(const std::unique_ptr<tflite::OperatorT> &tflit
}
MS_LOG(DEBUG) << "parse TfliteSplitVParser";
std::unique_ptr<schema::SplitT> attr(new schema::SplitT());
std::unique_ptr<schema::SplitT> attr = std::make_unique<schema::SplitT>();
const auto &tflite_attr = tflite_op->builtin_options.AsSplitVOptions();
if (tflite_attr == nullptr) {
......
......@@ -40,7 +40,7 @@ STATUS TfliteSqueezeParser::Parse(const std::unique_ptr<tflite::OperatorT> &tfli
return RET_NULL_PTR;
}
std::unique_ptr<schema::SqueezeT> attr(new schema::SqueezeT());
std::unique_ptr<schema::SqueezeT> attr = std::make_unique<schema::SqueezeT>();
const auto &tflite_attr = tflite_op->builtin_options.AsSqueezeOptions();
if (tflite_attr == nullptr) {
......
......@@ -40,7 +40,7 @@ STATUS TfliteStackParser::Parse(const std::unique_ptr<tflite::OperatorT> &tflite
return RET_NULL_PTR;
}
std::unique_ptr<schema::StackT> attr(new schema::StackT());
std::unique_ptr<schema::StackT> attr = std::make_unique<schema::StackT>();
const auto &tflite_attr = tflite_op->builtin_options.AsPackOptions();
if (tflite_attr == nullptr) {
MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed";
......
......@@ -39,7 +39,7 @@ STATUS TfliteStridedSliceParser::Parse(const std::unique_ptr<tflite::OperatorT>
}
MS_LOG(DEBUG) << "parse TfliteStridedSliceParser";
std::unique_ptr<schema::StridedSliceT> attr(new schema::StridedSliceT());
std::unique_ptr<schema::StridedSliceT> attr = std::make_unique<schema::StridedSliceT>();
const auto &tflite_attr = tflite_op->builtin_options.AsStridedSliceOptions();
if (tflite_attr == nullptr) {
MS_LOG(ERROR) << "get op: %s attr failed", op->name.c_str();
......
......@@ -41,7 +41,7 @@ STATUS TfliteTileParser::Parse(const std::unique_ptr<tflite::OperatorT> &tflite_
return RET_NULL_PTR;
}
std::unique_ptr<schema::TileT> attr(new schema::TileT());
std::unique_ptr<schema::TileT> attr = std::make_unique<schema::TileT>();
if (GetTfliteData(tflite_op->inputs[1], tflite_tensors, tflite_model_buffer, attr->multiples)) {
MS_LOG(ERROR) << "get tile -> multiples failed";
......
......@@ -41,7 +41,7 @@ STATUS TfliteTopKV2Parser::Parse(const std::unique_ptr<tflite::OperatorT> &tflit
return RET_NULL_PTR;
}
std::unique_ptr<schema::TopKT> attr(new schema::TopKT());
std::unique_ptr<schema::TopKT> attr = std::make_unique<schema::TopKT>();
attr->sorted = true;
std::vector<int32_t> k;
......
......@@ -39,7 +39,7 @@ STATUS TfliteTransposeParser::Parse(const std::unique_ptr<tflite::OperatorT> &tf
return RET_NULL_PTR;
}
std::unique_ptr<schema::TransposeT> attr(new schema::TransposeT());
std::unique_ptr<schema::TransposeT> attr = std::make_unique<schema::TransposeT>();
if (GetTfliteData(tflite_op->inputs[1], tflite_tensors, tflite_model_buffer, attr->perm)) {
MS_LOG(ERROR) << "get transpose -> perm failed";
......
......@@ -41,7 +41,7 @@ STATUS TfliteUniqueParser::Parse(const std::unique_ptr<tflite::OperatorT> &tflit
return RET_NULL_PTR;
}
std::unique_ptr<schema::UniqueT> attr(new schema::UniqueT());
std::unique_ptr<schema::UniqueT> attr = std::make_unique<schema::UniqueT>();
const auto &tflite_attr = tflite_op->builtin_options.AsUniqueOptions();
if (tflite_attr == nullptr) {
......
......@@ -42,7 +42,7 @@ STATUS TfliteUnstackParser::Parse(const std::unique_ptr<tflite::OperatorT> &tfli
return RET_NULL_PTR;
}
std::unique_ptr<schema::UnstackT> attr(new schema::UnstackT());
std::unique_ptr<schema::UnstackT> attr = std::make_unique<schema::UnstackT>();
const auto &tflite_attr = tflite_op->builtin_options.AsUnpackOptions();
if (tflite_attr == nullptr) {
......
......@@ -41,7 +41,7 @@ STATUS TfliteWhereParser::Parse(const std::unique_ptr<tflite::OperatorT> &tflite
return RET_NULL_PTR;
}
std::unique_ptr<schema::WhereT> attr(new schema::WhereT());
std::unique_ptr<schema::WhereT> attr = std::make_unique<schema::WhereT>();
if (GetTfliteData(tflite_op->inputs[0], tflite_tensors, tflite_model_buffer, attr->condition)) {
MS_LOG(ERROR) << "get where -> condition failed";
......
......@@ -41,7 +41,7 @@ STATUS TfliteZerosLikeParser::Parse(const std::unique_ptr<tflite::OperatorT> &tf
return RET_NULL_PTR;
}
std::unique_ptr<schema::ZerosLikeT> attr(new schema::ZerosLikeT());
std::unique_ptr<schema::ZerosLikeT> attr = std::make_unique<schema::ZerosLikeT>();
op->primitive->value.type = schema::PrimitiveType_ZerosLike;
op->primitive->value.value = attr.release();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册