!23762 [MS][LITE]Fix graph input

Merge pull request !23762 from gongdaguo/fix_inputs
This commit is contained in:
i-robot 2021-09-26 04:35:41 +00:00 committed by Gitee
commit fac7ad25d3
10 changed files with 22 additions and 35 deletions

View File

@ -10,7 +10,7 @@ detection/ssd nnie_ssd_deploy 1 1 0 0.5
detection/yolov1 yolo_small_deploy 1 1 0 0.5
lstm/lstm_fc lstm_fc_0;2,135,1,1:20,135,1,1 2 10 0 0.5
segmentation/segnet segnet_basic_batchnorm_scale_inference 1 1 0 0.5
tracker/goturn goturn_tracker_no_group_mark 2 1 0 0.5
tracker/goturn goturn_tracker_no_group_mark 2:2,1 1 0 0.5
ci_models detect-deeper-halfdeeper-mbv1-shortcut-400-400_nopostprocess_simplified 1 1 0 0.5
ci_models gender_res_large_deploy 1 1 0 0.5
ci_models hdc_age_medium 1 1 0 0.5
@ -27,8 +27,8 @@ ci_models ml_ocr_detect_20200305 1 1 0 0.5
ci_models mtk_detect-deeper-halfdeeper-mbv1-lastearlySSD-shortcut-400-400_nopostprocess_simplified 1 1 0 0.5
ci_models mtk_detect-mbv1-shortcut-400-400_nopostprocess_simplified 1 1 0 0.5
ci_models mtk_detect_mbv1_640_480_nopostprocess_simplified 1 1 0 0.5
ci_models ml_Heatmap_depth_180240 2 1 0 0.5
ci_models ml_video_edit_person_divison_video 2 1 0 0.5
ci_models ml_Heatmap_depth_180240 2:2,1 1 0 0.5
ci_models ml_video_edit_person_divison_video 2:2,1 1 0 0.5
ci_models bolt_deploy_color-server 1 1 0 1.9
ci_models hiai_video_seg 1 1 0 3.0
ci_models ml_video_edit_have_imageProcessLayer_interpTo145_20201015 1 1 0 2.8

View File

