Skip to content

Commit

Permalink
fix converter && add onnx test model (OAID#965)
Browse files Browse the repository at this point in the history
Co-authored-by: xlchen <[email protected]>
  • Loading branch information
cccxinli and cccxinli authored Jul 30, 2021
1 parent dce6adc commit 2a39812
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 2 deletions.
7 changes: 7 additions & 0 deletions source/device/cpu/op/batchnorm/batchnorm_ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ static int run(struct node_ops* node_ops, struct exec_node* exec_node, struct ex
batchnorm_op_param->input_w = input_tensor->dims[2];
batchnorm_op_param->input_h = 1;
}
else if (2 == input_tensor->dim_num)
{
batchnorm_op_param->input_n = input_tensor->dims[0];
batchnorm_op_param->input_c = input_tensor->dims[1];
batchnorm_op_param->input_h = 1;
batchnorm_op_param->input_w = 1;
}
else
{
return -1;
Expand Down
10 changes: 10 additions & 0 deletions source/device/cpu/op/eltwise/eltwise_ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@ static int ref_eltwise_fp32(void* output, void* input0, void* input1, int type,
*out_ptr++ = in0[i / input_hw] * in1[i];
}
}
else if (input_hw == input_hw_1)
{
for (int i = 0; i < input_chan; i++)
{
for (int j = 0; j < input_hw; j++)
{
*out_ptr++ = in0[i * input_hw + j] * in1[j];
}
}
}
else
return -1;
break;
Expand Down
2 changes: 1 addition & 1 deletion tests/models/test_model_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ int onnx_model_test(std::string model_file, int img_c, int img_h, int img_w)
}
for (size_t i = 0; i < output_size; i++)
{
if (fabs(output_data[i] - onnx_out_data[i]) > 0.0001)
if (fabs(output_data[i] - onnx_out_data[i]) > 0.001)
{
fprintf(stderr, "not equal on data\n");
fprintf(stderr, "tengine:%f,onnx:%f\n", output_data[i], onnx_out_data[i]);
Expand Down
21 changes: 21 additions & 0 deletions tests/test_onnx_model.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,24 @@ test_model retinanet_sim 3 480 640
test_model yolov5-face-sim 3 384 640
test_model version-RFB-640_sim 3 480 640
test_model mobilenetv2-7_sim 3 224 224
test_model efficientnet_b0-sim 3 224 224
test_model facekeypoints_9_sim 3 96 96
test_model facequality 3 64 64
test_model facerfb 3 320 320
test_model ghostnet-sim 3 224 224
test_model hrnet_w18-sim 3 224 224
test_model landmark_out-sim 1 160 160
test_model RFB_pytorch-sim_face 3 320 320
test_model ultraNet 3 240 320
test_model xception_sim 3 229 229
test_model step-final 3 640 640
test_model eais_face 3 640 960
test_model eais-mnet 3 640 960
test_model eais 3 640 960
test_model eais_retina 3 640 960
test_model facedetect_retinaface_sim 3 384 640
test_model inception-v2-9_sim 3 224 224
test_model efficientnet-lite4-11_sim 224 224 3
test_model facerec 3 112 112
test_model MobileNetSSD_deploy_sim 3 300 300
test_model dense-sim 1 32 277
2 changes: 1 addition & 1 deletion tools/convert_tool/onnx/onnx2tengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2061,7 +2061,7 @@ int load_depth_to_space(ir_graph_t* graph, ir_node_t* node, const onnx::NodeProt
for (int k = 0; k < onnx_node.attribute_size(); k++)
{
const onnx::AttributeProto& attr = onnx_node.attribute(k);
if (attr.name() == "block_size")
if (attr.name() == "blocksize")
{
depthtospace_param->block_size = attr.i();
}
Expand Down
9 changes: 9 additions & 0 deletions tools/convert_tool/utils/graph_optimizer/graph_opt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ int delete_node(ir_graph_t* graph, int16_t pre_node_id, int16_t del_node_id)
}
pre_output_tensor->consumer_num = del_output_tensor->consumer_num;

/* check if graph output */
for (int i = 0; i < graph->output_num; ++i)
{
if (del_node_id == graph->output_nodes[i])
{
graph->output_nodes[i] = pre_node_id;
}
}

/* delete node */
if (erase_tensor_id(graph, del_node->output_tensors[0]) < 0 || erase_node_id(graph, del_node->index) < 0)
{
Expand Down

0 comments on commit 2a39812

Please sign in to comment.