diff --git a/mindspore/lite/tools/converter/parser/caffe/CMakeLists.txt b/mindspore/lite/tools/converter/parser/caffe/CMakeLists.txt index 0d8a833e76..37208577a2 100644 --- a/mindspore/lite/tools/converter/parser/caffe/CMakeLists.txt +++ b/mindspore/lite/tools/converter/parser/caffe/CMakeLists.txt @@ -27,5 +27,4 @@ add_library(caffe_parser_mid OBJECT ${CMAKE_CURRENT_SOURCE_DIR}/caffe_inspector.cc ${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_proposal_parser.cc) + ${CMAKE_CURRENT_SOURCE_DIR}/caffe_tile_parser.cc) diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_argmax_parser.cc b/mindspore/lite/tools/converter/parser/caffe/caffe_argmax_parser.cc index a1035eec52..1c15f640fe 100644 --- a/mindspore/lite/tools/converter/parser/caffe/caffe_argmax_parser.cc +++ b/mindspore/lite/tools/converter/parser/caffe/caffe_argmax_parser.cc @@ -24,7 +24,7 @@ STATUS CaffeArgMaxParser::Parse(const caffe::LayerParameter &proto, schema::CNodeT *op, std::vector *weightVec) { op->name = proto.name(); - std::unique_ptr attr(new schema::ArgMaxT()); + std::unique_ptr attr = std::make_unique(); const caffe::ArgMaxParameter argmaxParam = proto.argmax_param(); int32_t axisType = 0; diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_batchnorm_parser.cc b/mindspore/lite/tools/converter/parser/caffe/caffe_batchnorm_parser.cc index b126089ac7..b96082d25a 100644 --- a/mindspore/lite/tools/converter/parser/caffe/caffe_batchnorm_parser.cc +++ b/mindspore/lite/tools/converter/parser/caffe/caffe_batchnorm_parser.cc @@ -32,7 +32,7 @@ STATUS CaffeBatchNormParser::Parse(const caffe::LayerParameter &proto, const caf schema::CNodeT *op, std::vector *weightVec) { op->name = proto.name(); // caffe batch norm attr - std::unique_ptr attr(new schema::BatchNormT()); + std::unique_ptr attr = std::make_unique(); const caffe::BatchNormParameter batchNormParam = proto.batch_norm_param(); // check bottom size diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_concat_parser.cc b/mindspore/lite/tools/converter/parser/caffe/caffe_concat_parser.cc index ce9590f981..dd7f2ff23b 100644 --- a/mindspore/lite/tools/converter/parser/caffe/caffe_concat_parser.cc +++ b/mindspore/lite/tools/converter/parser/caffe/caffe_concat_parser.cc @@ -26,7 +26,7 @@ STATUS CaffeConcatParser::Parse(const caffe::LayerParameter &proto, schema::CNodeT *op, std::vector *weightVec) { op->name = proto.name(); - std::unique_ptr attr(new schema::ConcatT()); + std::unique_ptr attr = std::make_unique(); const caffe::ConcatParameter concatParam = proto.concat_param(); if (concatParam.has_axis() && concatParam.has_concat_dim()) { // MS_LOGE("Concat param in caffe have concat_dim and axis simultaneously,return fail"); diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_convolution_parser.cc b/mindspore/lite/tools/converter/parser/caffe/caffe_convolution_parser.cc index 6b3533b8b3..7b2d0eda29 100644 --- a/mindspore/lite/tools/converter/parser/caffe/caffe_convolution_parser.cc +++ b/mindspore/lite/tools/converter/parser/caffe/caffe_convolution_parser.cc @@ -24,7 +24,7 @@ void CaffeConvolutionParser::ParseGroupConvolution(schema::CNodeT *op, schema::C if (attr == nullptr || attr->group == 1) { return; } - std::unique_ptr depthwiseConv2DParam(new schema::DepthwiseConv2DT()); + std::unique_ptr depthwiseConv2DParam = std::make_unique(); if (depthwiseConv2DParam == nullptr) { // MS_LOGW("new DepthwiseConv2DT failed"); return; @@ -125,6 +125,7 @@ STATUS CaffeConvolutionParser::Parse(const caffe::LayerParameter &proto, const c if (status != RET_OK) { MS_LOG(ERROR) << "ParseWeight for " << proto.name().c_str() << " failed"; } + return status; } diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_crop_parser.cc b/mindspore/lite/tools/converter/parser/caffe/caffe_crop_parser.cc index 71d894d148..f613fb74ce 100644 --- a/mindspore/lite/tools/converter/parser/caffe/caffe_crop_parser.cc +++ b/mindspore/lite/tools/converter/parser/caffe/caffe_crop_parser.cc @@ -25,7 +25,7 @@ STATUS CaffeCropParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight, schema::CNodeT *op, std::vector *weightVec) { - std::unique_ptr attr(new schema::CropT()); + std::unique_ptr attr = std::make_unique(); if (!proto.has_crop_param()) { attr->axis = CROP_AXIS; std::vector offsets(2, 0); diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_deconvolution_parser.cc b/mindspore/lite/tools/converter/parser/caffe/caffe_deconvolution_parser.cc index 503bffe2d4..217efab258 100644 --- a/mindspore/lite/tools/converter/parser/caffe/caffe_deconvolution_parser.cc +++ b/mindspore/lite/tools/converter/parser/caffe/caffe_deconvolution_parser.cc @@ -24,7 +24,8 @@ void CaffeDeconvolutionParser::ParseGroupDeconvolution(schema::CNodeT *op, schem return; } - std::unique_ptr deDepthwiseConv2DParam(new schema::DeDepthwiseConv2DT()); + std::unique_ptr deDepthwiseConv2DParam + = std::make_unique(); if (deDepthwiseConv2DParam == nullptr) { MS_LOG(ERROR) << "new DeDepthwiseConv2DT failed"; return; @@ -125,6 +126,7 @@ STATUS CaffeDeconvolutionParser::Parse(const caffe::LayerParameter &proto, const if (status != RET_OK) { MS_LOG(ERROR) << "ParseWeight for " << proto.name().c_str() << " failed"; } + return status; } diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_eltwise_parser.cc b/mindspore/lite/tools/converter/parser/caffe/caffe_eltwise_parser.cc index 0880dba878..c0211bd66b 100644 --- a/mindspore/lite/tools/converter/parser/caffe/caffe_eltwise_parser.cc +++ b/mindspore/lite/tools/converter/parser/caffe/caffe_eltwise_parser.cc @@ -26,7 +26,7 @@ namespace mindspore { namespace lite { STATUS CaffeEltwiseParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight, schema::CNodeT *op, std::vector *weightVec) { - std::unique_ptr attr(new schema::EltwiseT()); + std::unique_ptr attr = std::make_unique(); if (proto.bottom_size() < ELTWISE_MIN_INPUT_SIZE) { MS_LOG(ERROR) << "Eltwise Op " << proto.name() << " need at least 2 inputs,but input size is " << proto.bottom_size(); diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_innerproduct_parser.cc b/mindspore/lite/tools/converter/parser/caffe/caffe_innerproduct_parser.cc index 1cc01dcedc..d4ddd37870 100644 --- a/mindspore/lite/tools/converter/parser/caffe/caffe_innerproduct_parser.cc +++ b/mindspore/lite/tools/converter/parser/caffe/caffe_innerproduct_parser.cc @@ -22,7 +22,7 @@ namespace lite { STATUS CaffeInnerProductParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight, schema::CNodeT *op, std::vector *weightVec) { const caffe::InnerProductParameter innerProductParam = proto.inner_product_param(); - std::unique_ptr attr(new schema::FullConnectionT()); + std::unique_ptr attr = std::make_unique(); if (!innerProductParam.has_num_output()) { // MS_LOGE("InnerProduct Parse num_output for %s failed.", proto.name().c_str()); diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_interp_parser.cc b/mindspore/lite/tools/converter/parser/caffe/caffe_interp_parser.cc index e2459061c3..3fbee1237c 100644 --- a/mindspore/lite/tools/converter/parser/caffe/caffe_interp_parser.cc +++ b/mindspore/lite/tools/converter/parser/caffe/caffe_interp_parser.cc @@ -21,7 +21,7 @@ namespace mindspore { namespace lite { STATUS CaffeInterpParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight, schema::CNodeT *op, std::vector *weightVec) { - std::unique_ptr attr(new schema::ResizeT()); + std::unique_ptr attr = std::make_unique(); const caffe::InterpParameter interpParam = proto.interp_param(); if (interpParam.has_height()) { int64_t height = interpParam.height(); diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_model_parser.cc b/mindspore/lite/tools/converter/parser/caffe/caffe_model_parser.cc index d9f9f04773..1e29ab1f78 100644 --- a/mindspore/lite/tools/converter/parser/caffe/caffe_model_parser.cc +++ b/mindspore/lite/tools/converter/parser/caffe/caffe_model_parser.cc @@ -33,7 +33,7 @@ const std::set CaffeModelParser::skipedLayerType = {"Dropout"}; schema::MetaGraphT *CaffeModelParser::Parse(const std::string &modelFile, const std::string &weightFile, const QuantType &quantType) { - std::unique_ptr graph(new schema::MetaGraphT()); + // std::unique_ptr graph = std::make_unique(); if (ValidateFileStr(modelFile, ".prototxt") != RET_OK) { MS_LOG(ERROR) << "INPUT ILLEGAL: modelFile must be *.prototxt"; @@ -50,7 +50,7 @@ schema::MetaGraphT *CaffeModelParser::Parse(const std::string &modelFile, const return nullptr; } - std::unique_ptr subGraphDef(new schema::MetaGraphT()); + std::unique_ptr subGraphDef = std::make_unique(); TensorCache tensorCache; caffe::NetParameter proto; @@ -87,11 +87,11 @@ schema::MetaGraphT *CaffeModelParser::Parse(const std::string &modelFile, const subGraphDef->name = GetModelName(modelFile); // set all tensors to graph SetAllTensors(tensorCache, subGraphDef.get()); - graph = move(subGraphDef); + // graph = move(subGraphDef); // ConvertCaffeBatchNorm(graph.get()); - return graph.release(); + return subGraphDef.release(); // return Fb2Anf(graph.release()); } @@ -112,7 +112,7 @@ STATUS CaffeModelParser::SetOpInputIdx(const caffe::LayerParameter &layer, schem STATUS CaffeModelParser::SetOpOutputIdx(const caffe::LayerParameter &layer, schema::CNodeT *op, TensorCache *tensorCache) { for (int i = 0; i < layer.top_size(); i++) { - std::unique_ptr msTensor(new schema::TensorT()); + std::unique_ptr msTensor = std::make_unique(); op->outputIndex.emplace_back(tensorCache->AddTensor(layer.top(i), msTensor.release(), OP_OUTPUT)); } return RET_OK; @@ -176,7 +176,7 @@ STATUS CaffeModelParser::ParseLayer(const caffe::NetParameter &proto, const caff } // todo y00520784 : layer.input_param().shape(0) if (layer.type() == "Input") { - std::unique_ptr msTensor(new schema::TensorT()); + std::unique_ptr msTensor = std::make_unique(); for (int j = 0; j < layer.input_param().shape(0).dim_size(); j++) { msTensor->dims.push_back(layer.input_param().shape(0).dim(j)); } @@ -190,7 +190,7 @@ STATUS CaffeModelParser::ParseLayer(const caffe::NetParameter &proto, const caff continue; } - std::unique_ptr op(new schema::CNodeT()); + std::unique_ptr op = std::make_unique(); op->name = layer.name(); // set op input index @@ -234,7 +234,7 @@ STATUS CaffeModelParser::GetModelInput(const caffe::NetParameter &proto, TensorC if (proto.input_dim_size() <= 0) { continue; } - std::unique_ptr msTensor(new schema::TensorT()); + std::unique_ptr msTensor = std::make_unique(); for (int j = 0; j < proto.input_dim_size(); j++) { msTensor->dims.push_back(proto.input_dim(j)); } @@ -245,7 +245,7 @@ STATUS CaffeModelParser::GetModelInput(const caffe::NetParameter &proto, TensorC for (int i = 0; i < proto.input_shape_size(); i++) { auto shape = proto.input_shape(i); - std::unique_ptr msTensor(new schema::TensorT()); + std::unique_ptr msTensor = std::make_unique(); for (int j = 0; j < shape.dim_size(); j++) { msTensor->dims.push_back(shape.dim(j)); } diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_node_parser.cc b/mindspore/lite/tools/converter/parser/caffe/caffe_node_parser.cc index b82d55446e..0efc9bfdbe 100644 --- a/mindspore/lite/tools/converter/parser/caffe/caffe_node_parser.cc +++ b/mindspore/lite/tools/converter/parser/caffe/caffe_node_parser.cc @@ -22,7 +22,7 @@ namespace mindspore { namespace lite { schema::TensorT *ConvertWeight(const caffe::BlobProto &proto) { - std::unique_ptr weight(new schema::TensorT()); + std::unique_ptr weight = std::make_unique(); weight->format = schema::Format_NCHW; std::vector shapeVec; ConvertShape(proto, &shapeVec); @@ -46,7 +46,7 @@ schema::TensorT *ConvertWeight(const caffe::BlobProto &proto) { } // get weight - std::unique_ptr buf(new (std::nothrow) float[count]()); + std::unique_ptr buf = std::make_unique(count); if (buf == nullptr) { return nullptr; } diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_permute_parser.cc b/mindspore/lite/tools/converter/parser/caffe/caffe_permute_parser.cc index a4c548cd0e..4e5026ca45 100644 --- a/mindspore/lite/tools/converter/parser/caffe/caffe_permute_parser.cc +++ b/mindspore/lite/tools/converter/parser/caffe/caffe_permute_parser.cc @@ -24,7 +24,7 @@ STATUS CaffePermuteParser::Parse(const caffe::LayerParameter &proto, schema::CNodeT *op, std::vector *weightVec) { op->name = proto.name(); - std::unique_ptr attr(new schema::TransposeT()); + std::unique_ptr attr = std::make_unique(); const caffe::PermuteParameter permuteParam = proto.permute_param(); const int num_order_dims = permuteParam.order_size(); diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_pooling_parser.cc b/mindspore/lite/tools/converter/parser/caffe/caffe_pooling_parser.cc index 0dbe2927a9..4e6d67bc15 100644 --- a/mindspore/lite/tools/converter/parser/caffe/caffe_pooling_parser.cc +++ b/mindspore/lite/tools/converter/parser/caffe/caffe_pooling_parser.cc @@ -27,7 +27,7 @@ STATUS CaffePoolingParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight, schema::CNodeT *op, std::vector *weightVec) { - std::unique_ptr attr(new schema::PoolingT()); + std::unique_ptr attr = std::make_unique(); attr->format = schema::Format_NCHW; const caffe::PoolingParameter poolingParam = proto.pooling_param(); diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_power_parser.cc b/mindspore/lite/tools/converter/parser/caffe/caffe_power_parser.cc index 0336bd1c4f..47677542f4 100644 --- a/mindspore/lite/tools/converter/parser/caffe/caffe_power_parser.cc +++ b/mindspore/lite/tools/converter/parser/caffe/caffe_power_parser.cc @@ -27,7 +27,7 @@ STATUS CaffePowerParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight, schema::CNodeT *op, std::vector *weightVec) { - std::unique_ptr attr(new schema::PowerT()); + std::unique_ptr attr = std::make_unique(); const caffe::PowerParameter powerParam = proto.power_param(); if (proto.has_power_param()) { attr->power = powerParam.has_power() ? powerParam.power() : CAFFE_POWER_DEFAULT_POWER; diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_prelu_parser.cc b/mindspore/lite/tools/converter/parser/caffe/caffe_prelu_parser.cc index 2f07077e64..f99c05c59a 100644 --- a/mindspore/lite/tools/converter/parser/caffe/caffe_prelu_parser.cc +++ b/mindspore/lite/tools/converter/parser/caffe/caffe_prelu_parser.cc @@ -23,7 +23,7 @@ STATUS CaffePReluParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight, schema::CNodeT *op, std::vector *weightVec) { - std::unique_ptr attr(new schema::CaffePReLUT()); + std::unique_ptr attr = std::make_unique(); const caffe::PReLUParameter pReluParam = proto.prelu_param(); if (pReluParam.has_channel_shared()) { attr->channelShared = pReluParam.channel_shared(); diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_proposal_parser.cc b/mindspore/lite/tools/converter/parser/caffe/caffe_proposal_parser.cc deleted file mode 100644 index eb0929e2c8..0000000000 --- a/mindspore/lite/tools/converter/parser/caffe/caffe_proposal_parser.cc +++ /dev/null @@ -1,67 +0,0 @@ -/** - * 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 -#include -#include "mindspore/lite/tools/converter/parser/caffe/caffe_proposal_parser.h" - -namespace mindspore { -namespace lite { -STATUS CaffeProposalParser::Parse(const caffe::LayerParameter &proto, - const caffe::LayerParameter &weight, - schema::CNodeT *op, - std::vector *weightVec) { - std::unique_ptr attr(new schema::ProposalT()); - const caffe::ProposalParameter proposal_param = proto.proposal_param(); - - if (proposal_param.has_feat_stride()) { - attr->feat_stride = proposal_param.feat_stride(); - } - if (proposal_param.has_base_size()) { - attr->base_size = proposal_param.base_size(); - } - if (proposal_param.has_min_size()) { - attr->min_size = proposal_param.min_size(); - } - if (proposal_param.has_pre_nms_topn()) { - attr->pre_nms_topn = proposal_param.pre_nms_topn(); - } - if (proposal_param.has_post_nms_topn()) { - attr->post_nms_topn = proposal_param.post_nms_topn(); - } - if (proposal_param.has_nms_thresh()) { - attr->nms_thresh = proposal_param.nms_thresh(); - } - const int num_ratio = proposal_param.ratio_size(); - attr->ratio.resize(num_ratio); - for (int i = 0; i < num_ratio; ++i) { - attr->ratio[i] = proposal_param.ratio(i); - } - const int num_scale = proposal_param.scale_size(); - attr->scale.resize(num_scale); - for (int i = 0; i < num_scale; ++i) { - attr->scale[i] = proposal_param.scale(i); - } - - op->primitive = std::make_unique(); - op->primitive->value.value = attr.release(); - op->primitive->value.type = schema::PrimitiveType_Tile; - return RET_OK; -} - -CaffeNodeRegistrar g_caffeProposalParser("Proposal", new CaffeProposalParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_proposal_parser.h b/mindspore/lite/tools/converter/parser/caffe/caffe_proposal_parser.h deleted file mode 100644 index 8b2079b421..0000000000 --- a/mindspore/lite/tools/converter/parser/caffe/caffe_proposal_parser.h +++ /dev/null @@ -1,36 +0,0 @@ -/** - * 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 LITE_CAFFE_PROPOSAL_PARSER_H -#define LITE_CAFFE_PROPOSAL_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 CaffeProposalParser : public CaffeNodeParser { - public: - CaffeProposalParser() : CaffeNodeParser("proposal") {} - - STATUS Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight, schema::CNodeT *op, - std::vector *weightVec) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // LITE_CAFFE_PROPOSAL_PARSER_H diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_relu_parser.cc b/mindspore/lite/tools/converter/parser/caffe/caffe_relu_parser.cc index 65e5710257..7d5ecc92af 100644 --- a/mindspore/lite/tools/converter/parser/caffe/caffe_relu_parser.cc +++ b/mindspore/lite/tools/converter/parser/caffe/caffe_relu_parser.cc @@ -23,7 +23,7 @@ STATUS CaffeReluParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight, schema::CNodeT *op, std::vector *weightVec) { - std::unique_ptr attr(new schema::ActivationT()); + std::unique_ptr attr = std::make_unique(); attr->type = schema::ActivationType_RELU; // relu: negative_slope = 0, no parameter; // leakyrelu: negative_slope != 0; diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_reshape_parser.cc b/mindspore/lite/tools/converter/parser/caffe/caffe_reshape_parser.cc index d59036c89b..10bfbef6f7 100644 --- a/mindspore/lite/tools/converter/parser/caffe/caffe_reshape_parser.cc +++ b/mindspore/lite/tools/converter/parser/caffe/caffe_reshape_parser.cc @@ -23,7 +23,7 @@ STATUS CaffeReshapeParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight, schema::CNodeT *op, std::vector *weightVec) { - std::unique_ptr attr(new schema::ReshapeT()); + std::unique_ptr attr = std::make_unique(); attr->format = schema::Format_NCHW; const caffe::ReshapeParameter reshapeParam = proto.reshape_param(); diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_scale_parser.cc b/mindspore/lite/tools/converter/parser/caffe/caffe_scale_parser.cc index 83198c2702..8ba3140c91 100644 --- a/mindspore/lite/tools/converter/parser/caffe/caffe_scale_parser.cc +++ b/mindspore/lite/tools/converter/parser/caffe/caffe_scale_parser.cc @@ -24,7 +24,7 @@ namespace mindspore { namespace lite { STATUS CaffeScaleParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight, schema::CNodeT *op, std::vector *weightVec) { - std::unique_ptr attr(new schema::ScaleT()); + std::unique_ptr attr = std::make_unique(); if (weight.blobs_size() + weight.bottom_size() < 2) { // MS_LOGE("Scale bottom size:%d, blobs size:%d invalid in layer %s", weight.bottom_size(), weight.blobs_size(), diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_sigmoid_parser.cc b/mindspore/lite/tools/converter/parser/caffe/caffe_sigmoid_parser.cc index 20c2590ff8..3371d9aca1 100644 --- a/mindspore/lite/tools/converter/parser/caffe/caffe_sigmoid_parser.cc +++ b/mindspore/lite/tools/converter/parser/caffe/caffe_sigmoid_parser.cc @@ -23,7 +23,7 @@ STATUS CaffeSigmoidParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight, schema::CNodeT *op, std::vector *weightVec) { - std::unique_ptr attr(new schema::ActivationT()); + std::unique_ptr attr = std::make_unique(); attr->type = schema::ActivationType_SIGMOID; op->primitive = std::make_unique(); op->primitive->value.value = attr.release(); diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_softmax_parser.cc b/mindspore/lite/tools/converter/parser/caffe/caffe_softmax_parser.cc index 399be822c1..7f2318c14c 100644 --- a/mindspore/lite/tools/converter/parser/caffe/caffe_softmax_parser.cc +++ b/mindspore/lite/tools/converter/parser/caffe/caffe_softmax_parser.cc @@ -26,7 +26,7 @@ STATUS CaffeSoftmaxParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight, schema::CNodeT *op, std::vector *weightVec) { - std::unique_ptr attr(new schema::SoftMaxT()); + std::unique_ptr attr = std::make_unique(); if (proto.has_softmax_param() && proto.softmax_param().has_axis()) { if (proto.softmax_param().axis() == -1) { MS_LOG(ERROR) << "axis with -1 may lead to calculation errors when input less than 4 dims."; diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_tile_parser.cc b/mindspore/lite/tools/converter/parser/caffe/caffe_tile_parser.cc index 56b10c6e61..04a10c1ce8 100644 --- a/mindspore/lite/tools/converter/parser/caffe/caffe_tile_parser.cc +++ b/mindspore/lite/tools/converter/parser/caffe/caffe_tile_parser.cc @@ -24,7 +24,7 @@ STATUS CaffeTileParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight, schema::CNodeT *op, std::vector *weightVec) { - std::unique_ptr attr(new schema::TileT()); + std::unique_ptr attr = std::make_unique(); const caffe::TileParameter tile_param = proto.tile_param(); std::vector dims; diff --git a/mindspore/lite/tools/converter/parser/onnx/onnx_argmax_parser.cc b/mindspore/lite/tools/converter/parser/onnx/onnx_argmax_parser.cc index a354d19eac..0d34c7d705 100644 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_argmax_parser.cc +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_argmax_parser.cc @@ -23,7 +23,7 @@ STATUS OnnxArgMaxParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx ArgMaxParser"; - std::unique_ptr attr(new schema::ArgMaxT()); + std::unique_ptr attr = std::make_unique(); for (const auto &onnx_node_attr : onnx_node.attribute()) { const auto &attribute_name = onnx_node_attr.name(); if (attribute_name == "axis") { diff --git a/mindspore/lite/tools/converter/parser/onnx/onnx_arithmetic_operation_parser.cc b/mindspore/lite/tools/converter/parser/onnx/onnx_arithmetic_operation_parser.cc index d8bcbec3b6..a97d62469c 100644 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_arithmetic_operation_parser.cc +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_arithmetic_operation_parser.cc @@ -22,7 +22,7 @@ namespace lite { STATUS OnnxAddParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx AddParser"; if (op != nullptr) { - std::unique_ptr attr(new schema::AddT()); + std::unique_ptr attr = std::make_unique(); op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Add; op->primitive->value.value = attr.release(); @@ -33,7 +33,7 @@ STATUS OnnxAddParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::Node STATUS OnnxSubParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx SubParser"; if (op != nullptr) { - std::unique_ptr attr(new schema::SubT()); + std::unique_ptr attr = std::make_unique(); op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Sub; op->primitive->value.value = attr.release(); @@ -44,7 +44,7 @@ STATUS OnnxSubParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::Node STATUS OnnxMulParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx MulParser"; if (op != nullptr) { - std::unique_ptr attr(new schema::MulT()); + std::unique_ptr attr = std::make_unique(); op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Mul; op->primitive->value.value = attr.release(); @@ -55,7 +55,7 @@ STATUS OnnxMulParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::Node STATUS OnnxDivParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx DivParser"; if (op != nullptr) { - std::unique_ptr attr(new schema::DivT()); + std::unique_ptr attr = std::make_unique(); op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Div; op->primitive->value.value = attr.release(); @@ -67,7 +67,7 @@ STATUS OnnxPowParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::Node MS_LOG(DEBUG) << "onnx PowParser"; if (op != nullptr) { // TODO(wangzhe) attr power need populate - std::unique_ptr attr(new schema::PowerT()); + std::unique_ptr attr = std::make_unique(); op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Power; op->primitive->value.value = attr.release(); @@ -78,7 +78,7 @@ STATUS OnnxEqualParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::No schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx EqualParser"; if (op != nullptr) { - std::unique_ptr attr(new schema::EqualT()); + std::unique_ptr attr = std::make_unique(); op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Equal; op->primitive->value.value = attr.release(); @@ -89,7 +89,7 @@ STATUS OnnxEqualParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::No STATUS OnnxLessParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx LessParser"; if (op != nullptr) { - std::unique_ptr attr(new schema::LessT()); + std::unique_ptr attr = std::make_unique(); op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Less; op->primitive->value.value = attr.release(); @@ -100,7 +100,7 @@ STATUS OnnxGreaterParser::Parse(const onnx::GraphProto &onnx_graph, const onnx:: schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx GreaterParser"; if (op != nullptr) { - std::unique_ptr attr(new schema::GreaterT()); + std::unique_ptr attr = std::make_unique(); op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Greater; op->primitive->value.value = attr.release(); @@ -111,7 +111,7 @@ STATUS OnnxGreaterParser::Parse(const onnx::GraphProto &onnx_graph, const onnx:: STATUS OnnxMinParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx MinParser"; if (op != nullptr) { - std::unique_ptr attr(new schema::MinT()); + std::unique_ptr attr = std::make_unique(); op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Min; op->primitive->value.value = attr.release(); @@ -122,7 +122,7 @@ STATUS OnnxMinParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::Node STATUS OnnxEltwiseParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx EltwiseParser"; - std::unique_ptr attr(new schema::EltwiseT()); + std::unique_ptr attr = std::make_unique(); // there is no Prod in onnx if (onnx_node.op_type() == "Sum") { attr->mode = schema::EltwiseMode_SUM; @@ -142,7 +142,7 @@ STATUS OnnxFloorParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::No schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx FloorParser"; if (op != nullptr) { - std::unique_ptr attr(new schema::FloorT()); + std::unique_ptr attr = std::make_unique(); op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Floor; op->primitive->value.value = attr.release(); @@ -152,7 +152,7 @@ STATUS OnnxFloorParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::No STATUS OnnxAbsParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx AbsParser"; if (op != nullptr) { - std::unique_ptr attr(new schema::AbsT()); + std::unique_ptr attr = std::make_unique(); op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Abs; op->primitive->value.value = attr.release(); @@ -162,7 +162,7 @@ STATUS OnnxAbsParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::Node STATUS OnnxNegParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx NegParser"; if (op != nullptr) { - std::unique_ptr attr(new schema::NegT()); + std::unique_ptr attr = std::make_unique(); op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Neg; op->primitive->value.value = attr.release(); @@ -172,7 +172,7 @@ STATUS OnnxNegParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::Node STATUS OnnxExpParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx ExpParser"; if (op != nullptr) { - std::unique_ptr attr(new schema::ExpT()); + std::unique_ptr attr = std::make_unique(); op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Exp; op->primitive->value.value = attr.release(); @@ -182,7 +182,7 @@ STATUS OnnxExpParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::Node STATUS OnnxCosParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx CosParser"; if (op != nullptr) { - std::unique_ptr attr(new schema::CosT()); + std::unique_ptr attr = std::make_unique(); op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Cos; op->primitive->value.value = attr.release(); @@ -192,7 +192,7 @@ STATUS OnnxCosParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::Node STATUS OnnxSinParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx SinParser"; if (op != nullptr) { - std::unique_ptr attr(new schema::SinT()); + std::unique_ptr attr = std::make_unique(); op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Sin; op->primitive->value.value = attr.release(); @@ -202,7 +202,7 @@ STATUS OnnxSinParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::Node STATUS OnnxSqrtParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx SqrtParser"; if (op != nullptr) { - std::unique_ptr attr(new schema::SqrtT()); + std::unique_ptr attr = std::make_unique(); op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Sqrt; op->primitive->value.value = attr.release(); @@ -212,7 +212,7 @@ STATUS OnnxSqrtParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::Nod STATUS OnnxCeilParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx CeilParser"; if (op != nullptr) { - std::unique_ptr attr(new schema::CeilT()); + std::unique_ptr attr = std::make_unique(); op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Ceil; op->primitive->value.value = attr.release(); @@ -222,7 +222,7 @@ STATUS OnnxCeilParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::Nod STATUS OnnxLogParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx LogParser"; if (op != nullptr) { - std::unique_ptr attr(new schema::LogT()); + std::unique_ptr attr = std::make_unique(); op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Log; op->primitive->value.value = attr.release(); @@ -232,7 +232,7 @@ STATUS OnnxLogParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::Node STATUS OnnxTanParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx TanParser"; if (op != nullptr) { - std::unique_ptr attr(new schema::TanT()); + std::unique_ptr attr = std::make_unique(); op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Tan; op->primitive->value.value = attr.release(); @@ -242,7 +242,7 @@ STATUS OnnxTanParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::Node STATUS OnnxAtanParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx AtanParser"; if (op != nullptr) { - std::unique_ptr attr(new schema::AtanT()); + std::unique_ptr attr = std::make_unique(); op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Atan; op->primitive->value.value = attr.release(); @@ -252,7 +252,7 @@ STATUS OnnxAtanParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::Nod STATUS OnnxAsinParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx AsinParser"; if (op != nullptr) { - std::unique_ptr attr(new schema::AsinT()); + std::unique_ptr attr = std::make_unique(); op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Asin; op->primitive->value.value = attr.release(); diff --git a/mindspore/lite/tools/converter/parser/onnx/onnx_batchnorm_parser.cc b/mindspore/lite/tools/converter/parser/onnx/onnx_batchnorm_parser.cc index 4279fdefe2..98837a5da5 100644 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_batchnorm_parser.cc +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_batchnorm_parser.cc @@ -22,7 +22,7 @@ namespace lite { STATUS OnnxBatchNormParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx BatchNormParser"; - std::unique_ptr attr(new schema::FusedBatchNormT()); + std::unique_ptr attr = std::make_unique(); for (const auto &onnx_node_attr : onnx_node.attribute()) { if (onnx_node_attr.name() == "epsilon") { attr->epsilon = onnx_node_attr.f(); diff --git a/mindspore/lite/tools/converter/parser/onnx/onnx_biasadd_parser.cc b/mindspore/lite/tools/converter/parser/onnx/onnx_biasadd_parser.cc index 21bd5640a6..73fe05a2c7 100644 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_biasadd_parser.cc +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_biasadd_parser.cc @@ -26,7 +26,7 @@ STATUS OnnxBiasAddParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx BiasAddParser"; - std::unique_ptr attr(new schema::BiasAddT()); + std::unique_ptr attr = std::make_unique(); // use channel dim as axis attr->axis = {1}; if (op != nullptr) { diff --git a/mindspore/lite/tools/converter/parser/onnx/onnx_cast_parser.cc b/mindspore/lite/tools/converter/parser/onnx/onnx_cast_parser.cc index 5df97be894..598cf6c830 100644 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_cast_parser.cc +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_cast_parser.cc @@ -21,7 +21,7 @@ namespace mindspore { namespace lite { STATUS OnnxCastParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx CastParser"; - std::unique_ptr attr(new schema::CastT()); + std::unique_ptr attr = std::make_unique(); for (const auto &onnx_node_attr : onnx_node.attribute()) { const auto &attribute_name = onnx_node_attr.name(); if (attribute_name == "to") { diff --git a/mindspore/lite/tools/converter/parser/onnx/onnx_clip_parser.cc b/mindspore/lite/tools/converter/parser/onnx/onnx_clip_parser.cc index 1536af4a32..f2c989ecdb 100644 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_clip_parser.cc +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_clip_parser.cc @@ -31,7 +31,7 @@ STATUS OnnxClipParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::Nod } } if (min == 0 && max == 6) { - std::unique_ptr attr(new schema::ActivationT()); + std::unique_ptr attr = std::make_unique(); attr->type = schema::ActivationType_RELU6; if (op != nullptr) { op->primitive = std::make_unique(); diff --git a/mindspore/lite/tools/converter/parser/onnx/onnx_concat_parser.cc b/mindspore/lite/tools/converter/parser/onnx/onnx_concat_parser.cc index 2d4f63286c..039cde4469 100644 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_concat_parser.cc +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_concat_parser.cc @@ -23,7 +23,7 @@ STATUS OnnxConcatParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx ConcatParser"; - std::unique_ptr attr(new schema::ConcatT()); + std::unique_ptr attr = std::make_unique(); for (const auto &onnx_node_attr : onnx_node.attribute()) { const auto &attribute_name = onnx_node_attr.name(); if (attribute_name == "axis") { diff --git a/mindspore/lite/tools/converter/parser/onnx/onnx_constant_parser.cc b/mindspore/lite/tools/converter/parser/onnx/onnx_constant_parser.cc index 07ad527017..df54cbc165 100644 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_constant_parser.cc +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_constant_parser.cc @@ -24,7 +24,7 @@ STATUS OnnxConstantParser::Parse(const onnx::GraphProto &onnx_graph, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx ConstantParser"; if (op != nullptr) { - std::unique_ptr attr(new schema::ConstantT()); + std::unique_ptr attr = std::make_unique(); op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Constant; op->primitive->value.value = attr.release(); diff --git a/mindspore/lite/tools/converter/parser/onnx/onnx_conv_parser.cc b/mindspore/lite/tools/converter/parser/onnx/onnx_conv_parser.cc index 566b29aefb..fb0e77ebe5 100644 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_conv_parser.cc +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_conv_parser.cc @@ -26,7 +26,7 @@ bool OnnxConvParser::ParseGroupConvolution(const std::unique_ptrgroup != attr->channelIn) { return false; } - std::unique_ptr depthwiseConv2DParam(new (std::nothrow) schema::DepthwiseConv2DT()); + std::unique_ptr depthwiseConv2DParam = std::make_unique(); if (depthwiseConv2DParam == nullptr) { MS_LOG(ERROR) << "new DepthwiseConv2DT failed"; return false; @@ -55,7 +55,7 @@ bool OnnxConvParser::ParseGroupConvolution(const std::unique_ptr attr(new (std::nothrow) schema::Conv2DT()); + std::unique_ptr attr = std::make_unique(); // set opdef each attr params for (const auto &onnx_node_attr : onnx_node.attribute()) { if (onnx_node_attr.name() == "group") { diff --git a/mindspore/lite/tools/converter/parser/onnx/onnx_deconv_parser.cc b/mindspore/lite/tools/converter/parser/onnx/onnx_deconv_parser.cc index 6ace91e0c7..aef5dcdeb5 100644 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_deconv_parser.cc +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_deconv_parser.cc @@ -26,7 +26,7 @@ bool OnnxDeConvParser::ParseGroupDeConvolution(const std::unique_ptrgroup != attr->channelOut) { return false; } - std::unique_ptr deDepthwiseConv2DParam(new (std::nothrow) schema::DeDepthwiseConv2DT()); + std::unique_ptr deDepthwiseConv2DParam = std::make_unique(); if (deDepthwiseConv2DParam == nullptr) { MS_LOG(ERROR) << "new DeDepthwiseConv2DT failed"; return false; @@ -58,7 +58,7 @@ bool OnnxDeConvParser::ParseGroupDeConvolution(const std::unique_ptr attr(new (std::nothrow) schema::DeConv2DT()); + std::unique_ptr attr = std::make_unique(); // set opdef each attr params for (const auto &onnx_node_attr : onnx_node.attribute()) { if (onnx_node_attr.name() == "group") { diff --git a/mindspore/lite/tools/converter/parser/onnx/onnx_depth_to_space_parser.cc b/mindspore/lite/tools/converter/parser/onnx/onnx_depth_to_space_parser.cc index 8fcdf957dd..adb6169786 100644 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_depth_to_space_parser.cc +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_depth_to_space_parser.cc @@ -23,7 +23,7 @@ STATUS OnnxDepthToSpaceParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx DepthToSpaceParser"; - std::unique_ptr attr(new schema::DepthToSpaceT()); + std::unique_ptr attr = std::make_unique(); for (const auto &onnx_node_attr : onnx_node.attribute()) { const auto& attribute_name = onnx_node_attr.name(); if (attribute_name == "blocksize") { diff --git a/mindspore/lite/tools/converter/parser/onnx/onnx_dropout_parser.cc b/mindspore/lite/tools/converter/parser/onnx/onnx_dropout_parser.cc index 4653a5d712..065f270e85 100644 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_dropout_parser.cc +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_dropout_parser.cc @@ -23,7 +23,7 @@ STATUS OnnxDropoutParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx DropoutParser"; - std::unique_ptr attr(new schema::DropoutT()); + std::unique_ptr attr = std::make_unique(); for (const auto &onnx_node_attr : onnx_node.attribute()) { const auto &attribute_name = onnx_node_attr.name(); if (attribute_name == "ratio") { diff --git a/mindspore/lite/tools/converter/parser/onnx/onnx_elu_parser.cc b/mindspore/lite/tools/converter/parser/onnx/onnx_elu_parser.cc index 2ce944e139..9106a58ff0 100644 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_elu_parser.cc +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_elu_parser.cc @@ -21,7 +21,7 @@ namespace mindspore { namespace lite { STATUS OnnxEluParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx EluParser"; - std::unique_ptr attr(new schema::EluT()); + std::unique_ptr attr = std::make_unique(); for (const auto &onnx_node_attr : onnx_node.attribute()) { const auto& attribute_name = onnx_node_attr.name(); if (attribute_name == "alpha") { diff --git a/mindspore/lite/tools/converter/parser/onnx/onnx_expand_parser.cc b/mindspore/lite/tools/converter/parser/onnx/onnx_expand_parser.cc index 3f5283cc2b..d474ef565b 100644 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_expand_parser.cc +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_expand_parser.cc @@ -23,7 +23,7 @@ STATUS OnnxExpandParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::N schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx ExpandParser"; if (op != nullptr) { - std::unique_ptr attr(new schema::BroadcastT()); + std::unique_ptr attr = std::make_unique(); op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Broadcast; op->primitive->value.value = attr.release(); diff --git a/mindspore/lite/tools/converter/parser/onnx/onnx_flatten_parser.cc b/mindspore/lite/tools/converter/parser/onnx/onnx_flatten_parser.cc index 62445d58be..2e30d702b3 100644 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_flatten_parser.cc +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_flatten_parser.cc @@ -23,7 +23,7 @@ STATUS OnnxFlattenParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx FlattenParser"; - std::unique_ptr attr(new schema::ReshapeT()); + std::unique_ptr attr = std::make_unique(); int axis = 1; for (const auto &onnx_node_attr : onnx_node.attribute()) { const auto &attribute_name = onnx_node_attr.name(); diff --git a/mindspore/lite/tools/converter/parser/onnx/onnx_gather_parser.cc b/mindspore/lite/tools/converter/parser/onnx/onnx_gather_parser.cc index 5ca1dc8299..68d916ba46 100644 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_gather_parser.cc +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_gather_parser.cc @@ -23,7 +23,7 @@ STATUS OnnxGatherParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx GatherParser"; - std::unique_ptr attr(new schema::GatherT()); + std::unique_ptr attr = std::make_unique(); for (const auto &onnx_node_attr : onnx_node.attribute()) { const auto& attribute_name = onnx_node_attr.name(); if (attribute_name == "axis") { diff --git a/mindspore/lite/tools/converter/parser/onnx/onnx_lrn_parser.cc b/mindspore/lite/tools/converter/parser/onnx/onnx_lrn_parser.cc index 1cccf7ffba..ee2c345ac4 100644 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_lrn_parser.cc +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_lrn_parser.cc @@ -21,7 +21,7 @@ namespace mindspore { namespace lite { STATUS OnnxLrnParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx LrnParser"; - std::unique_ptr attr(new schema::LrnT()); + std::unique_ptr attr = std::make_unique(); for (const auto &onnx_node_attr : onnx_node.attribute()) { const auto& attribute_name = onnx_node_attr.name(); if (attribute_name == "size") { diff --git a/mindspore/lite/tools/converter/parser/onnx/onnx_matmul_parser.cc b/mindspore/lite/tools/converter/parser/onnx/onnx_matmul_parser.cc index 8f2f0d056b..fcbfbb46bd 100644 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_matmul_parser.cc +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_matmul_parser.cc @@ -22,7 +22,7 @@ namespace lite { STATUS OnnxMatmulParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx MatMulParser"; - std::unique_ptr attr(new schema::MatMulT()); + std::unique_ptr attr = std::make_unique(); float alpha = 1.0f; float beta = 1.0f; for (const auto &onnx_node_attr : onnx_node.attribute()) { diff --git a/mindspore/lite/tools/converter/parser/onnx/onnx_model_parser.cc b/mindspore/lite/tools/converter/parser/onnx/onnx_model_parser.cc index 70cb8a2a45..85ca5510ef 100755 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_model_parser.cc +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_model_parser.cc @@ -70,6 +70,7 @@ STATUS OnnxModelParser::ReadOnnxModelFromBinary(const std::string &modelFile, go return RET_ERROR; } (void)close(fd); + onnx_file.release(); return RET_OK; } @@ -117,7 +118,7 @@ STATUS OnnxModelParser::AddValueInfo(const onnx::ValueInfoProto &proto, const st << static_cast(proto.type().tensor_type().elem_type()); return RET_ERROR; } - std::unique_ptr tensor(new schema::TensorT); + std::unique_ptr tensor = std::make_unique(); if (tensor == nullptr) { MS_LOG(ERROR) << "new tensor failed"; return RET_ERROR; @@ -137,7 +138,7 @@ STATUS OnnxModelParser::AddTensorProto(const onnx::TensorProto &proto, const std return RET_ERROR; } - std::unique_ptr tensor(new (std::nothrow) schema::TensorT); + std::unique_ptr tensor = std::make_unique(); if (tensor == nullptr) { MS_LOG(ERROR) << "new tensor failed"; return RET_ERROR; @@ -190,7 +191,7 @@ STATUS OnnxModelParser::SetGraphOutputTensor(const onnx::GraphProto &onnx_graph, void OnnxModelParser::ParseOnnxGemmNode(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::MetaGraphT *graph, TensorCache *tensor_cache) { - std::unique_ptr dst_op_1(new schema::CNodeT); + std::unique_ptr dst_op_1 = std::make_unique(); dst_op_1->name = "Gemm_MatMul_" + onnx_node.output(0); ParseOnnxNodeAttr(onnx_graph, onnx_node, "MatMul", dst_op_1.get()); auto matmul_output_id = "Gemm_MatMul_" + onnx_node.output(0); @@ -200,7 +201,7 @@ void OnnxModelParser::ParseOnnxGemmNode(const onnx::GraphProto &onnx_graph, cons SetOpOutputIndex(matmul_outputs, dst_op_1.get(), tensor_cache); graph->nodes.emplace_back(std::move(dst_op_1)); - std::unique_ptr dst_op_2(new schema::CNodeT); + std::unique_ptr dst_op_2 = std::make_unique(); dst_op_2->name = "Gemm_BiasAdd_" + onnx_node.output(0); ParseOnnxNodeAttr(onnx_graph, onnx_node, "BiasAdd", dst_op_2.get()); std::vector biasadd_inputs{matmul_output_id, onnx_node.input(2)}; @@ -214,7 +215,7 @@ STATUS OnnxModelParser::ParseOnnxGivenFillNode(const onnx::NodeProto &onnx_node, // convert GivenTensorFill node to a weight/bias tensor auto ret = tensor_cache->FindTensor(onnx_node.output(0)); if (ret < 0) { - std::unique_ptr tensor(new schema::TensorT); + std::unique_ptr tensor = std::make_unique(); std::vector shape; auto iter = std::find_if(onnx_node.attribute().begin(), onnx_node.attribute().end(), [](const onnx::AttributeProto &attr) { return attr.name() == "shape"; }); @@ -322,7 +323,7 @@ void OnnxModelParser::SetOpQuantParams(const onnx::GraphProto &onnx_graph, const } size_t findQuantParams = 0; for (const auto &node : quant_node) { - std::unique_ptr quant_param(new (std::nothrow) schema::QuantParamT()); + std::unique_ptr quant_param = std::make_unique(); if (quant_param == nullptr) { MS_LOG(ERROR) << "new QuantParamT failed, node: " << dst_op->name; return; @@ -385,7 +386,7 @@ STATUS OnnxModelParser::SetOpOutputIndex(const std::vector &node_outputs for (const auto &onnx_node_output : node_outputs) { auto index = tensor_cache->FindTensor(onnx_node_output); if (index < 0) { // when index >= 0, it's graph's output - std::unique_ptr tensor(new schema::TensorT); + std::unique_ptr tensor = std::make_unique(); tensor->nodeType = schema::NodeType_Parameter; index = tensor_cache->AddTensor(onnx_node_output, tensor.release(), OP_OUTPUT); } @@ -482,7 +483,7 @@ MetaGraphT *OnnxModelParser::Parse(const std::string &modelFile, const std::stri MS_LOG(ERROR) << "Input illegal: modelFile must be *.onnx"; return nullptr; } - std::unique_ptr dst_graph(new schema::MetaGraphT()); + std::unique_ptr dst_graph = std::make_unique(); onnx::ModelProto onnx_model; if (ReadOnnxModelFromBinary(modelFile, &onnx_model) != RET_OK) { MS_LOG(ERROR) << "read onnx model fail"; @@ -526,8 +527,8 @@ MetaGraphT *OnnxModelParser::Parse(const std::string &modelFile, const std::stri continue; } - std::unique_ptr dst_op(new schema::CNodeT); - std::unique_ptr dst_tensor(new schema::TensorT); + std::unique_ptr dst_op = std::make_unique(); + std::unique_ptr dst_tensor = std::make_unique(); auto status = ParseOnnxNodeToDstOp(onnx_graph, onnx_node, dst_op.get(), dst_tensor.get(), &tensor_cache); if (status != RET_OK) { MS_LOG(ERROR) << "parse node " << onnx_node.op_type() << " failed"; diff --git a/mindspore/lite/tools/converter/parser/onnx/onnx_node_parser.cc b/mindspore/lite/tools/converter/parser/onnx/onnx_node_parser.cc index c5e7553906..59ba5256de 100644 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_node_parser.cc +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_node_parser.cc @@ -26,7 +26,7 @@ schema::PadMode OnnxNodeParser::GetOnnxPadMode(const onnx::AttributeProto &onnx_ } else if (onnx_node_attr.s() == "VALID") { return schema::PadMode_VALID; } else { - // MS_LOGE("unsupported padMode"); + MS_LOG(ERROR) << "unsupported padMode"; return schema::PadMode_NOTSET; } } diff --git a/mindspore/lite/tools/converter/parser/onnx/onnx_pad_parser.cc b/mindspore/lite/tools/converter/parser/onnx/onnx_pad_parser.cc index ad89ae8a03..96729b973a 100644 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_pad_parser.cc +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_pad_parser.cc @@ -21,7 +21,7 @@ namespace mindspore { namespace lite { STATUS OnnxPadParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx PadParser"; - std::unique_ptr attr(new schema::PadT()); + std::unique_ptr attr = std::make_unique(); for (const auto &onnx_node_attr : onnx_node.attribute()) { const auto &attribute_name = onnx_node_attr.name(); if (attribute_name == "pads") { diff --git a/mindspore/lite/tools/converter/parser/onnx/onnx_pool_parser.cc b/mindspore/lite/tools/converter/parser/onnx/onnx_pool_parser.cc index 95707c6b76..6b05d7041a 100644 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_pool_parser.cc +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_pool_parser.cc @@ -21,7 +21,7 @@ namespace mindspore { namespace lite { STATUS OnnxPoolParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx PoolParser"; - std::unique_ptr attr(new schema::PoolingT()); + std::unique_ptr attr = std::make_unique(); attr->format = schema::Format_NCHW; const auto &pool_type = onnx_node.op_type(); diff --git a/mindspore/lite/tools/converter/parser/onnx/onnx_reduce_parser.cc b/mindspore/lite/tools/converter/parser/onnx/onnx_reduce_parser.cc index c310f21431..9d7aed8b95 100644 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_reduce_parser.cc +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_reduce_parser.cc @@ -23,7 +23,7 @@ STATUS OnnxReduceParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx ReduceParser"; - std::unique_ptr attr(new schema::ReduceT()); + std::unique_ptr attr = std::make_unique(); for (const auto &onnx_node_attr : onnx_node.attribute()) { const auto &attribute_name = onnx_node_attr.name(); if (attribute_name == "axes") { diff --git a/mindspore/lite/tools/converter/parser/onnx/onnx_relu_parser.cc b/mindspore/lite/tools/converter/parser/onnx/onnx_relu_parser.cc index e51d2aab60..3de97da060 100644 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_relu_parser.cc +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_relu_parser.cc @@ -22,7 +22,7 @@ namespace mindspore { namespace lite { STATUS OnnxReluParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx ReluParser"; - std::unique_ptr attr(new schema::ActivationT()); + std::unique_ptr attr = std::make_unique(); const auto &relu_type = onnx_node.op_type(); if (relu_type == "Relu") { attr->type = schema::ActivationType_RELU; @@ -45,7 +45,7 @@ STATUS OnnxPReluParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::No MS_LOG(ERROR) << "input num is not 2"; return RET_PARAM_INVALID; } - std::unique_ptr attr(new schema::CaffePReLUT()); + std::unique_ptr attr = std::make_unique(); std::vector params; const auto &input_name = onnx_node.input(1); for (const auto &it : onnx_graph.initializer()) { diff --git a/mindspore/lite/tools/converter/parser/onnx/onnx_reshape_parser.cc b/mindspore/lite/tools/converter/parser/onnx/onnx_reshape_parser.cc index 520a0215b7..72bf55547a 100644 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_reshape_parser.cc +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_reshape_parser.cc @@ -23,7 +23,7 @@ namespace lite { STATUS OnnxReshapeParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx ReshapeParser"; - std::unique_ptr attr(new schema::ReshapeT()); + std::unique_ptr attr = std::make_unique(); attr->format = schema::Format_NCHW; std::vector params; // TODO(wangzhe) shape may also come from other op, there need refactor to introduce tensor_cache diff --git a/mindspore/lite/tools/converter/parser/onnx/onnx_shape_parser.cc b/mindspore/lite/tools/converter/parser/onnx/onnx_shape_parser.cc index db0115fe2b..5b7d195559 100644 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_shape_parser.cc +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_shape_parser.cc @@ -24,7 +24,7 @@ STATUS OnnxShapeParser::Parse(const onnx::GraphProto &onnx_graph, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx ShapeParser"; if (op != nullptr) { - std::unique_ptr attr(new schema::ShapeT()); + std::unique_ptr attr = std::make_unique(); op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Shape; op->primitive->value.value = attr.release(); diff --git a/mindspore/lite/tools/converter/parser/onnx/onnx_sigmoid_parser.cc b/mindspore/lite/tools/converter/parser/onnx/onnx_sigmoid_parser.cc index a2002d2cea..15383689ac 100644 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_sigmoid_parser.cc +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_sigmoid_parser.cc @@ -23,7 +23,7 @@ STATUS OnnxSigmoidParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx SigmoidParser"; - std::unique_ptr attr(new schema::ActivationT()); + std::unique_ptr attr = std::make_unique(); attr->type = schema::ActivationType_SIGMOID; if (op != nullptr) { op->primitive = std::make_unique(); diff --git a/mindspore/lite/tools/converter/parser/onnx/onnx_slice_parser.cc b/mindspore/lite/tools/converter/parser/onnx/onnx_slice_parser.cc index 9ee15e0402..541e0c86a8 100644 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_slice_parser.cc +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_slice_parser.cc @@ -22,7 +22,7 @@ namespace lite { STATUS OnnxSliceParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx SliceParser"; - std::unique_ptr attr(new schema::SliceT()); + std::unique_ptr attr = std::make_unique(); for (const auto &onnx_node_attr : onnx_node.attribute()) { const auto &attribute_name = onnx_node_attr.name(); if (attribute_name == "starts") { diff --git a/mindspore/lite/tools/converter/parser/onnx/onnx_softmax_parser.cc b/mindspore/lite/tools/converter/parser/onnx/onnx_softmax_parser.cc index a19d6e32fd..4f37559821 100644 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_softmax_parser.cc +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_softmax_parser.cc @@ -23,7 +23,7 @@ STATUS OnnxSoftMaxParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx SoftMaxParser"; - std::unique_ptr attr(new schema::SoftMaxT()); + std::unique_ptr attr = std::make_unique(); for (const auto &onnx_node_attr : onnx_node.attribute()) { const auto& attribute_name = onnx_node_attr.name(); if (attribute_name == "axis") { diff --git a/mindspore/lite/tools/converter/parser/onnx/onnx_space_to_depth_parser.cc b/mindspore/lite/tools/converter/parser/onnx/onnx_space_to_depth_parser.cc index 1f4f88024a..fbb6d44d1b 100644 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_space_to_depth_parser.cc +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_space_to_depth_parser.cc @@ -22,7 +22,7 @@ namespace lite { STATUS OnnxSpaceToDepthParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx SpaceToDepthParser"; - std::unique_ptr attr(new schema::SpaceToDepthT()); + std::unique_ptr attr = std::make_unique(); for (const auto &onnx_node_attr : onnx_node.attribute()) { const auto &attribute_name = onnx_node_attr.name(); if (attribute_name == "blocksize") { diff --git a/mindspore/lite/tools/converter/parser/onnx/onnx_squeeze_parser.cc b/mindspore/lite/tools/converter/parser/onnx/onnx_squeeze_parser.cc index f0fb977cec..7e8e2c202b 100644 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_squeeze_parser.cc +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_squeeze_parser.cc @@ -23,7 +23,7 @@ STATUS OnnxSqueezeParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx SqueezeParser"; - std::unique_ptr attr(new schema::SqueezeT()); + std::unique_ptr attr = std::make_unique(); for (const auto &onnx_node_attr : onnx_node.attribute()) { const auto &attribute_name = onnx_node_attr.name(); if (attribute_name == "axes") { diff --git a/mindspore/lite/tools/converter/parser/onnx/onnx_tile_parser.cc b/mindspore/lite/tools/converter/parser/onnx/onnx_tile_parser.cc index c4a220720d..e2d7782b10 100644 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_tile_parser.cc +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_tile_parser.cc @@ -22,7 +22,7 @@ namespace lite { STATUS OnnxTileParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx TileParser"; if (op != nullptr) { - std::unique_ptr attr(new schema::TileT()); + std::unique_ptr attr = std::make_unique(); op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Tile; op->primitive->value.value = attr.release(); diff --git a/mindspore/lite/tools/converter/parser/onnx/onnx_transpose_parser.cc b/mindspore/lite/tools/converter/parser/onnx/onnx_transpose_parser.cc index fd7ee3bb55..ffa5fc6916 100644 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_transpose_parser.cc +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_transpose_parser.cc @@ -23,7 +23,7 @@ STATUS OnnxTransposeParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx TransposeParser"; - std::unique_ptr attr(new schema::TransposeT()); + std::unique_ptr attr = std::make_unique(); attr->conjugate = false; for (const auto &onnx_node_attr : onnx_node.attribute()) { const auto &attribute_name = onnx_node_attr.name(); diff --git a/mindspore/lite/tools/converter/parser/onnx/onnx_unsample_parser.cc b/mindspore/lite/tools/converter/parser/onnx/onnx_unsample_parser.cc index fc83f1ed39..b18c6ca309 100644 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_unsample_parser.cc +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_unsample_parser.cc @@ -23,7 +23,7 @@ STATUS OnnxUpsampleParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx UpsampleParser"; - std::unique_ptr attr(new schema::UpsampleT()); + std::unique_ptr attr = std::make_unique(); for (const auto &onnx_node_attr : onnx_node.attribute()) { const auto &attribute_name = onnx_node_attr.name(); if (attribute_name == "mode") { diff --git a/mindspore/lite/tools/converter/parser/onnx/onnx_unsqueeze_parser.cc b/mindspore/lite/tools/converter/parser/onnx/onnx_unsqueeze_parser.cc index 2f142d76d4..c5cc571620 100644 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_unsqueeze_parser.cc +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_unsqueeze_parser.cc @@ -22,7 +22,7 @@ namespace lite { STATUS OnnxUnSqueezeParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { MS_LOG(DEBUG) << "onnx UnSqueezeParser"; - std::unique_ptr attr(new schema::UnsqueezeT()); + std::unique_ptr attr = std::make_unique(); for (const auto &onnx_node_attr : onnx_node.attribute()) { const auto &attribute_name = onnx_node_attr.name(); if (attribute_name == "axes") { diff --git a/mindspore/lite/tools/converter/parser/onnx/onnx_unuseful_node_parser.cc b/mindspore/lite/tools/converter/parser/onnx/onnx_unuseful_node_parser.cc index bd8180ebf3..4b3425eae6 100644 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_unuseful_node_parser.cc +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_unuseful_node_parser.cc @@ -27,10 +27,10 @@ STATUS OnnxUnusefulNodeParser::Parse(const onnx::GraphProto &onnx_graph, op->primitive = std::make_unique(); if (onnx_node.op_type() == "Int8Quantize") { op->primitive->value.type = schema::PrimitiveType_OnnxInt8Quantize; - op->primitive->value.value = new (std::nothrow) schema::OnnxInt8QuantizeT; + op->primitive->value.value = std::make_unique().release(); } else if (onnx_node.op_type() == "Int8Dequantize") { op->primitive->value.type = schema::PrimitiveType_OnnxInt8Dequantize; - op->primitive->value.value = new (std::nothrow) schema::OnnxInt8DequantizeT; + op->primitive->value.value = std::make_unique().release(); } else { // MS_LOGE("Unsupported nodeType: %s", onnx_node.op_type().c_str()); return RET_ERROR; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_model_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_model_parser.cc index 452f44d84d..eceadc8b94 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_model_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_model_parser.cc @@ -64,7 +64,7 @@ STATUS TfliteModelParser::CopyConstTensorData(const std::vector &tflite_tensor, schema::TensorT *tensor) { - std::unique_ptr quant_param(new QuantParamT()); + std::unique_ptr quant_param = std::make_unique(); if (!tflite_tensor->quantization->scale.empty()) { quant_param->scale = tflite_tensor->quantization->scale[0]; } @@ -104,7 +104,7 @@ STATUS TfliteModelParser::ConvertOp(const std::unique_ptr &tflit return RET_ERROR; } - std::unique_ptr op(new schema::CNodeT); + std::unique_ptr op = std::make_unique(); op->name = op_type + "-" + std::to_string(idx++); op->quantType = quant_type; MS_LOG(INFO) << "parse op: " << op->name.c_str(); @@ -138,7 +138,7 @@ STATUS TfliteModelParser::ConvertTensor(const std::unique_ptr idx += tflite_subgraph->tensors.size(); } const auto &tflite_tensor = tflite_subgraph->tensors[idx]; - std::unique_ptr tensor(new schema::TensorT()); + std::unique_ptr tensor = std::make_unique(); tensor->format = tensorsFormat[i]; tensor->dataType = GetTfliteDataType(tflite_tensor->type); @@ -231,7 +231,7 @@ STATUS TfliteModelParser::ConvertGroupDepthwiseOp(schema::MetaGraphT* sub_graph) if (op->primitive->value.type == schema::PrimitiveType_DepthwiseConv2D) { auto attr = op->primitive->value.AsDepthwiseConv2D(); if (attr->channelMultiplier > 1) { - std::unique_ptr conv_attr(new schema::Conv2DT); + std::unique_ptr conv_attr = std::make_unique(); // get channel attr if (op->inputIndex.empty()) { MS_LOG(ERROR) << "the input of DepthwiseConv2D is null"; @@ -298,7 +298,7 @@ STATUS TfliteModelParser::ConvertGroupDepthwiseOp(schema::MetaGraphT* sub_graph) MetaGraphT *TfliteModelParser::Parse(const std::string &model_file, const std::string &weight_file, const QuantType &quant_type) { - std::unique_ptr sub_graph(new schema::MetaGraphT); + std::unique_ptr sub_graph = std::make_unique(); sub_graph->name = "MS_model converted by TF-Lite"; // load graph