@ -12,7 +12,7 @@ function Run_Hi3516() {
fi
nnie_line_info=${line}
model_info=`echo ${nnie_line_info}|awk -F ' ' '{print $2}'`
input_num=`echo ${nnie_line_info}|awk -F ' ' '{print $3}'`
input_info=`echo ${nnie_line_info}|awk -F ' ' '{print $3}'`
env_time_step=`echo ${nnie_line_info}|awk -F ' ' '{print $4}'`
env_max_roi_num=`echo ${nnie_line_info}|awk -F ' ' '{print $5}'`
accuracy_limit=`echo ${nnie_line_info}|awk -F ' ' '{print $6}'`
@ -20,11 +20,22 @@ function Run_Hi3516() {
length=`expr ${#model_name} + 1`
input_shapes=${model_info:${length}}
input_files=''
if [[ $input_num != 1 ]]; then
for i in $(seq 1 $input_num)
do
input_files=$input_files${basepath}'/../input_output/input/'${model_name}'.ms.bin_'$i','
done
if [[ $input_info != 1 ]]; then
input_num=`echo ${input_info} | awk -F ':' '{print $1}'`
input_seq=`echo ${input_info} | awk -F ':' '{print $2}'`
if [[ "${input_seq}" == "" ]]; then
for i in $(seq 1 $input_num)
do
input_files=${input_files}${basepath}'/../input_output/input/'${model_name}'.ms.bin_'$i','
done
else
for i in $(seq 1 $input_num)
do
cur_input_num=${input_seq%%,*}
input_seq=${input_seq#*,}
input_files=${input_files}${basepath}'/../input_output/input/'${model_name}'.ms.bin_'$cur_input_num','
done
fi
else
input_files=${basepath}/../input_output/input/${model_name}.ms.bin
fi

View File

@ -527,9 +527,6 @@ FuncGraphPtr GetFinalGraph(const FuncGraphPtr &func_graph, int i) {
int AnfExporter::SetMetaGraphInput(const FuncGraphPtr &func_graph,
const std::unique_ptr<schema::MetaGraphT> &meta_graphT) {
MS_ASSERT(func_graph != nullptr);
if (!reorder_input_) {
return RET_OK;
}
meta_graphT->inputIndex.clear();
for (const auto &input : func_graph->get_inputs()) {
auto iter = graph_inputs_map_.find(input);
@ -565,7 +562,6 @@ schema::MetaGraphT *AnfExporter::Export(const FuncGraphPtr &func_graph, bool kee
bool train_flag) {
this->train_flag_ = train_flag;
// hardcode for nnie and train
this->reorder_input_ = !(ConverterContext::GetInstance()->GetGraphInputTensorNames().empty());
this->graph_inputs_map_.clear();
auto meta_graphT = std::make_unique<schema::MetaGraphT>();
MS_CHECK_TRUE_MSG(meta_graphT != nullptr, nullptr, "meta_graphT is nullptr");
@ -776,11 +772,7 @@ int AnfExporter::SetOpInputNode(const CNodePtr &cnode, const std::unique_ptr<sch
if (IsContain(graph_inputs_, input_node->cast<AnfNodePtr>()) &&
graph_inputs_has_exported_.find(input_node) == graph_inputs_has_exported_.end()) {
graph_inputs_has_exported_.insert(input_node);
if (reorder_input_) {
graph_inputs_map_[input_node] = meta_graphT->allTensors.size() - 1;
} else {
meta_graphT->inputIndex.push_back(meta_graphT->allTensors.size() - 1);
}
graph_inputs_map_[input_node] = meta_graphT->allTensors.size() - 1;
}
} else if (input_node->isa<ValueNode>()) {
auto ret = ConvertInputValueNode(cnode, i, primitive_c, meta_graphT, fb_node);

View File

@ -50,7 +50,7 @@ class AnfExporter {
schema::MetaGraphT *Export(const FuncGraphPtr &func_graph, bool keep_graph = false, bool copy_primitive = false,
bool train_flag = false);
int SetOpOutputNode(const CNodePtr &cnode, const std::unique_ptr<schema::MetaGraphT> &meta_graphT,
schema::CNodeT *fb_node);
schema::CNodeT *fb_node);
int SetOpInputNode(const CNodePtr &cnode, const std::unique_ptr<schema::MetaGraphT> &meta_graphT,
schema::CNodeT *fb_node);
@ -95,7 +95,6 @@ class AnfExporter {
std::map<AnfNodePtr, int> graph_inputs_map_;
uint32_t node_idx_ = 0;
bool train_flag_ = false;
bool reorder_input_ = false;
};
// by default, copy_primitive is false, which means that the MetaGraph and func_graph share the same schema::PrimitiveT.
// but in PostQuantization, the func_graph need to transfer to MetaGraph first and do MetaGraph pass, which may modify

View File

@ -112,18 +112,12 @@ class ConverterContext {
const std::vector<std::string> GetGraphOutputTensorNames() const { return graph_output_tensor_names_; }
void AddGraphInputTensorNames(const std::string &input_name) { graph_input_tensor_names_.emplace_back(input_name); }
const std::vector<std::string> GetGraphInputTensorNames() const { return graph_input_tensor_names_; }
private:
ConverterContext() {}
virtual ~ConverterContext() = default;
std::map<int32_t, int32_t> tensor_data_type_map_;
std::map<int32_t, int32_t> graph_input_data_type_map_;
std::map<int32_t, int32_t> graph_output_data_type_map_;
std::map<std::string, std::vector<int64_t>> graph_input_tensor_shape_map_;
std::vector<std::string> graph_input_tensor_names_;
std::vector<std::string> graph_output_tensor_names_;
};
} // namespace lite

View File

@ -219,9 +219,6 @@ FuncGraphPtr MindsporeImporter::ImportMindIR(const converter::Flags &flag) {
MS_LOG(ERROR) << "RemoveUnusedGraphInput failed.";
return nullptr;
}
for (auto input : func_graph->get_inputs()) {
ConverterContext::GetInstance()->AddGraphInputTensorNames(input->fullname_with_scope());
}
status = GetFuncGraphOutputName(func_graph->get_return());
if (status != RET_OK) {
MS_LOG(ERROR) << "GetFuncGraphOutputName failed.";

View File

@ -283,7 +283,6 @@ STATUS CaffeModelParser::ConvertGraphInputsOfLayer() {
}
parameter->set_abstract(abstract);
parameter->set_name(layer.name());
ConverterContext::GetInstance()->AddGraphInputTensorNames(layer.name());
nodes_.insert(std::pair(layer.top(0), parameter));
}
}
@ -317,7 +316,6 @@ STATUS CaffeModelParser::ConvertGraphInputsOfShape() {
}
parameter->set_abstract(abstract);
parameter->set_name(caffe_model_.input(i));
ConverterContext::GetInstance()->AddGraphInputTensorNames(caffe_model_.input(i));
nodes_.insert(std::pair(caffe_model_.input(i), parameter));
}
return RET_OK;
@ -350,7 +348,6 @@ STATUS CaffeModelParser::ConvertGraphInputsOfDim() {
}
parameter->set_abstract(abstract);
parameter->set_name(caffe_model_.input(i));
ConverterContext::GetInstance()->AddGraphInputTensorNames(caffe_model_.input(i));
nodes_.insert(std::pair(caffe_model_.input(i), parameter));
}
return RET_OK;

View File

@ -308,7 +308,6 @@ STATUS ConvertGraphInputs(const onnx::GraphProto &onnx_graph, const FuncGraphPtr
}
parameter->set_abstract(abstract_tensor);
parameter->set_name(input_value.name());
ConverterContext::GetInstance()->AddGraphInputTensorNames(input_value.name());
anf_nodes_map->emplace(input_value.name(), parameter);
}
return RET_OK;

View File

@ -451,7 +451,6 @@ STATUS TFModelParser::ConvertParameter(const tensorflow::NodeDef &node, const Pa
} else {
if (root_graph) {
graph_input_names_.emplace_back(node.name()); // only root graph need set graph input names
ConverterContext::GetInstance()->AddGraphInputTensorNames(node.name());
}
}

View File

@ -422,7 +422,6 @@ STATUS TfliteModelParser::ConvertGraphInputs(const std::unique_ptr<tflite::SubGr
parameter->set_abstract(abstract_tensor);
if (tflite_subgraph == tflite_model_->subgraphs.front()) {
parameter->set_name(tensor->name);
ConverterContext::GetInstance()->AddGraphInputTensorNames(tensor->name);
} else {
parameter->set_name(tflite_subgraph->name + "_input_" + std::to_string(i) + "_parameter");
}