diff --git a/mindspore/lite/src/ops/conv2d.cc b/mindspore/lite/src/ops/conv2d.cc index d28618cee9..098b367fa6 100644 --- a/mindspore/lite/src/ops/conv2d.cc +++ b/mindspore/lite/src/ops/conv2d.cc @@ -219,8 +219,8 @@ void Conv2D::PopulaterConv2DSingleGroup(const Primitive &prim, schema::Primitive attr->padRight = pad_list[3]; auto dilation = CastToInt(prim.GetAttr("dilation"), true); - attr->dilateH = dilation[0]; - attr->dilateW = dilation[1]; + attr->dilateH = dilation[2]; + attr->dilateW = dilation[3]; auto kernel_size = CastToInt(prim.GetAttr("kernel_size"), true); attr->kernelH = kernel_size[0]; diff --git a/mindspore/lite/src/ops/primitive_c.cc b/mindspore/lite/src/ops/primitive_c.cc index 5916be5cc5..accf6c8b6a 100644 --- a/mindspore/lite/src/ops/primitive_c.cc +++ b/mindspore/lite/src/ops/primitive_c.cc @@ -191,7 +191,7 @@ std::vector CastToInt(const ValuePtr value, bool is_vector) { MS_LOG(WARNING) << "valueptr is not a sequence, value may be a scalar."; return {}; } - if (value->cast()->value().front()->type()->type_name() == "Int64Imm") { + if (value->cast()->value().front()->type()->number_type() == kNumberTypeInt64) { auto origin_value = GetValue>(value); for (size_t index = 0; index < origin_value.size(); ++index) { cur_value.push_back(static_cast(origin_value[index])); @@ -200,7 +200,7 @@ std::vector CastToInt(const ValuePtr value, bool is_vector) { cur_value = GetValue>(value); } } else { - if (value->type_name() == "Int64Imm") { + if (value->type()->number_type() == kNumberTypeInt64) { cur_value.push_back(static_cast(GetValue(value))); } else { cur_value.push_back(GetValue(value)); @@ -321,9 +321,9 @@ void PrimitiveC::GetAttrDataFromInput(const AnfNodePtr inputNode, std::vectorcast(); MS_ASSERT(tuple != nullptr); for (size_t i = 0; i < tuple->size(); i++) { - auto elem = tuple->value()[i]->cast(); + auto elem = tuple->value()[i]; MS_ASSERT(elem != nullptr); - data->emplace_back(static_cast(elem->value())); + data->emplace_back(CastToInt(elem, false).front()); } } } @@ -556,6 +556,10 @@ std::shared_ptr PrimitiveC::Create(const Primitive &prim, const std: return NewPrimitiveC(prim, inputs, quantType); } else if (op_type == "UnsortedSegmentSum") { return NewPrimitiveC(prim, inputs, quantType); + } else if (op_type == "ResizeNearestNeighbor") { + return NewPrimitiveC(prim, inputs, quantType); + } else if (op_type == "ResizeBilinear") { + return NewPrimitiveC(prim, inputs, quantType); #ifdef SUPPORT_TRAIN } else if (op_type == "SoftmaxCrossEntropyWithLogits") { diff --git a/mindspore/lite/src/ops/reshape.cc b/mindspore/lite/src/ops/reshape.cc index 4203375265..bd2a429a64 100644 --- a/mindspore/lite/src/ops/reshape.cc +++ b/mindspore/lite/src/ops/reshape.cc @@ -58,9 +58,9 @@ int Reshape::UnPackAttr(const Primitive &prim, const std::vector &in auto tuple = val->cast(); MS_ASSERT(tuple != nullptr); for (size_t i = 0; i < tuple->size(); ++i) { - auto elem = tuple->value()[i]->cast(); + auto elem = tuple->value()[i]; MS_ASSERT(elem != nullptr); - attr->shape.emplace_back(static_cast(elem->value())); + attr->shape.emplace_back(CastToInt(elem, false).front()); } } else { int dim = CastToInt(val, false).front(); diff --git a/mindspore/lite/src/ops/transpose.cc b/mindspore/lite/src/ops/transpose.cc index 1c1dc46ec3..f11b3703b8 100644 --- a/mindspore/lite/src/ops/transpose.cc +++ b/mindspore/lite/src/ops/transpose.cc @@ -62,9 +62,9 @@ int Transpose::UnPackAttr(const Primitive &prim, const std::vector & auto tuple = val->cast(); MS_ASSERT(tuple != nullptr); for (size_t i = 0; i < tuple->size(); i++) { - auto elem = tuple->value()[i]->cast(); + auto elem = tuple->value()[i]; MS_ASSERT(elem != nullptr); - attr->perm.emplace_back(static_cast(elem->value())); + attr->perm.emplace_back(CastToInt(elem, false).front()); } } } diff --git a/mindspore/lite/src/runtime/kernel/arm/base/split_base.h b/mindspore/lite/src/runtime/kernel/arm/base/split_base.h index f1bfa9a7a0..dbb9a8447c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/split_base.h +++ b/mindspore/lite/src/runtime/kernel/arm/base/split_base.h @@ -32,7 +32,12 @@ class SplitBaseCPUKernel : public LiteKernel { : LiteKernel(parameter, inputs, outputs, ctx, primitive), ctx_(ctx), thread_count_(ctx->thread_num_) { param = reinterpret_cast(op_parameter_); } - ~SplitBaseCPUKernel() = default; + ~SplitBaseCPUKernel() override { + if (param != nullptr && param->split_sizes_ != nullptr) { + free(param->split_sizes_); + param->split_sizes_ = nullptr; + } + } int Init() override; int ReSize() override; diff --git a/mindspore/lite/test/models_onnx.cfg b/mindspore/lite/test/models_onnx.cfg index 04e9248fc0..2ce2c6d825 100644 --- a/mindspore/lite/test/models_onnx.cfg +++ b/mindspore/lite/test/models_onnx.cfg @@ -31,3 +31,4 @@ mosaic-9.onnx pointilism-9.onnx rain-princess-9.onnx udnie-9.onnx +adversarial_pruning.onnx diff --git a/mindspore/lite/test/models_only_for_process.cfg b/mindspore/lite/test/models_with_several_inputs_or_without_outputs.cfg similarity index 100% rename from mindspore/lite/test/models_only_for_process.cfg rename to mindspore/lite/test/models_with_several_inputs_or_without_outputs.cfg diff --git a/mindspore/lite/test/run_benchmark_nets.sh b/mindspore/lite/test/run_benchmark_nets.sh index 581b3a3935..8509a7624c 100644 --- a/mindspore/lite/test/run_benchmark_nets.sh +++ b/mindspore/lite/test/run_benchmark_nets.sh @@ -220,13 +220,13 @@ function Run_Converter() { fi done < ${models_mindspore_mixbit_config} - # Convert models which do not need to be cared about the accuracy: + # Convert models which has several inputs or does not need to be cared about the accuracy: while read line; do - model_name=${line} - model_type=${line##*.} - if [[ $model_name == \#* ]] || [[ $model_type == \#* ]]; then + if [[ $line == \#* ]]; then continue fi + model_name=${line%%;*} + model_type=${model_name##*.} case $model_type in tflite) model_fmk="TFLITE" @@ -462,17 +462,37 @@ function Run_x86() { fi done < ${models_mindspore_mixbit_config} - # Run converted models which do not need to be cared about the accuracy: + # Run converted models which has several inputs or does not need to be cared about the accuracy: while read line; do - model_name=${line} - if [[ ${line##*.} == "caffemodel" ]]; then - model_name=${line%.*} + if [[ $line == \#* ]]; then + continue + fi + model_name=${line%%;*} + model_name_len=${#model_name} + input_params=${line:model_name_len+1} + input_num=${input_params%%;*} + input_shape=${input_params##*;} + input_files='' + output_file='' + if [[ -z "$input_files" || $input_files == 1 ]] && [ -e ${ms_models_path}/${model_name}'.ms.bin' ]; then + input_files=$model_name'.ms.bin' + elif [[ ! -z "$input_files" && $input_files > 1 ]]; then + for i in $(seq 1 $input_num) + do + input_files=$input_files$model_name'.ms.bin_'$i',' + done + fi + if [ -e ${ms_models_path}/${model_name}'.ms.out' ]; then + output_file=${ms_models_path}/${model_name}'.ms.out' + fi + if [[ ${model_name##*.} == "caffemodel" ]]; then + model_name=${model_name%.*} fi echo ${model_name} >> "${run_x86_log_file}" echo 'cd '${x86_path}'/mindspore-lite-'${version}'-runtime-x86-'${process_unit_x86} >> "{run_x86_log_file}" cd ${x86_path}/mindspore-lite-${version}-runtime-x86-${process_unit_x86} || return 1 - echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:./lib:./third_party/libjpeg-turbo/lib:./third_party/opencv/lib;./benchmark/benchmark --modelFile='${ms_models_path}'/'${model_name}'.ms --loopCount=1 --warmUpLoopCount=0' >> "${run_x86_log_file}" - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:./lib:./third_party/libjpeg-turbo/lib:./third_party/opencv/lib;./benchmark/benchmark --modelFile=${ms_models_path}/${model_name}.ms --loopCount=1 --warmUpLoopCount=0 >> "${run_x86_log_file}" + echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:./lib:./third_party/libjpeg-turbo/lib:./third_party/opencv/lib;./benchmark/benchmark --modelFile='${ms_models_path}'/'${model_name}'.ms --inDataFile='${input_files}' --benchmarkDataFile='${output_file}' --loopCount=1 --warmUpLoopCount=0' >> "${run_x86_log_file}" + export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:./lib:./third_party/libjpeg-turbo/lib:./third_party/opencv/lib;./benchmark/benchmark --modelFile=${ms_models_path}/${model_name}.ms --inDataFile=${input_files} --benchmarkDataFile=${output_file} --loopCount=1 --warmUpLoopCount=0 >> "${run_x86_log_file}" if [ $? = 0 ]; then run_result='x86: '${model_name}' pass'; echo ${run_result} >> ${run_benchmark_result_file} else @@ -690,17 +710,34 @@ function Run_x86_sse() { fi done < ${models_mindspore_mixbit_config} - # Run converted models which do not need to be cared about the accuracy: + # Run converted models which has several inputs or does not need to be cared about the accuracy: while read line; do - model_name=${line} - if [[ ${line##*.} == "caffemodel" ]]; then - model_name=${line%.*} + model_name=${line%%;*} + model_name_len=${#model_name} + input_params=${line:model_name_len+1} + input_num=${input_params%%;*} + input_shape=${input_params##*;} + input_files='' + output_file='' + if [[ -z "$input_files" || $input_files == 1 ]] && [ -e ${ms_models_path}/${model_name}'.ms.bin' ]; then + input_files=$model_name'.ms.bin' + elif [[ ! -z "$input_files" && $input_files > 1 ]]; then + for i in $(seq 1 $input_num) + do + input_files=$input_files$model_name'.ms.bin_'$i',' + done + fi + if [ -e ${ms_models_path}/${model_name}'.ms.out' ]; then + output_file=${ms_models_path}/${model_name}'.ms.out' + fi + if [[ ${model_name##*.} == "caffemodel" ]]; then + model_name=${model_name%.*} fi echo ${model_name} >> "${run_x86_sse_log_file}" echo 'cd '${x86_path}'/mindspore-lite-'${version}'-runtime-x86-sse-'${process_unit_x86} >> "{run_x86_sse_log_file}" cd ${x86_path}/mindspore-lite-${version}-runtime-x86-sse-${process_unit_x86} || return 1 - echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:./lib:./third_party/libjpeg-turbo/lib:./third_party/opencv/lib;./benchmark/benchmark --modelFile='${ms_models_path}'/'${model_name}'.ms --loopCount=1 --warmUpLoopCount=0' >> "${run_x86_sse_log_file}" - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:./lib:./third_party/libjpeg-turbo/lib:./third_party/opencv/lib;./benchmark/benchmark --modelFile=${ms_models_path}/${model_name}.ms --loopCount=1 --warmUpLoopCount=0 >> "${run_x86_sse_log_file}" + echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:./lib:./third_party/libjpeg-turbo/lib:./third_party/opencv/lib;./benchmark/benchmark --modelFile='${ms_models_path}'/'${model_name}'.ms --inDataFile='${input_files}' --benchmarkDataFile='${output_file}' --loopCount=1 --warmUpLoopCount=0' >> "${run_x86_sse_log_file}" + export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:./lib:./third_party/libjpeg-turbo/lib:./third_party/opencv/lib;./benchmark/benchmark --modelFile=${ms_models_path}/${model_name}.ms --inDataFile=${input_files} --benchmarkDataFile=${output_file} --loopCount=1 --warmUpLoopCount=0 >> "${run_x86_sse_log_file}" if [ $? = 0 ]; then run_result='x86_sse: '${model_name}' pass'; echo ${run_result} >> ${run_benchmark_result_file} else @@ -1083,6 +1120,41 @@ function Run_arm64() { run_result='arm64: '${model_name}'_train failed'; echo ${run_result} >> ${run_benchmark_result_file}; return 1 fi done < ${models_mindspore_weightquant_config} + + # Run converted models which has several inputs or does not need to be cared about the accuracy: + while read line; do + model_name=${line%%;*} + model_name_len=${#model_name} + input_params=${line:model_name_len+1} + input_num=${input_params%%;*} + input_shape=${input_params##*;} + input_files='' + output_file='' + if [[ -z "$input_files" || $input_files == 1 ]] && [ -e ${ms_models_path}/${model_name}'.ms.bin' ]; then + input_files=$model_name'.ms.bin' + elif [[ ! -z "$input_files" && $input_files > 1 ]]; then + for i in $(seq 1 $input_num) + do + input_files=$input_files$model_name'.ms.bin_'$i',' + done + fi + if [ -e ${ms_models_path}/${model_name}'.ms.out' ]; then + output_file=${ms_models_path}/${model_name}'.ms.out' + fi + if [[ ${model_name##*.} == "caffemodel" ]]; then + model_name=${model_name%.*} + fi + echo ${model_name} >> "${run_arm64_log_file}" + echo 'cd /data/local/tmp/benchmark_test' > adb_run_cmd.txt + echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/data/local/tmp/benchmark_test;./benchmark --modelFile='${model_name}'.ms --inDataFile='${input_files}' --benchmarkDataFile='${output_file} >> "${run_arm64_log_file}" + echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/data/local/tmp/benchmark_test;./benchmark --modelFile='${model_name}'.ms --inDataFile='${input_files}' --benchmarkDataFile='${output_file} >> adb_run_cmd.txt + adb -s ${device_id} shell < adb_run_cmd.txt >> "${run_arm64_log_file}" + if [ $? = 0 ]; then + run_result='arm64: '${model_name}' pass'; echo ${run_result} >> ${run_benchmark_result_file} + else + run_result='arm64: '${model_name}' failed'; echo ${run_result} >> ${run_benchmark_result_file}; return 1 + fi + done < ${models_only_for_process_config} } # Run on arm32 platform: @@ -1229,7 +1301,7 @@ models_mindspore_weightquant_config=${basepath}/models_mindspore_weightquant.cfg models_fp16_gpu_config=${basepath}/models_fp16_gpu.cfg models_arm32_config=${basepath}/models_arm32.cfg models_compatibility_config=${basepath}/models_compatibility.cfg -models_only_for_process_config=${basepath}/models_only_for_process.cfg +models_only_for_process_config=${basepath}/models_with_several_inputs_or_without_outputs.cfg ms_models_path=${basepath}/ms_models diff --git a/mindspore/lite/tools/anf_exporter/anf_exporter.cc b/mindspore/lite/tools/anf_exporter/anf_exporter.cc index 7a10f903d4..7ce2a813b1 100644 --- a/mindspore/lite/tools/anf_exporter/anf_exporter.cc +++ b/mindspore/lite/tools/anf_exporter/anf_exporter.cc @@ -313,10 +313,10 @@ int AnfExporter::ConvertInputCNode(const std::shared_ptr input_anode, s MS_LOG(ERROR) << "cast to ValueNode failed"; return RET_ERROR; } - auto input_index_key = - get_item_input_cnode->fullname_with_scope() + "_o:" + - std::to_string(value_node->value()->type_name() == "Int64Imm" ? GetValue(value_node->value()) - : GetValue(value_node->value())); + auto input_index_key = get_item_input_cnode->fullname_with_scope() + "_o:" + + std::to_string(value_node->value()->type()->number_type() == kNumberTypeInt64 + ? GetValue(value_node->value()) + : GetValue(value_node->value())); auto iter = node_id_map_.find(input_index_key); if (iter == node_id_map_.end()) { #ifdef SUPPORT_TRAIN @@ -415,8 +415,7 @@ int AnfExporter::ConvertInputValueNode(std::shared_ptr input_anode, paramTensor->dataType = typePtr->type_id(); paramTensor->dims = {1}; paramTensor->nodeType = schema::NodeType::NodeType_ValueNode; - auto data = value->cast(); - int real_data = GetValue(data); + int real_data = CastToInt(value, false).front(); paramTensor->data.resize(sizeof(int32_t)); memcpy(paramTensor->data.data(), &real_data, sizeof(int32_t)); node_id_map_[valueNode->fullname_with_scope()] = meta_graphT->allTensors.size(); diff --git a/mindspore/lite/tools/common/graph_util.cc b/mindspore/lite/tools/common/graph_util.cc index 689ac803e5..9681d7a8e9 100644 --- a/mindspore/lite/tools/common/graph_util.cc +++ b/mindspore/lite/tools/common/graph_util.cc @@ -669,7 +669,7 @@ STATUS ChangeOpAxis(schema::MetaGraphT *graph, const std::unique_ptrprimitive->value != nullptr); auto type = node->primitive->value.type; auto input1_ndim = graph->allTensors.at(node->inputIndex[0])->dims.size(); - if (input1_ndim != 4 && input1_ndim != 0) { + if (input1_ndim != 4) { if (node->inputIndex.size() > 1) { auto input2_ndim = graph->allTensors.at(node->inputIndex[1])->dims.size(); if (input2_ndim != 4 && input2_ndim != 0) {