diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/fp32_grad/layernorm_grad.c b/mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/fp32_grad/layernorm_grad.c index 24c6b3df59..0be57947c8 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/fp32_grad/layernorm_grad.c +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/fp32_grad/layernorm_grad.c @@ -16,12 +16,16 @@ #include "nnacl/fp32_grad/layernorm_grad.h" #include #include +#include "nnacl/errorcode.h" -void LayerNormGrad(const float *x, const float *dy, const float *var, const float *mean, const float *gamma, - int param_num, int param_size, int block_num, int block_size, float *dx, float *dg, float *db) { +int LayerNormGrad(const float *x, const float *dy, const float *var, const float *mean, const float *gamma, + int param_num, int param_size, int block_num, int block_size, float *dx, float *dg, float *db) { // var is actually layer_norm forward output var const float eps = 1e-12; const float *var_sqrt_rev = var; + if (block_size <= 0) { + return NNACL_ERRCODE_DIVISOR_ZERO; + } for (size_t i = 0; i < param_num; ++i) { float dgamma = 0.0f; float dbeta = 0.0f; @@ -56,4 +60,5 @@ void LayerNormGrad(const float *x, const float *dy, const float *var, const floa dx[index] = dx1 + dx2 + dx3; } } + return NNACL_OK; } diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/fp32_grad/layernorm_grad.h b/mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/fp32_grad/layernorm_grad.h index ab9122c5c9..efab78dd3b 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/fp32_grad/layernorm_grad.h +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/fp32_grad/layernorm_grad.h @@ -20,8 +20,8 @@ extern "C" { #endif -void LayerNormGrad(const float *x, const float *dy, const float *var, const float *mean, const float *gamma, - int param_num, int param_size, int block_num, int block_size, float *dx, float *dg, float *db); +int LayerNormGrad(const float *x, const float *dy, const float *var, const float *mean, const float *gamma, + int param_num, int param_size, int block_num, int block_size, float *dx, float *dg, float *db); #ifdef __cplusplus } diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/infer/arithmetic_infer.c b/mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/infer/arithmetic_infer.c index 9e4f4541d9..edf38a52bb 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/infer/arithmetic_infer.c +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/infer/arithmetic_infer.c @@ -62,7 +62,6 @@ int ArithmeticInferShape(const TensorC *const *inputs, size_t inputs_size, Tenso } in_shape1_[i] = input_shape1[i]; } - // format = input0->format(); } else if (input_shape0_size > input_shape1_size) { ndim_ = input_shape0_size; int fill_dim_num = input_shape0_size - input_shape1_size; diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/infer/strided_slice_grad_infer.c b/mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/infer/strided_slice_grad_infer.c index 69fb638b26..2f1501deb2 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/infer/strided_slice_grad_infer.c +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/infer/strided_slice_grad_infer.c @@ -89,7 +89,7 @@ int StridedSliceGradInferShape(const TensorC *const *inputs, size_t inputs_size, param->strides_[i] = strides_[i]; } ShapeSet(param->in_shape_, &in_shape_size, input->shape_, input->shape_size_); - // ApplyNewAxisMask(); + // ApplyNewAxisMask; for (size_t i = 0; i < ndim_; i++) { if (new_axis_mask_[i]) { ndim_ += 1; @@ -107,19 +107,19 @@ int StridedSliceGradInferShape(const TensorC *const *inputs, size_t inputs_size, ellipsis_mask_[i] = false; } } - // ApplyBeginMask(); + // ApplyBeginMask; for (size_t i = 0; i < ndim_; i++) { if (begins_mask_[i]) { begins_[i] = 0; } } - // ApplyEndMask(); + // ApplyEndMask; for (size_t i = 0; i < ndim_; i++) { if (ends_mask_[i]) { ends_[i] = in_shape_[i]; } } - // ApplyEllipsisMask(); + // ApplyEllipsisMask; for (size_t i = 0; i < ndim_; i++) { if (ellipsis_mask_[i]) { begins_[i] = 0; diff --git a/mindspore/lite/examples/export_models/models/effnet.py b/mindspore/lite/examples/export_models/models/effnet.py index cc550ea62d..497175731b 100755 --- a/mindspore/lite/examples/export_models/models/effnet.py +++ b/mindspore/lite/examples/export_models/models/effnet.py @@ -49,7 +49,6 @@ class Swish(nn.Cell): s = self.sigmoid(x) m = x*s return m - #return x * (1/(1+self.exp(-x))) class AdaptiveAvgPool(nn.Cell): @@ -75,7 +74,6 @@ class SELayer(nn.Cell): self.act2 = nn.Sigmoid() def construct(self, x): - #b, c, _, _ = x.shape() o = self.avg_pool(x) #.view(b,c) o = self.conv_reduce(o) o = self.act1(o) @@ -119,9 +117,6 @@ class DepthwiseSeparableConv(nn.Cell): x = self.bn2(x) if self.has_residual: - # if self.drop_connect_rate > 0.: - # x = x - # x = drop_connect(x, self.training, self.drop_connect_rate) x += residual return x @@ -199,8 +194,6 @@ class InvertedResidual(nn.Cell): x = self.bn3(x) if self.has_residual: - # if self.drop_connect_rate > 0.: - # x = x x += residual return x diff --git a/mindspore/lite/examples/export_models/models/mobilenetv2_train_export.py b/mindspore/lite/examples/export_models/models/mobilenetv2_train_export.py index 2a440d1a12..8f1d5432ac 100644 --- a/mindspore/lite/examples/export_models/models/mobilenetv2_train_export.py +++ b/mindspore/lite/examples/export_models/models/mobilenetv2_train_export.py @@ -25,7 +25,6 @@ from mindspore.train.serialization import export context.set_context(mode=context.PYNATIVE_MODE, device_target="GPU", save_graphs=False) batch = 16 -#n = MobileNetV2() backbone_net = MobileNetV2Backbone() head_net = MobileNetV2Head(input_channel=backbone_net.out_channels, num_classes=10) n = mobilenet_v2(backbone_net, head_net) diff --git a/mindspore/lite/examples/quick_start_cpp/build.sh b/mindspore/lite/examples/quick_start_cpp/build.sh index b0a404d9fe..f0d9324da3 100644 --- a/mindspore/lite/examples/quick_start_cpp/build.sh +++ b/mindspore/lite/examples/quick_start_cpp/build.sh @@ -14,7 +14,7 @@ # limitations under the License. # ============================================================================ -BASEPATH=$(cd "$(dirname $0)"; pwd) +BASEPATH=$(cd "$(dirname $0)" || exit; pwd) get_version() { VERSION_MAJOR=$(grep "const int ms_version_major =" ${BASEPATH}/../../include/version.h | tr -dc "[0-9]") VERSION_MINOR=$(grep "const int ms_version_minor =" ${BASEPATH}/../../include/version.h | tr -dc "[0-9]") @@ -39,6 +39,6 @@ fi tar xzvf ${BASEPATH}/build/${MINDSPORE_FILE} -C ${BASEPATH}/build/ cp -r ${BASEPATH}/build/${MINDSPORE_FILE_NAME}/inference/lib/libmindspore-lite.a ${BASEPATH}/lib cp -r ${BASEPATH}/build/${MINDSPORE_FILE_NAME}/inference/include ${BASEPATH}/ -cd ${BASEPATH}/build +cd ${BASEPATH}/build || exit cmake ${BASEPATH} make diff --git a/mindspore/lite/examples/quick_start_java/build.sh b/mindspore/lite/examples/quick_start_java/build.sh index 78603d874b..0ddc8903ce 100644 --- a/mindspore/lite/examples/quick_start_java/build.sh +++ b/mindspore/lite/examples/quick_start_java/build.sh @@ -14,7 +14,7 @@ # limitations under the License. # ============================================================================ -BASEPATH=$(cd "$(dirname $0)"; pwd) +BASEPATH=$(cd "$(dirname $0)" || exit; pwd) get_version() { VERSION_MAJOR=$(grep "const int ms_version_major =" ${BASEPATH}/../../include/version.h | tr -dc "[0-9]") VERSION_MINOR=$(grep "const int ms_version_minor =" ${BASEPATH}/../../include/version.h | tr -dc "[0-9]") @@ -38,6 +38,6 @@ if [ ! -e ${BASEPATH}/build/${MINDSPORE_FILE} ]; then fi tar xzvf ${BASEPATH}/build/${MINDSPORE_FILE} -C ${BASEPATH}/build/ cp -r ${BASEPATH}/build/${MINDSPORE_FILE_NAME}/inference/lib/jar/* ${BASEPATH}/lib -cd ${BASEPATH}/ +cd ${BASEPATH}/ || exit mvn package diff --git a/mindspore/lite/examples/runtime_cpp/build.sh b/mindspore/lite/examples/runtime_cpp/build.sh index c4e8f6d30a..05bf4c9be7 100644 --- a/mindspore/lite/examples/runtime_cpp/build.sh +++ b/mindspore/lite/examples/runtime_cpp/build.sh @@ -24,7 +24,7 @@ usage() } BASEPATH=$( - cd "$(dirname $0)" + cd "$(dirname $0)" || exit pwd ) get_version() { @@ -94,7 +94,7 @@ cp -r ${BASEPATH}/build/${MINDSPORE_FILE_NAME}/inference/include ${BASEPATH}/ if [[ "X${DEVICE}" == "Xnpu" ]]; then cp -r ${BASEPATH}/build/${MINDSPORE_FILE_NAME}/inference/third_party/hiai_ddk/lib/*.so ${BASEPATH}/lib fi -cd ${BASEPATH}/build +cd ${BASEPATH}/build || exit cmake -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" -DANDROID_NATIVE_API_LEVEL="19" \ -DANDROID_NDK="${ANDROID_NDK}" -DANDROID_ABI="arm64-v8a" -DANDROID_STL="c++_shared" ${BASEPATH} -DSUPPORT_NPU=${SUPPORT_NPU} diff --git a/mindspore/lite/src/common/tensor_util.cc b/mindspore/lite/src/common/tensor_util.cc index 5e492b019f..9e5b13c747 100644 --- a/mindspore/lite/src/common/tensor_util.cc +++ b/mindspore/lite/src/common/tensor_util.cc @@ -208,11 +208,11 @@ int GenerateInTensorC(const OpParameter *const parameter, const std::vector &tensors) { for (auto &tensor : tensors) { if (tensor == nullptr) { - MS_LOG(ERROR) << "check tensor is nullptr"; + MS_LOG(ERROR) << "Graph input tensor is nullptr"; return RET_ERROR; } if (tensor->data_type() != kObjectTypeTensorType && tensor->data_c() == nullptr) { - MS_LOG(ERROR) << "check tensor data is nullptr " << tensors; + MS_LOG(ERROR) << "Graph input tensor is nullptr " << tensors; return RET_ERROR; } auto shape = tensor->shape(); diff --git a/mindspore/lite/src/lite_model.cc b/mindspore/lite/src/lite_model.cc index 5cb3fa8209..1f4194209a 100644 --- a/mindspore/lite/src/lite_model.cc +++ b/mindspore/lite/src/lite_model.cc @@ -255,7 +255,29 @@ int LiteModel::SubGraphVerify() const { return RET_OK; } -bool LiteModel::ModelVerify() const { return NodeVerify() == RET_OK && SubGraphVerify() == RET_OK; } +bool LiteModel::ModelVerify() const { + if (this->sub_graphs_.empty()) { + MS_LOG(ERROR) << "Model does not have a main graph."; + return false; + } + auto main_graph = this->sub_graphs_.front(); + for (auto input_index : main_graph->input_indices_) { + if (input_index >= this->all_tensors_.size()) { + MS_LOG(ERROR) << "Graph indices is beyond tensor_size."; + return false; + } + auto *tensor = this->all_tensors_.at(input_index); + if (tensor == nullptr) { + MS_LOG(ERROR) << "Tensor in all tensors is nullptr."; + return false; + } + if (tensor->format() != schema::Format_NHWC) { + MS_LOG(ERROR) << "Graph input tensor should be NHWC"; + return false; + } + } + return NodeVerify() == RET_OK && SubGraphVerify() == RET_OK; +} const void *LiteModel::GetMetaGraphByVerison() { MS_ASSERT(this->buf != nullptr); diff --git a/mindspore/lite/src/lite_model.h b/mindspore/lite/src/lite_model.h index 7f6edbe571..944de3db38 100644 --- a/mindspore/lite/src/lite_model.h +++ b/mindspore/lite/src/lite_model.h @@ -70,7 +70,11 @@ class LiteModel : public Model { } else if (node->quant_type_ == schema::QuantType_WeightQuant) { node->quant_type_ = schema::QuantType_QUANT_WEIGHT; } - node->name_ = c_node->name()->c_str(); + if (c_node->name() == nullptr) { + node->name_ = ""; + } else { + node->name_ = c_node->name()->c_str(); + } auto count = c_node->inputIndex()->size(); for (uint32_t j = 0; j < count; ++j) { node->input_indices_.push_back(size_t(c_node->inputIndex()->template GetAs(j))); diff --git a/mindspore/lite/src/ops/populate/depthwise_conv2d_populate.cc b/mindspore/lite/src/ops/populate/depthwise_conv2d_populate.cc index 678ff5a685..387561ea23 100644 --- a/mindspore/lite/src/ops/populate/depthwise_conv2d_populate.cc +++ b/mindspore/lite/src/ops/populate/depthwise_conv2d_populate.cc @@ -26,47 +26,6 @@ OpParameter *PopulateConvDwParameter(const void *primitive) { return nullptr; } memset(conv_param, 0, sizeof(ConvParameter)); - // conv_param->op_parameter_.type_ = primitive->Type(); - - // auto conv_primitive = - // reinterpret_cast(const_cast(primitive)); - // conv_param->kernel_h_ = conv_primitive->GetKernelH(); - // conv_param->kernel_w_ = conv_primitive->GetKernelW(); - // conv_param->stride_h_ = conv_primitive->GetStrideH(); - // conv_param->stride_w_ = conv_primitive->GetStrideW(); - - // auto convdw_lite_primitive = (lite::DepthwiseConv2D *)primitive; - // conv_param->pad_u_ = convdw_lite_primitive->PadUp(); - // conv_param->pad_d_ = convdw_lite_primitive->PadDown(); - // conv_param->pad_l_ = convdw_lite_primitive->PadLeft(); - // conv_param->pad_r_ = convdw_lite_primitive->PadRight(); - // conv_param->input_channel_ = convdw_lite_primitive->GetInputChannel(); - // conv_param->dilation_h_ = conv_primitive->GetDilateH(); - // conv_param->dilation_w_ = conv_primitive->GetDilateW(); - // auto pad_mode = conv_primitive->GetPadMode(); - // switch (pad_mode) { - // case schema::PadMode_SAME_UPPER: - // conv_param->pad_mode_ = Pad_Same; - // break; - // case schema::PadMode_VALID: - // conv_param->pad_mode_ = Pad_Valid; - // break; - // default: - // conv_param->pad_mode_ = Pad_No; - // break; - // } - // auto act_type = conv_primitive->GetActivationType(); - // switch (act_type) { - // case schema::ActivationType_RELU: - // conv_param->act_type_ = ActType_Relu; - // break; - // case schema::ActivationType_RELU6: - // conv_param->act_type_ = ActType_Relu6; - // break; - // default: - // conv_param->act_type_ = ActType_No; - // break; - // } return reinterpret_cast(conv_param); } } // namespace lite diff --git a/mindspore/lite/src/ops/populate/mul_populate.cc b/mindspore/lite/src/ops/populate/mul_populate.cc index 609b4b9573..a9061be48c 100644 --- a/mindspore/lite/src/ops/populate/mul_populate.cc +++ b/mindspore/lite/src/ops/populate/mul_populate.cc @@ -29,8 +29,6 @@ OpParameter *PopulateMulParameter(const void *prim) { } auto *primitive = static_cast(prim); param->op_parameter_.type_ = primitive->value_type(); - // auto mul_prim = primitive->value_as_Mul(); - // param->activation_type_ = mul_prim->activationType(); return reinterpret_cast(param); } } // namespace diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/convolution.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/convolution.cc index 51328f54e4..7687ea6aff 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/convolution.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/convolution.cc @@ -115,8 +115,6 @@ int ConvolutionTrainCPUKernel::Execute(int task_id) { for (int j = 0; j < groups; ++j) { const float *mat_b = w_addr + j * nweights / groups; float *mat_c = y_addr + (i * groups) * n * m + j * (out_ch / groups) + ci * out_ch; - // float *im = x_addr + i * in_ch * in_h * in_w + j * (in_ch / groups); - // RollingIm2ColPackUnitFp32(im, conv_param_, mat_a, real_chunk, ci); GemmMatmul(0, 1, real_chunk, n, k, 1, mat_a + (j * kernel_spatial), k * groups, mat_b, k, 0, mat_c, out_ch, mat_workspace); } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/layernorm_grad.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/layernorm_grad.cc index dd9e70cbbd..e36b9cd282 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/layernorm_grad.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/layernorm_grad.cc @@ -21,6 +21,7 @@ #include "src/kernel_registry.h" #include "nnacl/fp32_grad/layernorm_grad.h" #include "nnacl/fp32_grad/layernormgrad_parameter.h" +#include "nnacl/errorcode.h" #include "include/errorcode.h" #include "src/runtime/runtime_api.h" @@ -81,7 +82,11 @@ int LayerNormGradCPUKernel::Execute(int task_id) { float *dx = reinterpret_cast(output_dx->MutableData()); float *dg = reinterpret_cast(output_dg->MutableData()); float *db = reinterpret_cast(output_db->MutableData()); - LayerNormGrad(x, dy, var, mean, gamma, param_num_, param_size_, block_num_, block_size_, dx, dg, db); + int ret = LayerNormGrad(x, dy, var, mean, gamma, param_num_, param_size_, block_num_, block_size_, dx, dg, db); + if (ret != NNACL_OK) { + MS_LOG(ERROR) << "LayerNormGrad error task_id[" << task_id << "] error_code[" << ret << "]"; + return RET_ERROR; + } return RET_OK; } diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/conv2d.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/conv2d.cc index 031d512f68..2ad1b9ca07 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/conv2d.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/conv2d.cc @@ -278,7 +278,7 @@ void Conv2DOpenCLKernel::InitFilter() { allocator->UnmapBuffer(packed_filter_); } - FreeTmpWeight(in_tensors_.at(kWeightIndex)->data_c()); + FreeTmpWeight(in_tensors_.at(kWeightIndex)); } void Conv2DOpenCLKernel::InitBias() { @@ -315,7 +315,7 @@ void Conv2DOpenCLKernel::InitBias() { } } allocator->UnmapBuffer(packed_bias_); - FreeTmpWeight(in_tensors_.at(kBiasIndex)->data_c()); + FreeTmpWeight(in_tensors_.at(kBiasIndex)); } void Conv2DOpenCLKernel::SetConstArgs() { diff --git a/mindspore/lite/src/runtime/kernel/opencl/utils.cc b/mindspore/lite/src/runtime/kernel/opencl/utils.cc index 0abc134cfb..7f6fa1f87a 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/utils.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/utils.cc @@ -300,7 +300,7 @@ static std::set tmp_weights; void StoreTmpWeight(lite::Tensor *tensor) { MS_LOG(WARNING) << "store weight when kernel don't infer shape!"; - if (tensor != nullptr && tensor->data_c() != nullptr && tensor->Size() > 0) { + if ((tensor != nullptr) && (tensor->data_c() != nullptr) && (tensor->Size() > 0)) { void *new_data = malloc(tensor->Size()); MS_ASSERT(new_data); if (new_data == nullptr) { @@ -312,10 +312,13 @@ void StoreTmpWeight(lite::Tensor *tensor) { } } -void FreeTmpWeight(void *data) { +void FreeTmpWeight(lite::Tensor *tensor) { + MS_ASSERT(tensor != nullptr); + auto data = tensor->data_c(); if (tmp_weights.count(data)) { tmp_weights.erase(data); free(data); + tensor->set_data(nullptr); } } diff --git a/mindspore/lite/src/runtime/kernel/opencl/utils.h b/mindspore/lite/src/runtime/kernel/opencl/utils.h index 6a8dcaad27..e7bbd275f2 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/utils.h +++ b/mindspore/lite/src/runtime/kernel/opencl/utils.h @@ -64,7 +64,7 @@ int CheckParamLikeTensor(const std::string &kernel_name, const std::string &tens TypeId expect_data_type, const std::vector &expect_shape); void StoreTmpWeight(lite::Tensor *tensor); -void FreeTmpWeight(void *tensor); +void FreeTmpWeight(lite::Tensor *tensor); template void PackNCHWToNC4HW4(void *src, void *dst, int batch, int plane_in, int plane_out, int channel, diff --git a/mindspore/lite/src/tensorlist.cc b/mindspore/lite/src/tensorlist.cc index cf434d398c..fe39775723 100644 --- a/mindspore/lite/src/tensorlist.cc +++ b/mindspore/lite/src/tensorlist.cc @@ -142,6 +142,9 @@ int TensorList::MallocData(const mindspore::Allocator *allocator) { void TensorList::FreeData() { // free data buf of each tensor in tensors_ for (auto tensor : tensors_) { + if (tensor == nullptr) { + continue; + } tensor->FreeData(); } } @@ -274,7 +277,11 @@ STATUS TensorList::Decode(const int *data) { element_shape_.push_back(data[2 + j]); } int tensors_num = data[2 + data[1]]; - tensors_.resize(tensors_num); + if (this->ElementsNum() != tensors_num) { + MS_LOG(WARNING) << "Input tensorlist data is invalid: shape size(" << this->ElementsNum() << ") != tensors_num(" + << tensors_num << ")."; + } + tensors_.reserve(tensors_num); int tensor_index = 2 + data[1] + 1; for (int i = 0; i < tensors_num; i++) { int tensor_dims_size = data[tensor_index++]; @@ -282,11 +289,12 @@ STATUS TensorList::Decode(const int *data) { for (int j = 0; j < tensor_dims_size; j++) { shape[j] = data[tensor_index++]; } - tensors_[i] = new (std::nothrow) Tensor(tensors_data_type_, shape); - if (tensors_[i] == nullptr) { + auto tensor = new (std::nothrow) Tensor(tensors_data_type_, shape); + if (tensor == nullptr) { MS_LOG(ERROR) << "new Tensor failed"; return RET_NULL_PTR; } + tensors_.emplace_back(tensor); } return RET_OK; } diff --git a/mindspore/lite/tools/anf_exporter/anf_exporter.cc b/mindspore/lite/tools/anf_exporter/anf_exporter.cc index 7ba679991b..c26969758b 100644 --- a/mindspore/lite/tools/anf_exporter/anf_exporter.cc +++ b/mindspore/lite/tools/anf_exporter/anf_exporter.cc @@ -753,7 +753,7 @@ int AnfExporter::ProcessTensor(const ValueNodePtr &value_node, std::unique_ptrSize() > 0) { - if (memcpy_s((*schema_tensor)->data.data(), data->Size(), data->data_c(), data->Size()) != EOK) { + if (memcpy_s((*schema_tensor)->data.data(), (*schema_tensor)->data.size(), data->data_c(), data->Size()) != EOK) { MS_LOG(ERROR) << "memcpy_s error."; return RET_ERROR; } diff --git a/mindspore/lite/tools/converter/converter_context.h b/mindspore/lite/tools/converter/converter_context.h index 397b7dd5a8..24e13f7c96 100644 --- a/mindspore/lite/tools/converter/converter_context.h +++ b/mindspore/lite/tools/converter/converter_context.h @@ -28,7 +28,6 @@ namespace mindspore { namespace lite { class ReturnCode { public: - virtual ~ReturnCode() = default; static ReturnCode *GetSingleReturnCode() { static ReturnCode return_code; return &return_code; @@ -42,12 +41,12 @@ class ReturnCode { private: ReturnCode() = default; + virtual ~ReturnCode() = default; int status_code_ = RET_OK; }; class NotSupportOp { public: - virtual ~NotSupportOp() = default; static NotSupportOp *GetInstance() { static NotSupportOp not_support_op; return ¬_support_op; @@ -67,13 +66,13 @@ class NotSupportOp { private: NotSupportOp() = default; + virtual ~NotSupportOp() = default; std::set not_support_ops_; std::string fmk_type_; }; class TensorDataType { public: - ~TensorDataType() = default; static TensorDataType *GetInstance() { static TensorDataType tensor_data_type; return &tensor_data_type; @@ -88,6 +87,7 @@ class TensorDataType { private: TensorDataType() {} + virtual ~TensorDataType() = default; std::map tensor_data_type_map_; }; } // namespace lite diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_node_parser_registry.h b/mindspore/lite/tools/converter/parser/caffe/caffe_node_parser_registry.h index a824ce59ac..1c1b844341 100644 --- a/mindspore/lite/tools/converter/parser/caffe/caffe_node_parser_registry.h +++ b/mindspore/lite/tools/converter/parser/caffe/caffe_node_parser_registry.h @@ -25,15 +25,16 @@ namespace mindspore::lite { class CaffeNodeParserRegistry { public: - CaffeNodeParserRegistry(); - - virtual ~CaffeNodeParserRegistry(); - static CaffeNodeParserRegistry *GetInstance(); CaffeNodeParser *GetNodeParser(const std::string &name); std::unordered_map parsers; + + private: + CaffeNodeParserRegistry(); + + virtual ~CaffeNodeParserRegistry(); }; class CaffeNodeRegistrar { 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 8566481d86..81054a92de 100644 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_model_parser.cc +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_model_parser.cc @@ -1127,7 +1127,7 @@ STATUS OnnxModelParser::CopyOnnxTensorData(const onnx::TensorProto &onnx_const_t return RET_MEMORY_FAILED; } auto tensor_data = reinterpret_cast(tensor_info->data_c()); - if (memcpy_s(tensor_data, data_size, onnx_data, data_size) != EOK) { + if (memcpy_s(tensor_data, tensor_info->data().nbytes(), onnx_data, data_size) != EOK) { MS_LOG(ERROR) << "memcpy_s failed"; return RET_ERROR; } diff --git a/mindspore/lite/tools/converter/parser/onnx/onnx_node_parser_registry.h b/mindspore/lite/tools/converter/parser/onnx/onnx_node_parser_registry.h index 3436f7a7ff..a39ff4605d 100644 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_node_parser_registry.h +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_node_parser_registry.h @@ -25,15 +25,16 @@ namespace mindspore { namespace lite { class OnnxNodeParserRegistry { public: - OnnxNodeParserRegistry(); - - virtual ~OnnxNodeParserRegistry(); - static OnnxNodeParserRegistry *GetInstance(); OnnxNodeParser *GetNodeParser(const std::string &name); std::unordered_map parsers; + + private: + OnnxNodeParserRegistry(); + + virtual ~OnnxNodeParserRegistry(); }; class OnnxNodeRegistrar { diff --git a/mindspore/lite/tools/converter/parser/tf/tf_node_parser_registry.h b/mindspore/lite/tools/converter/parser/tf/tf_node_parser_registry.h index bec92021ad..142c99b061 100644 --- a/mindspore/lite/tools/converter/parser/tf/tf_node_parser_registry.h +++ b/mindspore/lite/tools/converter/parser/tf/tf_node_parser_registry.h @@ -25,14 +25,16 @@ namespace mindspore { namespace lite { class TFNodeParserRegistry { public: - TFNodeParserRegistry() = default; - - virtual ~TFNodeParserRegistry(); - static TFNodeParserRegistry *GetInstance(); + TFNodeParser *GetNodeParser(const std::string &name); std::unordered_map parsers; + + private: + TFNodeParserRegistry() = default; + + virtual ~TFNodeParserRegistry(); }; class TFNodeRegistrar { diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser_registry.h b/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser_registry.h index 9332ad94c3..dea88cb5dd 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser_registry.h +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser_registry.h @@ -25,15 +25,16 @@ namespace mindspore { namespace lite { class TfliteNodeParserRegistry { public: - TfliteNodeParserRegistry(); - - virtual ~TfliteNodeParserRegistry(); - static TfliteNodeParserRegistry *GetInstance(); TfliteNodeParser *GetNodeParser(const tflite::BuiltinOperator &type); std::unordered_map parsers; + + private: + TfliteNodeParserRegistry(); + + virtual ~TfliteNodeParserRegistry(); }; class TfliteNodeRegister { diff --git a/mindspore/lite/tools/optimizer/fusion/conv_transform_fusion.cc b/mindspore/lite/tools/optimizer/fusion/conv_transform_fusion.cc index 148ffbc24f..ee1c0d23d2 100644 --- a/mindspore/lite/tools/optimizer/fusion/conv_transform_fusion.cc +++ b/mindspore/lite/tools/optimizer/fusion/conv_transform_fusion.cc @@ -52,6 +52,7 @@ int GetOutChannels(const CNodePtr &conv_node) { void GenerateNewWeightConv2D(float *dst_weight, const float *conv_weight, const float *scale_weight, FmkType fmk, int weight_shape_size, int kernel_num) { + MS_ASSERT(kernel_num > 0); if (dst_weight == nullptr || conv_weight == nullptr || scale_weight == nullptr) { return; } @@ -60,7 +61,6 @@ void GenerateNewWeightConv2D(float *dst_weight, const float *conv_weight, const dst_weight[i] = conv_weight[i] * scale_weight[i % kernel_num]; } } else { - MS_ASSERT(kernel_num > 0); auto kernel_size = weight_shape_size / kernel_num; for (int i = 0; i < kernel_num; i++) { for (int j = 0; j < kernel_size; j++) { @@ -75,6 +75,7 @@ void GenerateNewWeightConv2DTranspose(float *dst_weight, const float *scale_weig if (dst_weight == nullptr || scale_weight == nullptr || weight_tensor == nullptr) { return; } + MS_ASSERT(group > 0); auto weight_data = reinterpret_cast(weight_tensor->data_c()); if (fmk == lite::converter::FmkType_TF) { auto cin_group = weight_tensor->shape()[3] / group; diff --git a/model_zoo/official/lite/MindSpore_inhand/imageObject/src/main/cpp/SceneMindSporeNetnative.cpp b/model_zoo/official/lite/MindSpore_inhand/imageObject/src/main/cpp/SceneMindSporeNetnative.cpp index e348551c48..e5170c0d53 100644 --- a/model_zoo/official/lite/MindSpore_inhand/imageObject/src/main/cpp/SceneMindSporeNetnative.cpp +++ b/model_zoo/official/lite/MindSpore_inhand/imageObject/src/main/cpp/SceneMindSporeNetnative.cpp @@ -66,7 +66,6 @@ std::string SceneProcessRunnetResult(const int RET_CATEGORY_SUM, // Get a pointer to the first score. float *temp_scores = static_cast(outputTensor->MutableData()); - // float scores[RET_CATEGORY_SUM]; float scores = temp_scores[0]; int cat_loc = 0; for (int i = 0; i < RET_CATEGORY_SUM; ++i) { diff --git a/model_zoo/official/lite/MindSpore_inhand/segmentation/src/main/java/com/mindspore/imagesegmentation/StyleRecyclerViewAdapter.java b/model_zoo/official/lite/MindSpore_inhand/segmentation/src/main/java/com/mindspore/imagesegmentation/StyleRecyclerViewAdapter.java index a48906b4e3..3808957595 100644 --- a/model_zoo/official/lite/MindSpore_inhand/segmentation/src/main/java/com/mindspore/imagesegmentation/StyleRecyclerViewAdapter.java +++ b/model_zoo/official/lite/MindSpore_inhand/segmentation/src/main/java/com/mindspore/imagesegmentation/StyleRecyclerViewAdapter.java @@ -46,9 +46,6 @@ public class StyleRecyclerViewAdapter extends RecyclerView.Adapter { diff --git a/model_zoo/official/lite/MindSpore_inhand/segmentation/src/main/java/com/mindspore/imagesegmentation/help/TrackingMobile.java b/model_zoo/official/lite/MindSpore_inhand/segmentation/src/main/java/com/mindspore/imagesegmentation/help/TrackingMobile.java index b5be44e6f6..cc98541af4 100644 --- a/model_zoo/official/lite/MindSpore_inhand/segmentation/src/main/java/com/mindspore/imagesegmentation/help/TrackingMobile.java +++ b/model_zoo/official/lite/MindSpore_inhand/segmentation/src/main/java/com/mindspore/imagesegmentation/help/TrackingMobile.java @@ -111,7 +111,6 @@ public class TrackingMobile { ByteBuffer contentArray = BitmapUtils.bitmapToByteBuffer(scaledBitmap, imageSize, imageSize, IMAGE_MEAN, IMAGE_STD); MSTensor inTensor = inputs.get(0); - // int byteLen = (int) inTensor.size(); inTensor.setData(contentArray); // Run graph to infer results. diff --git a/model_zoo/official/lite/image_segmentation/app/src/main/java/com/mindspore/imagesegmentation/help/TrackingMobile.java b/model_zoo/official/lite/image_segmentation/app/src/main/java/com/mindspore/imagesegmentation/help/TrackingMobile.java index 50fe28635f..b48c5f00c9 100644 --- a/model_zoo/official/lite/image_segmentation/app/src/main/java/com/mindspore/imagesegmentation/help/TrackingMobile.java +++ b/model_zoo/official/lite/image_segmentation/app/src/main/java/com/mindspore/imagesegmentation/help/TrackingMobile.java @@ -111,7 +111,6 @@ public class TrackingMobile { ByteBuffer contentArray = BitmapUtils.bitmapToByteBuffer(scaledBitmap, imageSize, imageSize, IMAGE_MEAN, IMAGE_STD); MSTensor inTensor = inputs.get(0); - // int byteLen = (int) inTensor.size(); inTensor.setData(contentArray); // Run graph to infer results. diff --git a/model_zoo/official/lite/scene_detection/app/src/main/cpp/MindSporeNetnative.cpp b/model_zoo/official/lite/scene_detection/app/src/main/cpp/MindSporeNetnative.cpp index 463d171a83..e38b967d55 100644 --- a/model_zoo/official/lite/scene_detection/app/src/main/cpp/MindSporeNetnative.cpp +++ b/model_zoo/official/lite/scene_detection/app/src/main/cpp/MindSporeNetnative.cpp @@ -235,7 +235,6 @@ std::string ProcessRunnetResult(const int RET_CATEGORY_SUM, const char *const la // Get a pointer to the first score. float *temp_scores = static_cast(outputTensor->MutableData()); - // float scores[RET_CATEGORY_SUM]; float scores = temp_scores[0]; int cat_loc = 0; for (int i = 0; i < RET_CATEGORY_SUM; ++i) { diff --git a/model_zoo/official/lite/style_transfer/app/src/main/java/com/mindspore/styletransferdemo/StyleTransferModelExecutor.java b/model_zoo/official/lite/style_transfer/app/src/main/java/com/mindspore/styletransferdemo/StyleTransferModelExecutor.java index 7dd5e6e29f..caf369dc33 100644 --- a/model_zoo/official/lite/style_transfer/app/src/main/java/com/mindspore/styletransferdemo/StyleTransferModelExecutor.java +++ b/model_zoo/official/lite/style_transfer/app/src/main/java/com/mindspore/styletransferdemo/StyleTransferModelExecutor.java @@ -127,20 +127,16 @@ public class StyleTransferModelExecutor { } @SuppressLint("LongLogTag") -// public ModelExecutionResult execute(String contentImagePath, String styleImageName) { public ModelExecutionResult execute(Bitmap contentImage, Bitmap styleBitmap) { Log.i(TAG, "running models"); fullExecutionTime = SystemClock.uptimeMillis(); preProcessTime = SystemClock.uptimeMillis(); -// Bitmap contentImage = ImageUtils.decodeBitmap(new File(contentImagePath)); ByteBuffer contentArray = ImageUtils.bitmapToByteBuffer(contentImage, CONTENT_IMAGE_SIZE, CONTENT_IMAGE_SIZE, 0, 255); -// Bitmap styleBitmap = -// ImageUtils.loadBitmapFromResources(context, "thumbnails/" + styleImageName); ByteBuffer input = ImageUtils.bitmapToByteBuffer(styleBitmap, STYLE_IMAGE_SIZE, STYLE_IMAGE_SIZE, 0, 255);