From 3b94bef00c720b194b2ce98c4bf1fc59436624a6 Mon Sep 17 00:00:00 2001 From: lyvette Date: Tue, 4 Aug 2020 15:09:19 +0800 Subject: [PATCH] supplement some parser ut and modify tflite parser supplement some tflite parser ut. format tflite parsers and ut --- mindspore/lite/test/CMakeLists.txt | 3 + mindspore/lite/test/run_test.sh | 2 + .../parser/tflite/test_data/add1.tflite | Bin 0 -> 568 bytes .../parser/tflite/test_data/add2.tflite | Bin 0 -> 560 bytes .../parser/tflite/test_data/add3.tflite | Bin 0 -> 564 bytes .../parser/tflite/test_data/argmin.tflite | Bin 0 -> 604 bytes .../parser/tflite/test_data/ceil.tflite | Bin 0 -> 476 bytes .../parser/tflite/test_data/div1.tflite | Bin 0 -> 580 bytes .../parser/tflite/test_data/div2.tflite | Bin 0 -> 572 bytes .../parser/tflite/test_data/div3.tflite | Bin 0 -> 572 bytes .../tflite/test_data/expand_dims.tflite | Bin 0 -> 600 bytes .../parser/tflite/test_data/fill.tflite | Bin 0 -> 556 bytes .../parser/tflite/test_data/floor.tflite | Bin 0 -> 476 bytes .../parser/tflite/test_data/floor_div.tflite | Bin 0 -> 552 bytes .../parser/tflite/test_data/floor_mod.tflite | Bin 0 -> 552 bytes .../parser/tflite/test_data/gather.tflite | Bin 0 -> 592 bytes .../parser/tflite/test_data/gather_nd.tflite | Bin 0 -> 588 bytes .../parser/tflite/test_data/leaky_relu.tflite | Bin 0 -> 516 bytes .../parser/tflite/test_data/lrn.tflite | Bin 0 -> 532 bytes .../parser/tflite/test_data/mul1.tflite | Bin 0 -> 572 bytes .../parser/tflite/test_data/mul2.tflite | Bin 0 -> 564 bytes .../parser/tflite/test_data/mul3.tflite | Bin 0 -> 568 bytes .../parser/tflite/test_data/pad.tflite | Bin 0 -> 628 bytes .../parser/tflite/test_data/pow.tflite | Bin 0 -> 544 bytes .../parser/tflite/test_data/range.tflite | Bin 0 -> 428 bytes .../parser/tflite/test_data/rank.tflite | Bin 0 -> 432 bytes .../parser/tflite/test_data/relu.tflite | Bin 0 -> 476 bytes .../test_data/resize_nearest_neighbor.tflite | Bin 0 -> 640 bytes .../parser/tflite/test_data/reverse.tflite | Bin 0 -> 596 bytes .../parser/tflite/test_data/sigmoid.tflite | Bin 0 -> 476 bytes .../parser/tflite/test_data/squeeze.tflite | Bin 0 -> 620 bytes .../parser/tflite/test_data/sub1.tflite | Bin 0 -> 572 bytes .../parser/tflite/test_data/sub2.tflite | Bin 0 -> 564 bytes .../parser/tflite/test_data/sub3.tflite | Bin 0 -> 568 bytes .../parser/tflite/tflite_abs_parser_test.cc | 2 +- .../parser/tflite/tflite_add_parser_test.cc | 78 ++++++++++++++++++ .../parser/tflite/tflite_addn_parser_test.cc | 2 +- .../tflite/tflite_argmin_parser_test.cc | 45 ++++++++++ .../tflite_batch_to_space_nd_parser_test.cc | 2 +- .../parser/tflite/tflite_cast_parser_test.cc | 2 +- .../parser/tflite/tflite_ceil_parser_test.cc | 33 ++++++++ .../parser/tflite/tflite_cos_parser_test.cc | 2 +- .../tflite_depth_to_space_parser_test.cc | 2 +- .../parser/tflite/tflite_div_parser_test.cc | 78 ++++++++++++++++++ .../parser/tflite/tflite_equal_parser_test.cc | 2 +- .../parser/tflite/tflite_fill_parser_test.cc | 42 ++++++++++ .../tflite/tflite_floor_div_parser_test.cc | 33 ++++++++ .../tflite/tflite_floor_mod_parser_test.cc | 33 ++++++++ .../parser/tflite/tflite_floor_parser_test.cc | 33 ++++++++ .../tflite/tflite_gather_nd_parser_test.cc | 41 +++++++++ .../tflite/tflite_gather_parser_test.cc | 42 ++++++++++ .../tflite_greater_equal_parser_test.cc | 2 +- .../tflite/tflite_greater_parser_test.cc | 2 +- .../tflite/tflite_leaky_relu_parser_test.cc | 42 ++++++++++ .../tflite/tflite_less_equal_parser_test.cc | 2 +- .../parser/tflite/tflite_less_parser_test.cc | 2 +- .../parser/tflite/tflite_log_parser_test.cc | 2 +- .../tflite/tflite_logical_and_parser_test.cc | 2 +- .../tflite/tflite_logical_not_parser_test.cc | 2 +- .../tflite/tflite_logical_or_parser_test.cc | 2 +- .../parser/tflite/tflite_lrn_parser_test.cc | 45 ++++++++++ .../tflite/tflite_maximum_parser_test.cc | 2 +- .../tflite/tflite_minimum_parser_test.cc | 2 +- .../parser/tflite/tflite_mul_parser_test.cc | 78 ++++++++++++++++++ .../tflite/tflite_not_equal_parser_test.cc | 2 +- .../tflite/tflite_one_hot_parser_test.cc | 2 +- .../tflite/tflite_p_relu_parser_test.cc | 2 +- .../parser/tflite/tflite_pad_parser_test.cc | 43 ++++++++++ .../tflite/tflite_parsers_test_utils.cc | 5 +- .../parser/tflite/tflite_parsers_test_utils.h | 4 +- .../parser/tflite/tflite_pow_parser_test.cc | 44 ++++++++++ .../tflite/tflite_reduce_max_parser_test.cc | 2 +- .../tflite/tflite_reduce_min_parser_test.cc | 2 +- .../tflite/tflite_reduce_prod_parser_test.cc | 2 +- .../parser/tflite/tflite_relu_parser_test.cc | 33 ++++++++ .../tflite/tflite_resize_nn_parser_test.cc | 44 ++++++++++ .../tflite/tflite_reverse_parser_test.cc | 43 ++++++++++ .../tflite_reverse_sequence_parser_test.cc | 2 +- .../parser/tflite/tflite_round_parser_test.cc | 2 +- .../parser/tflite/tflite_rsqrt_parser_test.cc | 2 +- .../parser/tflite/tflite_sin_parser_test.cc | 2 +- .../tflite_space_to_batch_nd_parser_test.cc | 2 +- .../tflite_space_to_depth_parser_test.cc | 2 +- .../tflite_sparse_to_dense_parser_test.cc | 2 +- .../parser/tflite/tflite_split_parser_test.cc | 2 +- .../tflite/tflite_split_v_parser_test.cc | 2 +- .../parser/tflite/tflite_sqrt_parser_test.cc | 2 +- .../tflite/tflite_square_parser_test.cc | 2 +- .../tflite_squared_difference_parser_test.cc | 2 +- .../tflite_strided_slice_parser_test.cc | 2 +- .../parser/tflite/tflite_sub_parser_test.cc | 78 ++++++++++++++++++ .../parser/tflite/tflite_sum_parser_test.cc | 2 +- .../parser/tflite/tflite_tile_parser_test.cc | 2 +- .../tflite/tflite_topk_v2_parser_test.cc | 2 +- .../tflite/tflite_unique_parser_test.cc | 2 +- .../tflite/tflite_unstack_parser_test.cc | 2 +- .../parser/tflite/tflite_abs_parser.cc | 2 +- .../parser/tflite/tflite_add_parser.cc | 48 +++++++++-- .../parser/tflite/tflite_addn_parser.cc | 18 ++-- .../parser/tflite/tflite_argmax_parser.cc | 18 +++- .../parser/tflite/tflite_argmin_parser.cc | 28 +++---- .../tflite/tflite_batch_to_sapce_nd_parser.cc | 6 +- .../tflite/tflite_batch_to_space_parser.cc | 22 ++--- .../tflite/tflite_broadcast_to_parser.cc | 30 +++---- .../parser/tflite/tflite_cast_parser.cc | 28 +++++-- .../parser/tflite/tflite_ceil_parser.cc | 6 +- .../parser/tflite/tflite_concat_parser.cc | 9 +- .../parser/tflite/tflite_conv_parser.cc | 34 +++++--- .../parser/tflite/tflite_cos_parser.cc | 10 +-- .../parser/tflite/tflite_deconv_parser.cc | 28 ++++--- .../tflite/tflite_depth_to_space_parser.cc | 17 ++-- .../tflite/tflite_depthwise_conv_parser.cc | 12 ++- .../parser/tflite/tflite_div_parser.cc | 54 +++++++++--- .../tflite/tflite_expand_dims_parser.cc | 14 ++-- .../parser/tflite/tflite_fakequant_parser.cc | 10 +++ .../parser/tflite/tflite_fill_parser.cc | 1 + .../parser/tflite/tflite_floor_parser.cc | 2 +- .../parser/tflite/tflite_floor_parser.h | 2 +- .../tflite/tflite_fullyconnected_parser.cc | 11 ++- .../parser/tflite/tflite_gather_nd_parser.cc | 8 +- .../parser/tflite/tflite_gather_nd_parser.h | 2 +- .../parser/tflite/tflite_gather_parser.cc | 6 +- .../parser/tflite/tflite_gather_v2_parser.cc | 52 ------------ .../parser/tflite/tflite_gather_v2_parser.h | 42 ---------- .../tflite/tflite_inner_product_parser.cc | 63 -------------- .../tflite/tflite_inner_product_parser.h | 42 ---------- .../parser/tflite/tflite_leaky_relu_parser.cc | 5 +- .../parser/tflite/tflite_lrn_parser.cc | 3 +- .../tflite/tflite_max_pooling_parser.cc | 3 + .../parser/tflite/tflite_mean_parser.cc | 5 +- .../tflite/tflite_mean_pooling_parser.cc | 10 ++- .../parser/tflite/tflite_model_parser.cc | 6 ++ .../parser/tflite/tflite_mul_parser.cc | 47 +++++++++-- .../parser/tflite/tflite_node_parser.cc | 23 ++++++ .../parser/tflite/tflite_node_parser.h | 7 +- .../parser/tflite/tflite_one_hot_parser.cc | 9 +- .../parser/tflite/tflite_p_relu_parser.cc | 4 +- .../parser/tflite/tflite_pad_parser.cc | 10 +-- .../parser/tflite/tflite_pow_parser.cc | 7 +- .../parser/tflite/tflite_range_parser.cc | 28 +------ .../parser/tflite/tflite_rank_parser.cc | 4 - .../parser/tflite/tflite_reduce_any_parser.cc | 6 +- .../parser/tflite/tflite_reduce_max_parser.cc | 6 +- .../parser/tflite/tflite_reduce_min_parser.cc | 6 +- .../tflite/tflite_reduce_prod_parser.cc | 6 +- .../parser/tflite/tflite_relu6_parser.cc | 1 + .../parser/tflite/tflite_relu_parser.cc | 1 + .../parser/tflite/tflite_reshape_parser.cc | 4 + .../tflite/tflite_resize_bilinear_parser.cc | 20 ++++- .../tflite_resize_nearest_neighbor_parser.cc | 20 ++++- .../parser/tflite/tflite_reverse_parser.cc | 7 +- .../parser/tflite/tflite_reverse_parser.h | 2 +- .../tflite/tflite_reverse_sequence_parser.cc | 9 +- .../parser/tflite/tflite_scatter_nd_parser.cc | 1 + .../parser/tflite/tflite_shape_parser.cc | 2 - .../parser/tflite/tflite_sigmoid_parser.cc | 42 ---------- .../parser/tflite/tflite_sigmoid_parser.h | 41 --------- .../parser/tflite/tflite_slice_parser.cc | 2 + .../parser/tflite/tflite_softmax_parser.cc | 5 +- .../tflite/tflite_space_to_batch_nd_parser.cc | 5 +- .../tflite/tflite_space_to_depth_parser.cc | 3 +- .../tflite/tflite_sparse_to_dense_parser.cc | 10 ++- .../parser/tflite/tflite_split_parser.cc | 19 +++-- .../parser/tflite/tflite_split_v_parser.cc | 21 +++-- .../parser/tflite/tflite_squeeze_parser.cc | 4 +- .../parser/tflite/tflite_stack_parser.cc | 1 + .../parser/tflite/tflite_sub_parser.cc | 48 +++++++++-- .../parser/tflite/tflite_sum_parser.cc | 8 +- .../parser/tflite/tflite_tanh_parser.cc | 1 + .../parser/tflite/tflite_tile_parser.cc | 2 +- .../parser/tflite/tflite_topk_v2_parser.cc | 3 +- .../parser/tflite/tflite_transpose_parser.cc | 6 +- .../parser/tflite/tflite_unique_parser.cc | 2 + .../parser/tflite/tflite_unstack_parser.cc | 2 +- .../parser/tflite/tflite_where_parser.cc | 3 +- 175 files changed, 1516 insertions(+), 603 deletions(-) create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/add1.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/add2.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/add3.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/argmin.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/ceil.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/div1.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/div2.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/div3.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/expand_dims.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/fill.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/floor.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/floor_div.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/floor_mod.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/gather.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/gather_nd.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/leaky_relu.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/lrn.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/mul1.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/mul2.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/mul3.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/pad.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/pow.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/range.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/rank.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/relu.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/resize_nearest_neighbor.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/reverse.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sigmoid.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/squeeze.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sub1.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sub2.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sub3.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_add_parser_test.cc create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_argmin_parser_test.cc create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_ceil_parser_test.cc create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_div_parser_test.cc create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_fill_parser_test.cc create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_floor_div_parser_test.cc create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_floor_mod_parser_test.cc create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_floor_parser_test.cc create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_gather_nd_parser_test.cc create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_gather_parser_test.cc create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_leaky_relu_parser_test.cc create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_lrn_parser_test.cc create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_mul_parser_test.cc create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_pad_parser_test.cc create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_pow_parser_test.cc create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_relu_parser_test.cc create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_resize_nn_parser_test.cc create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reverse_parser_test.cc create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sub_parser_test.cc delete mode 100644 mindspore/lite/tools/converter/parser/tflite/tflite_gather_v2_parser.cc delete mode 100644 mindspore/lite/tools/converter/parser/tflite/tflite_gather_v2_parser.h delete mode 100644 mindspore/lite/tools/converter/parser/tflite/tflite_inner_product_parser.cc delete mode 100644 mindspore/lite/tools/converter/parser/tflite/tflite_inner_product_parser.h delete mode 100644 mindspore/lite/tools/converter/parser/tflite/tflite_sigmoid_parser.cc delete mode 100644 mindspore/lite/tools/converter/parser/tflite/tflite_sigmoid_parser.h diff --git a/mindspore/lite/test/CMakeLists.txt b/mindspore/lite/test/CMakeLists.txt index 33da75312e..afc872bb5b 100644 --- a/mindspore/lite/test/CMakeLists.txt +++ b/mindspore/lite/test/CMakeLists.txt @@ -1,5 +1,7 @@ +set(TOP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..) set(TEST_DIR ${TOP_DIR}/mindspore/lite/test) set(LITE_DIR ${TOP_DIR}/mindspore/lite) +set(CCSRC_DIR ${TOP_DIR}/mindspore/ccsrc) include_directories(${TOP_DIR}) include_directories(${TEST_DIR}) include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/dependency_gtest.cmake) @@ -12,6 +14,7 @@ set(ANF_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../../core/base/base.cc ${CMAKE_CURRENT_SOURCE_DIR}/../../core/utils/log_adapter.cc ) + if(BUILD_CONVERTER) set(ANF_SRC ${ANF_SRC} diff --git a/mindspore/lite/test/run_test.sh b/mindspore/lite/test/run_test.sh index adfb48130f..f048dbb364 100755 --- a/mindspore/lite/test/run_test.sh +++ b/mindspore/lite/test/run_test.sh @@ -26,3 +26,5 @@ cp -fr $TEST_DATA_DIR/testPK ./data ./lite-test --gtest_filter=TestPadInt8.* ./lite-test --gtest_filter=TestDeconvInt8.* + +./lite-test --gtest_filter="TestTfliteParser*" diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/add1.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/add1.tflite new file mode 100644 index 0000000000000000000000000000000000000000..762c2e7d3f12ae5cb15f036aed2e0f98abd1a586 GIT binary patch literal 568 zcmYjO!AiqG6dX0Sr7g8s4?X12gNGg@Dk6BS2!aqn#Cs`b!9cTt7zHn$`~W}2&+z0I z^ytBF5HZed63oKv%g(+xZ{EfSaC06W0o(B5p@Tk#*daS618flG33zcVu*bMYOt~q( z5}U*q51&LxtcVkG3{-^Em3qg0gPnj8k;HbMJ=i=>%>2=0_i<|R{aX~e9}^OjdZzsV{V$sc`S;eu9t>ZsoQn4Dyv&@&&<_K%{Ntz-cDNLPooHL%mZ4i_qbPm z7=hWWiH}N88q$?_^_G@2skQ&)&Mn84^XRtx%bG`Zs;S?r>8D5jYPq;Icj+=R8GhK$ IqmmT<0EK5d(*OVf literal 0 HcmV?d00001 diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/add2.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/add2.tflite new file mode 100644 index 0000000000000000000000000000000000000000..c0c379a60ce1c0c4a1170569295fce1531352d7d GIT binary patch literal 560 zcmYjO!AiqG6dX0$QneQKkV6hV^w5JuiwGVof*@2V;yn}-FwkruM)3nYdGeF`4dT&* zU*SnyXLeKc!R+k5yf-^<69Krnm>dJUh!CKSE%dO@Y{(3-M)(u(?6SZCd4(8q5x)}a z#3v6Q#FTg^PMIT75l&a?ZMO$+0``a^H%awi>b%I3$E>=~OM|Z;YxTWHjN+5{h`fv) zZmuSm*ZuR-u)faHn3*o!{(0{*BhP(eKnw|a)+{o#Ak}`$)q7lRI3nxrVwM}}N=I+f zq8sTlHbX9&Np+#MRx_$!Q0NSF+^nkVG`SbnYNq9z>Mr%@?W83>OVeaTUa%I}phm#e ze^(7K9=|m@>Xi@qQM3rxfB59Oe7$DS&i`4>AP@4W*#^Xa58FIX=d;`FuAHY?<-C0J JzJMB1`32v2I`aSk literal 0 HcmV?d00001 diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/add3.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/add3.tflite new file mode 100644 index 0000000000000000000000000000000000000000..d36b81e327a2d30f36168106db579e0b0eb4f12c GIT binary patch literal 564 zcmaKpy-LJD6os!E*JahXsKpj3Qdn3>@V8e4L0Cb=J}f3+V3R;xWgo)I%7^eNd!Y*0*h{11e@qpvlahUDa%lxB!mX z6kowI_$K)RpWp+WQX`;fPFLz(cQ!hiZGk*1;_9)OWO*7trPV`L7F0X%JobjyCmuv6 z(LS+V8yv2Nmp9>gS#WQXCJ_}M*MBqkROCGbyFk9Bp_yjj4NSoz(2`d{xncn1GaqG` z@|~96XN4D%HfwdjruoDR>$-05&ug0X+}vXI;ED4BS97)Rt6sXJca)amS(3zu#3|hO zU%oh+N%PF}*U7KPqr3FJ94BcN^P%W;oL1vqs?G1pyL!uqw06LMTJkWXzlWMsegNV+ BI>rD1 literal 0 HcmV?d00001 diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/argmin.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/argmin.tflite new file mode 100644 index 0000000000000000000000000000000000000000..05b172c71e2077a89811d9eb0affba8184966f51 GIT binary patch literal 604 zcmYL{!Ab&A7==$ZrI?tMgbNogTC@l=YN5*rf3nyRemHafIrq-F=fB#PbbB#8k#^Kpq>5^4sA;ujMOrtCH|aH~(xG|HIQ0X5Gd7G` zNvarkh~~bDwr1dqdnNR8FYOxhBpqkZ=`xwesH9zG4_oEgUrm*bD&Q%vyhE~9XD{>%-QovlH$APp6q3( z!Phmwvt=-swCVM-pP{0a7k*T6Mm0F#R4wEy^p8BxO%ZdF4aS!>?i0_m>|sQb_pq0< zqM(xz6#mRlisHBX%UQyY9ONW3g;sbTO?~HSxNvK@;>XO*&=vm#y!eK5R(Fag`Pjc@ VT+b%=@#A7PjWc~aXXF*uegVEXHsk;R literal 0 HcmV?d00001 diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/ceil.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/ceil.tflite new file mode 100644 index 0000000000000000000000000000000000000000..75b2d77d30dfb4fd3d3aa3b3f15160b43ba4fec8 GIT binary patch literal 476 zcmZvZ%}T>i5QRsLwbW9JcF{!^S-5Z&EcyUKK@cj4xG%+AXdpijt54vf3zt5IPvSEP z@jLf6xG`|<%$%7y_goU2+0*Uf%Iwr)i>z-$8`}hS3S)KvLS?q~tl0%|Pdta>Cy2lY z#TLAS8*252K$=qS`#fl#k(YV3Y+kEPUb^L*YhLoYg6%OEaR$vXahA@m(@T=wcS5{h z+&w1qx?*qRvJ_^7<3Il+82OGt0?vVa?}IOp0r}IX*kMYpx0I_KGXw8msslKAQLmfr z_QTu}oiInTR`0uQTkYshc}aHpAyGQQ+~oy=*D{vA_}i3Nhdz|3a)2 z-~9L_Cd3DEPL7U>sC1>?sqSDUV3&xaWST9KJc`YJ%P zm+SG>t$&dwjL%INkm<48|K59K)U!_<5CcLzYZjLcz0*Gu>P;rUT6>RPwc}ZoNLM=A zNt@kBm$vWn&`gSR%Cc>t-`%2i&oyXC$%$=}Rpcji8w NhbF@hYdTbt!XFS?KSKZj literal 0 HcmV?d00001 diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/div2.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/div2.tflite new file mode 100644 index 0000000000000000000000000000000000000000..bc367d8f1e800dcb2ce78994aebcd66df8943423 GIT binary patch literal 572 zcmYjO!AiqW5F9mXt+5vM&_jeAdMF~%B8bO=AP5yiJa`MmJTTBC5Yy7L_yK;9AK=Mv z@aRGO0x{0KH0r{<-M87Doqh2DT%Qe(fGv1%(143Jc9`uj11u5M4S2L!V4r@0=<$$$ zB9@5{Ufzit;*B_Aj*g75ykc+I7@P!b6G@zg`6Mmk#Dr6m-^W>s&+oF-_cqZFj)Oz` z+BO+n49~Cp(=26uVWNPU7S;Y~Z!sgyKG7w5gfwdxmx5mCXN0uL$O+?u0CV+>HWmFMilwPMDaB2 zGk#`0utFAxXH}y*U@&-{bE#i?q+Pa7{Bj)3Y-iP@eH2xHS^G$fbZO5n@n6dZ@0a7z St+~s_k;$!|FV1wxA(kIm`#)m< literal 0 HcmV?d00001 diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/div3.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/div3.tflite new file mode 100644 index 0000000000000000000000000000000000000000..a8b7e5ec7b4223fa67a9152c47d1d7a201603176 GIT binary patch literal 572 zcmaKpy-LJT5QRsL>$+%M)FMTM6c!?~_=mM12*L^?_F*vr1Dgb5cCqjg#M%e(349U@ z3kx4Xh~G&JZsmn@=ZBed&&>7B?B;xUWVUX;Io7om>)R$-kBr#@Xd<(xI%~Fvodd^Q zvM*o}d=Y$t5AY67$zfo$npf=I+BaS@+W={jg~cQ*lQa&eadDsI8QBhX4tG=6#~ut$ z2K(6dtl?Y^FRp{LJfp9SqX8Kg)qgX%WTZU+J3zX{p_v?ny<#81JkXI=L9wh4q%$2Q zh;nN#?PrM%iJPS7#wTVP)jXZq=y`G=%EJ*77@Hx1))L_@mhijG|+4$t>Odt03LlfpTkpe zo!KQ6T$r8B_cPyYk_f=#?eqdTMuY$%I_RO#=ztMmm+()(hl>Jd+0N58at{!Qr(Z+X2cDubV2YnAU2 zLp-Sr>(_afFw&*lt@kb?@*ERGVnoQZ?lPjGZ}NhWH!U%3J06fVyG#oMw4HY;w;7Wk z<(hi+Xn7sg9`MQ6@^Gs7leJcTnjI1HA`R&&FIG-`^Zt^W?7Apdz!&>~eX0fAeUEhh z_xZbrob11w?#|Uxt^A2&LbEjYkl4-{J9WjS({~mA50H*})u(qdBpRQMXKBrr>2toQ OmRVk7L(c&=GEUUzzIpna196WfC)sTw^FCqkl1VlU=7Bi56*Rsfv1QM@Z z%n5VSqchEXidYPP&co7fC?4r6uzLS?q|tl1fHPdta>2Z+Es z#SXlIYijjIK$=n>_&jJ%$*ZDXH!thTgwahj8+uUN_tA zhq*qTFsDSlueNQqqdVm#`OOcB(otNL&NaU7c~0+``7Hbiy+az(`%mKt{;u3S=1;E7 M^2WZoGh$!*KUGyHtpET3 literal 0 HcmV?d00001 diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/floor_div.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/floor_div.tflite new file mode 100644 index 0000000000000000000000000000000000000000..3bf705e36de36ebad6cdca280d1139d4a8bda0f2 GIT binary patch literal 552 zcmYk3y-LJT5QRsLx~#e`y2Tb-q_D7%V9*B;1VLCq#L6ZtCSo8z5ZA4I1hMu3d=hI5 z3kx5_Qi$Kl59Y$j%$z%O?#yIjX4hxaBeNZwm}5QLw4se)$1r9qppML*E7t4)y9D<5 z$i9MA@J;XqKEVe#fy1C^m9Er#m2bRcwhPiY3yQ~V9;Z>Th>C|e&tTWcbNJSIL#*%l z$KD}MbGES;)AK9$G|#A;N1+EZpzHq`1~BT~1^YmKOF}dKfH#nUWuT*81;w&spgz-C zOjG@84ypIy)RXSo{H{iwyUuN$i*uvs?(-y!iohq<=A@^6j2dPARqaFXtLJtvU9AoHj+XuMwnM$N{s1=J BIL-h7 literal 0 HcmV?d00001 diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/floor_mod.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/floor_mod.tflite new file mode 100644 index 0000000000000000000000000000000000000000..b101b930765fb8c77818340451e17d70d99e89f1 GIT binary patch literal 552 zcmYk3y-LJT5QRsLx~#e`y2Tb-q_D7%VAvNBgau(2MC`+20tWH}akcUh#M%e&Nvtg_ zEPRkHh4`KPU@n}@%(*k?&P*m|b~~F-&5mqhj`eKchBks7!Ix>5yShF+i1~}m( z`v$hb55YJ10-xXl4uhgqx>D~|zVVXTF-YSqC?2y_oJPS@R6N9a2D?L^!?(^GVtvn_ zdgnOJIm9mJS2yluo>8}oLJwv@*Z(sNVAQ({PJ#NCgl1ZUcaVThprc*|#j<0dKGS7P zQ~hcVsrTX3lkVF5u11}^%Wa*D6DaSsEKAk3J9Y6@r`<_QyO||8qWc@joN;1g?e($hXhjk5l#_M!LHOS_k@)*gIE%YJ#=pS7#wTVP)jW;*h3CIOdt06u~b<&%g9 z55+i>HTc2ox0&zT+4-^&fbrGn4A@1403kZ)VV`WD46si4FW|LifkWmsV#r1Ljo2X2 z0#+o(#20ZvO7#vQU8#rl9^3ho5`~&7q)Qt{HZF{d&Eg{o*XkbvBS;n z=;nTKSvdADO_q@9((S+ZE*W_q5HT?%dVOy+H90y~gs-dWvEPH8fMcSxZd!e~+LmVeX{x1NICPq((RrU3r{k;if}4#U(mzff zUXt5|V}5P&luVCm|F!qXNOMA*5T}GRYnFt9zUd1>+GO(E8$YC1?=rIv=z8s{+$ASH zI&1TFM;7WRcaKrX<>p=d8)wly_0~J6zD)0MpVft_o^r)2<^dh@5!cX1_gV`*6lvC& zox(q9R$8Q7>5E^K52{ O#XL6^*8Z;|fA$BgmN+>8 literal 0 HcmV?d00001 diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/leaky_relu.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/leaky_relu.tflite new file mode 100644 index 0000000000000000000000000000000000000000..ba8c13f36324ae8cdd4a51a6b1e9b7eef0630d3c GIT binary patch literal 516 zcmZvZF-yZh7=~Xp+FDC3wMd5y9UMAHAarqZDF|W&DdJk9JusMDAhv>Ae}F&5!NJ*I zpqoEOi0^x8aPi=|`@Zik@Auxt2XK8Bje#C~cxa-HF8ZtvSOK<3l>sYP1x8#q$cU5H z7vhn3CU4}GoG{m3n@Cg2O&3?12aL1C&Wfd7B$=5#nc^|YEpE!PlvbC7K{yUV2J5lU z^)fo24kx+g`GuJWtaRw~&v%Cv`Sr<=91;25B;RC3=uW^6_dU+Q*JpHE>(tsn%Y7}CmOGDI?S1fmx|{r{=P^-Vz4P`O<+~&@@x$}f rq)W!?q`JKIT~z%kd6S;BrKh|8r?wy>}YidwrM2tpKD?3cw27}z8bS8Gd43qQxgLi`Fp zMTqB476;otsHwX15pFvDvmI7Fgdxi*1+c9u>1S=rXexS2a5zuE3Z{@eKm_ zB>8}M7?W!+1ZhgS@7A5>4(qb0rp;ruEXsWPls6AWT~Y1P7ch64G4UupO%I8FY_Yh? zE+?b&y5ih2pQltJ9RK-`sK|E$BiIM|UWIRX1^LrZ^r&CoQqBs@L{3BgH+U6kGKMEi z(vr83j+j}V^{tFEvuDRTiP!aanGKwpUS;6gZK%Dkwr!;+fAS!|@}c*aj_`Rlxn|vS odFN3(-Jg?3=}1#L^6Ah0*V&|gvzXoG_w{0)H}=E*0iEjo1$x{npa1{> literal 0 HcmV?d00001 diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/mul1.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/mul1.tflite new file mode 100644 index 0000000000000000000000000000000000000000..0621a681ac7258c559d9cd61bc65558352cdd2fb GIT binary patch literal 572 zcmYjOJxc>Y6dd(TLJaXp6jEG~!Xky7iU=tKf*>Ri#6ARb;K6;snTR%4{s4c9KScZu zmKN4l;ySaN!+S9MZfEz+o3|GLxV{*l0v!bK&_D}5_Q>|g09%CH0ne5N4w*NI0T<;L zVw?El=98EbAHF7=BbR%8HevgZ0(!G{3rmUBS!s#|`m8zSL?udWlea%&USJmnLq$hr|O7O~iK#kQN zS9hj5U^J@YeXS=Aoy))aNK2a3I(oGGn&sR~I(2_qGpSBB<(pOg?2w-(^PA{4PZm*u KANKR8B!xeDDmz>N literal 0 HcmV?d00001 diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/mul2.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/mul2.tflite new file mode 100644 index 0000000000000000000000000000000000000000..089de5cb2d746a2aaa83a836bbace87f723953da GIT binary patch literal 564 zcmYjOu}T9$6dd(5A!rOSLW(O=q(~vBK?KWyAP5PFq(6c=@ZfF_&P4J7R#twJg&IGsZxO@jEIJ`q zvCqw9e09^iC=BZt$vk4FNwdBkuKw~%SAJ(u4ApO`lX@px((N*?uJjdm49Nr=BnOR_o+|sCq40GnZ-l$3u}QL zDg<2pchvx+(c4-_z49VYiW=eik5{hC*J}>#{NL3a@*qE&uTT8g M&dWFN3#cKLU(g>rd;kCd literal 0 HcmV?d00001 diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/mul3.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/mul3.tflite new file mode 100644 index 0000000000000000000000000000000000000000..a0b90cde827a2fbf8c03c970d7b69a82d0762c9d GIT binary patch literal 568 zcmaKpy-EW?6os$4#t?K3Q6a?^DJ(2x@h`m~2tooP_De7eF60 zVN-kotKf^|6MTSoa7vAUqB&iux82!z$!rT`NgkE+e3oQ!bRU;@Ns&`+!SmQ_UYB?n z4#NXtvo<-5M;BLvvm)o-ES`o`d|dza;8T(J0oVibEe-V~W3Plqu&kUVuYz*L0LW)H zNigL*EzM_*2}zr^(`QqE;ssSzHTM@a%{uOurqF@M>WTLZU%fRm)_c0ASxQfFJWrz| z;se~bU%oi%OFb>}H^?v3$xVD)q|>;J_*8USPOJ7W)%u6!UvJBYw06ONTJrGC`yOgi F`2m6sIxheK literal 0 HcmV?d00001 diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/pad.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/pad.tflite new file mode 100644 index 0000000000000000000000000000000000000000..bc5c86a3346c0f76dce3ecefa67f621d2c1341d5 GIT binary patch literal 628 zcmYL{PfG$(6va8qg8cq7TrbWgo83(W+%M zo!`8y2j|^8_s_ZKK5a?5z387vyK1SZvZ|`9;b_wlY2654(n}td4sF+rjxX$+v0=0e zQe@mY*t9)$jC|FA7xr@Q%f7T{Op|mte@vIjG#)<1^F=aC_3@o$^FU}6Ls&_y6T666L>3m7u}T*J|KRbWf^;+g;|jS5AU~SY#VTsAB@I&b-h$F zOVM|zjcnlp%mmZ}xIlQ5vUP{w^H+O;+0?Jz2cLQ@8vLw_WgaX2@icNT{4?NzgW2fk dZRuw={eW-w7)(a@@xyE~j_3OF9z|!!{Q#PbH5dQ@ literal 0 HcmV?d00001 diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/pow.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/pow.tflite new file mode 100644 index 0000000000000000000000000000000000000000..2920f9ae4ea94037653ece5ecc754d364398540d GIT binary patch literal 544 zcmYk3K}y3=6h*JK+EAqybhf>5YZ#Ca(;V4zJPtvYo9EbXga`Ec|8zyH4b-hT-t-CPV#rG15}D$uT)I)rV(NSmNINzXYeoe(#`5g*4F zum!$3e1Q+}4$j~RI4bwGdywx%CFuan;$)QFCyRI%jUJ+G9;XTHHo7X`Lf0hrI=ybE z%VxFqh?j%@b^AO`$Xi5{4orit|KHGnaqn$#4BWRZ{H7o92Bx3_yxgndvttXm&)GPp zse1knyVv2|lke90vPYq2wlh`lW6aH~akoUFb7? literal 0 HcmV?d00001 diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/range.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/range.tflite new file mode 100644 index 0000000000000000000000000000000000000000..6e9afb7babd40411e17e8cc92a62ef4f09e8686e GIT binary patch literal 428 zcmZ9IL2JT55QSfBEP_ErbMTOZ2hY9q(qly^6%?fOC}=Q?2FwOh+mjT3K!216&;BAI zzL!J<2fm%zN#^a_^#Odnk6(Z`d^o7VMGGFgU3P#9(N65j+-FuikbmNk1vfKtWc^C? z%_Y*4YAvq|y$0o=LeB5h4Qu5nQ;(V;E6sRuEm|CRmK~zCkKMTi9Y2~y2?6FTGf&? ouq(q_O4623FRzN%l~2uS=6=4;-gFZz%{tkHCdD~_6DOa(07&F3RR910 literal 0 HcmV?d00001 diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/rank.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/rank.tflite new file mode 100644 index 0000000000000000000000000000000000000000..8733544ebade9d06f229c0cbfc888030d5933c96 GIT binary patch literal 432 zcmZ9IL2JT55QU!_ZJU&t+pXd%Rm*nVni}k@an8W1GUxV9X9csLXbrH9IHniRV!K01&B!GiZ*9m+5tSLF~R0lKaJc zncUVDdmERfFe4oQ`5(c^cMKA62IPAme1Z(fpFYJ7GjhG9T<4e>c>huzz{!hx-E6lX z=8ouuIg*KbUv1lJM|a9g@|zzLr6Vj|u_ciAe64p(eHQ+N-XRU?{iksZ|4^)-+;d%I MuCZ_KjM$g<4>5lyNdN!< literal 0 HcmV?d00001 diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/resize_nearest_neighbor.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/resize_nearest_neighbor.tflite new file mode 100644 index 0000000000000000000000000000000000000000..6a55540324eeb8492b3f4d448aa4a378e2b28e4a GIT binary patch literal 640 zcmZuv%}T>S7#wS?p_W?wfg(Bd&_fSWTk65Hf}q4A#e0cnv4J#!w2JiX1N5<)M@qQEJ6i|BI_Z-^aY zSYwWe8SIfS7*oDUNLT7^u?E+`A+d;(S@x2wqJ^2gnrs=R2|j=FT=_OJ8jQw+5f|my zC*S!u)9zK8@cWes2aL4n_Ro8Z5qa(sJ)%#@v(Dnv&=>iQkT(r6?H25j)q4>{iFBnS z@4Iv(U5?uhC!I;(eb8%FFAWW=+bF73-LT<6@yk5VbuM{PuX92=+6!U1KPFGjGFqF7 z2{N->O-%GWe@rvRH`D;?RCYMqdfjVPZ|}pUXZtTp-!=7>NAZxTe4lXrZ?7};mwvtQ pXzxRA?JJS4w4|f6=$@;y=sgJ9?-BQL@MPv`9GVQ@^zSgE+%Mp4Mo$0$ literal 0 HcmV?d00001 diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/reverse.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/reverse.tflite new file mode 100644 index 0000000000000000000000000000000000000000..96b50b4e23d808d6016149c934838e6452257635 GIT binary patch literal 596 zcmaJ;%SyvQ6g}41##(BrU38H}7G1cIXtfLXf*@2VMO<2f9q2%lKw8BQ@B{n=Kgq8V z7h*hT#@EV$Gxy$eUuTjCz}5Nq1n43{fDkQo&?DO?18fpL0v;U;9MEpa=Oz0@Y!N|? z7cn9EMw~KKzC~!RriadFE$tqW*?d;sHSxJ}e6WX1nHV2wcyCyfu zNsn^h_3F{_b5z@4PWnbA3$znSDT=(*oYUMs=$9 z?+v-l|0}(hr=~s9Bs(CqUr_#M_F?*9SDIIMdzI}u&;NPVs$YHo>D^&|vP^HyqFByN MiFfJ^I7b>k0kf?)7XSbN literal 0 HcmV?d00001 diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sigmoid.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sigmoid.tflite new file mode 100644 index 0000000000000000000000000000000000000000..d636c870ec1f9c9ed435fc3c10044f16d85aab85 GIT binary patch literal 476 zcmZvZ!AiqW5Jg9gwbT-ecF{!^S-5Z&EcyY0AP5yi-Irn>`k+Z5R=>bS7cTt_zr=46 z;<jGdr}zBJ11GMmC0>z?kiTP?@b;*6f71C7wg^6GY&H zVh!HG1+{uZAWbRv+dOCK9*?us!A?&Y(FWPP6HGc1p7O4v06i z>$~)_D%o4PJcEgG{O3Q0k?#bg;26mFHuwTLkUxEj9VX;@OR?~n8MOYTI)IZG^}5+^ zKg{jX33DW|df!dcXh(O-OS;K-iPF)=y?-hypHuf*PVX4ES@;urhcu-3pT<7??Q-$x Qo~vc%p@h;K2{{D?Ewo z%&tKXE==a_?7sKrB}oC?U5!qGeWZvGqk{xJs(mWJCJ}bPi&udGc|$QD;#XpeNL$p1 zF~x*@K~3i!LUmO=_AwX(2Si!eX}z|qqBPSdQ$H4!#mAR(I!}mUex9F@o3+Q_W^_Ht zE-TCXD>Kijbm{ijdzXqlXT%Y4Ovtll8PL!>c|pjVmY8-u_sQyA&I${(y?0e^QP=bZA?J0s*p@2aUGU9ni%w-0M$o(LJ7_M|>G=u6U!Xe5Ri1pG5%So05dZbB{Vp+H T&hE{kTFy<4PtFmsrs{tKNtrWS literal 0 HcmV?d00001 diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sub1.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sub1.tflite new file mode 100644 index 0000000000000000000000000000000000000000..8e3b3aaf8072610482befb19fd41f4db480f6b9c GIT binary patch literal 572 zcmYjOu}T9$6dd)8A%=LUMT#p@SVWLh5hP_m5QGRp?L#yN9_04mOhg+iKfq7%L&R^e zw6L}k*O}cM-hUH-Gb^^ADEH$HIZf0qgjP8@-F3kM(xWD=8U(e1zY78!Z&5IaPdkY~*j($E|810in;<>f_=nAJNQr$)Nc z(VMK%jdU4Nn~P@By{5Icte1wu>o#1KsvDl(75~KhnydP*s?+;PPyFTl8n3(u)L0#G z^=GOB`u!^27kbjrx%{h-w4_O`{YSU2InK|dQ~#$mlj>AczFF1JI{D#re3RVf(@9d` Khy4O7N#PHW;yZHy literal 0 HcmV?d00001 diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sub2.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sub2.tflite new file mode 100644 index 0000000000000000000000000000000000000000..dbca4e40a1a9f239d2644e2e31442715dcdaffaf GIT binary patch literal 564 zcmYjOu}T9$6dd(5A!rOHMT#p@q=+D=K@iJ;AP5me(;v|+c#zwJGm(6Nm6e~A!Y{D0 zwD1e8#dT&chd!8{-FNTJ&f5zCjLwJ0z#c*bsA3xpw3ux(18fk*33&2Z;DEeF^tgy$ zh)v>?hYw;zyc4I)k*El-EA^`1gEs+9B28?Z&+RNpP5fx`ha|K3`f*O*8$>@kiH^u+ z>~eECytwY1WtR0bGl`g~)9s)4Iy3UzA-Y75kY~*j(9kP+LCBjzyuRX)th>{3Vx=n` zy-9^`q{|4~Tr`vFTF$w$ztmuwQS)8ut`&)W)jhLbbCvI^`_!lRlb-lyejE46OV$Eg zR0y~h-&F$)25&1J^~#GpDJq2TKV0~(qF!@oSNvVgArJDS`MSh^4?8?xO~-fUKATQV N?!A2TzJMB1`32_lJCgta literal 0 HcmV?d00001 diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sub3.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sub3.tflite new file mode 100644 index 0000000000000000000000000000000000000000..c223cdbf90f32c04494de874f1be4fb1a37b0c72 GIT binary patch literal 568 zcmaKp%}T>S6os!E+fp!OP+x^ST&!9Thd1VN}E>ONE(Fwi6rTXEqdxN_xV_zXUW z3l}bY2qAuFVz4U*&fK||GiT1d6PVf6$?(8z-2(HhWh>UP4XQmVW=o*T%${7;Y=^i2 z4%rl6z%uwE`2-)}9UM_3plD84>MeIRUNY-~G|8f3mQ9m1j_%{)F3B^h4R{`V#p@9F z!a=x8tk)Wcv*GDQ|2WUMH;u<36(84sJ@{1Qy$`m4d`m+;$=EC55iBZa$*Z7TF#z(J zjuK4yPD}G?G9hWRf*zat6E7&svc5mBY1VePG=(-i*0y-h@YP#AW4)()nx*s@n^`)NX`K#pTlhI9ln@`4Z5%H<$G@MrDU#is)%fH^14{2?J|Fq=coA*7` Gr1Arqb~;J` literal 0 HcmV?d00001 diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_abs_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_abs_parser_test.cc index c90ff924a1..7f0453bd11 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_abs_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_abs_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserAbs : public TestTfliteParser { public: - TestTfliteParserAbs() {} + TestTfliteParserAbs() = default; void SetUp() override { meta_graph = LoadAndConvert("./abs.tflite", ""); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_add_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_add_parser_test.cc new file mode 100644 index 0000000000..d590be8131 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_add_parser_test.cc @@ -0,0 +1,78 @@ +/** + * 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 "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserAdd1 : public TestTfliteParser { + public: + TestTfliteParserAdd1() = default; + void SetUp() override { meta_graph = LoadAndConvert("./add1.tflite", ""); } +}; + +TEST_F(TestTfliteParserAdd1, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Add) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserAdd1, Tensor) { + ASSERT_GT(meta_graph->allTensors.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(0)->data.size(), 0); + ASSERT_GT(meta_graph->allTensors.at(1)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(2)->data.size(), 0); +} + +class TestTfliteParserAdd2 : public TestTfliteParser { + public: + TestTfliteParserAdd2() = default; + void SetUp() override { meta_graph = LoadAndConvert("./add2.tflite", ""); } +}; + +TEST_F(TestTfliteParserAdd2, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Add) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserAdd2, Tensor) { + ASSERT_GT(meta_graph->allTensors.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(0)->data.size(), 0); + ASSERT_GT(meta_graph->allTensors.at(1)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(2)->data.size(), 0); +} + +class TestTfliteParserAdd3 : public TestTfliteParser { + public: + TestTfliteParserAdd3() = default; + void SetUp() override { meta_graph = LoadAndConvert("./add3.tflite", ""); } +}; + +TEST_F(TestTfliteParserAdd3, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Add) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserAdd3, Tensor) { + ASSERT_GT(meta_graph->allTensors.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(0)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(1)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(2)->data.size(), 0); +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_addn_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_addn_parser_test.cc index 89519cea10..72a8237673 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_addn_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_addn_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserAddN : public TestTfliteParser { public: - TestTfliteParserAddN() {} + TestTfliteParserAddN() = default; void SetUp() override { meta_graph = LoadAndConvert("./addn.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_argmin_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_argmin_parser_test.cc new file mode 100644 index 0000000000..0bb625ec87 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_argmin_parser_test.cc @@ -0,0 +1,45 @@ +/** + * 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 "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserArgmin : public TestTfliteParser { + public: + TestTfliteParserArgmin() = default; + void SetUp() override { meta_graph = LoadAndConvert("./argmin.tflite", ""); } +}; + +TEST_F(TestTfliteParserArgmin, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_ArgMin) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserArgmin, AttrValue) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + + auto val = meta_graph->nodes.front()->primitive->value.AsArgMin(); + ASSERT_EQ(val->axis, 1); + ASSERT_EQ(val->topK, 1); + ASSERT_EQ(val->axisType, 1); + ASSERT_EQ(val->keepDims, false); + ASSERT_EQ(val->outMaxValue, false); +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_batch_to_space_nd_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_batch_to_space_nd_parser_test.cc index 4d37fa506a..c78d8eac54 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_batch_to_space_nd_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_batch_to_space_nd_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserBatchToSpaceNd : public TestTfliteParser { public: - TestTfliteParserBatchToSpaceNd() {} + TestTfliteParserBatchToSpaceNd() = default; void SetUp() override { meta_graph = LoadAndConvert("./batch_to_space_nd.tflite"); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_cast_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_cast_parser_test.cc index c986d595d7..28fe10828c 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_cast_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_cast_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserCast : public TestTfliteParser { public: - TestTfliteParserCast() {} + TestTfliteParserCast() = default; void SetUp() override { meta_graph = LoadAndConvert("./cast.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_ceil_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_ceil_parser_test.cc new file mode 100644 index 0000000000..59d8664be1 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_ceil_parser_test.cc @@ -0,0 +1,33 @@ +/** + * 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 "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserCeil : public TestTfliteParser { + public: + TestTfliteParserCeil() = default; + void SetUp() override { meta_graph = LoadAndConvert("./ceil.tflite", ""); } +}; + +TEST_F(TestTfliteParserCeil, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Ceil) << "wrong Op Type"; +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_cos_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_cos_parser_test.cc index 785cd35e44..756cd626c6 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_cos_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_cos_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserCos : public TestTfliteParser { public: - TestTfliteParserCos() {} + TestTfliteParserCos() = default; void SetUp() override { meta_graph = LoadAndConvert("./cos.tflite", ""); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_depth_to_space_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_depth_to_space_parser_test.cc index d1983e0b84..5283c0a85d 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_depth_to_space_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_depth_to_space_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserDepthToSpace : public TestTfliteParser { public: - TestTfliteParserDepthToSpace() {} + TestTfliteParserDepthToSpace() = default; void SetUp() override { meta_graph = LoadAndConvert("./depth_to_space.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_div_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_div_parser_test.cc new file mode 100644 index 0000000000..8ee47212a4 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_div_parser_test.cc @@ -0,0 +1,78 @@ +/** + * 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 "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserDiv1 : public TestTfliteParser { + public: + TestTfliteParserDiv1() = default; + void SetUp() override { meta_graph = LoadAndConvert("./div1.tflite", ""); } +}; + +TEST_F(TestTfliteParserDiv1, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Div) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserDiv1, Tensor) { + ASSERT_GT(meta_graph->allTensors.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(0)->data.size(), 0); + ASSERT_GT(meta_graph->allTensors.at(1)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(2)->data.size(), 0); +} + +class TestTfliteParserDiv2 : public TestTfliteParser { + public: + TestTfliteParserDiv2() = default; + void SetUp() override { meta_graph = LoadAndConvert("./div2.tflite", ""); } +}; + +TEST_F(TestTfliteParserDiv2, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Div) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserDiv2, Tensor) { + ASSERT_GT(meta_graph->allTensors.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(0)->data.size(), 0); + ASSERT_GT(meta_graph->allTensors.at(1)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(2)->data.size(), 0); +} + +class TestTfliteParserDiv3 : public TestTfliteParser { + public: + TestTfliteParserDiv3() = default; + void SetUp() override { meta_graph = LoadAndConvert("./div3.tflite", ""); } +}; + +TEST_F(TestTfliteParserDiv3, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Div) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserDiv3, Tensor) { + ASSERT_GT(meta_graph->allTensors.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(0)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(1)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(2)->data.size(), 0); +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_equal_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_equal_parser_test.cc index 7e816a9d39..ba2e4b0f51 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_equal_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_equal_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserEqual : public TestTfliteParser { public: - TestTfliteParserEqual() {} + TestTfliteParserEqual() = default; void SetUp() override { meta_graph = LoadAndConvert("./equal.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_fill_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_fill_parser_test.cc new file mode 100644 index 0000000000..359d54b6e5 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_fill_parser_test.cc @@ -0,0 +1,42 @@ +/** + * 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 "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserFill : public TestTfliteParser { + public: + TestTfliteParserFill() = default; + void SetUp() override { meta_graph = LoadAndConvert("./fill.tflite", ""); } +}; + +TEST_F(TestTfliteParserFill, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Fill) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserFill, AttrValue) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + + auto val = meta_graph->nodes.front()->primitive->value.AsFill(); + + std::vector dims = {9}; + ASSERT_EQ(val->dims, dims); +} +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_floor_div_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_floor_div_parser_test.cc new file mode 100644 index 0000000000..d92c1608a7 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_floor_div_parser_test.cc @@ -0,0 +1,33 @@ +/** + * 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 "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserFloorDiv : public TestTfliteParser { + public: + TestTfliteParserFloorDiv() = default; + void SetUp() override { meta_graph = LoadAndConvert("./floor_div.tflite", ""); } +}; + +TEST_F(TestTfliteParserFloorDiv, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_FloorDiv) << "wrong Op Type"; +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_floor_mod_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_floor_mod_parser_test.cc new file mode 100644 index 0000000000..f8cf0fdf03 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_floor_mod_parser_test.cc @@ -0,0 +1,33 @@ +/** + * 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 "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserFloorMod : public TestTfliteParser { + public: + TestTfliteParserFloorMod() = default; + void SetUp() override { meta_graph = LoadAndConvert("./floor_mod.tflite", ""); } +}; + +TEST_F(TestTfliteParserFloorMod, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_FloorMod) << "wrong Op Type"; +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_floor_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_floor_parser_test.cc new file mode 100644 index 0000000000..d7777f24b9 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_floor_parser_test.cc @@ -0,0 +1,33 @@ +/** + * 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 "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserFloor : public TestTfliteParser { + public: + TestTfliteParserFloor() = default; + void SetUp() override { meta_graph = LoadAndConvert("./floor.tflite", ""); } +}; + +TEST_F(TestTfliteParserFloor, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Floor) << "wrong Op Type"; +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_gather_nd_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_gather_nd_parser_test.cc new file mode 100644 index 0000000000..d6badec6a7 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_gather_nd_parser_test.cc @@ -0,0 +1,41 @@ +/** + * 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 "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserGatherNd : public TestTfliteParser { + public: + TestTfliteParserGatherNd() = default; + void SetUp() override { meta_graph = LoadAndConvert("./gather_nd.tflite", ""); } +}; + +TEST_F(TestTfliteParserGatherNd, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_GatherNd) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserGatherNd, AttrValue) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + + auto val = meta_graph->nodes.front()->primitive->value.AsGatherNd(); + ASSERT_EQ(val->batchDims, 0); +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_gather_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_gather_parser_test.cc new file mode 100644 index 0000000000..13420abada --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_gather_parser_test.cc @@ -0,0 +1,42 @@ +/** + * 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 "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserGather : public TestTfliteParser { + public: + TestTfliteParserGather() = default; + void SetUp() override { meta_graph = LoadAndConvert("./gather.tflite", ""); } +}; + +TEST_F(TestTfliteParserGather, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Gather) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserGather, AttrValue) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + + auto val = meta_graph->nodes.front()->primitive->value.AsGather(); + ASSERT_EQ(val->axis, 0); + ASSERT_EQ(val->batchDims, 0); +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_greater_equal_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_greater_equal_parser_test.cc index 3b5dba47c2..c65b80cc88 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_greater_equal_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_greater_equal_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserGreaterEqual : public TestTfliteParser { public: - TestTfliteParserGreaterEqual() {} + TestTfliteParserGreaterEqual() = default; void SetUp() override { meta_graph = LoadAndConvert("./greater_equal.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_greater_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_greater_parser_test.cc index 055dbab7da..b765fc8d85 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_greater_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_greater_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserGreater : public TestTfliteParser { public: - TestTfliteParserGreater() {} + TestTfliteParserGreater() = default; void SetUp() override { meta_graph = LoadAndConvert("./greater.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_leaky_relu_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_leaky_relu_parser_test.cc new file mode 100644 index 0000000000..80c8826088 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_leaky_relu_parser_test.cc @@ -0,0 +1,42 @@ +/** + * 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 "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserLeakyRelu : public TestTfliteParser { + public: + TestTfliteParserLeakyRelu() = default; + void SetUp() override { meta_graph = LoadAndConvert("./leaky_relu.tflite", ""); } +}; + +TEST_F(TestTfliteParserLeakyRelu, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_LeakyReLU) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserLeakyRelu, AttrValue) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + + auto val = meta_graph->nodes.front()->primitive->value.AsLeakyReLU(); + ASSERT_NE(val, nullptr); + ASSERT_EQ(val->negativeSlope, 0.20000000298023224); +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_less_equal_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_less_equal_parser_test.cc index 6c1d29877f..06f57a4bab 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_less_equal_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_less_equal_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserLessEqual : public TestTfliteParser { public: - TestTfliteParserLessEqual() {} + TestTfliteParserLessEqual() = default; void SetUp() override { meta_graph = LoadAndConvert("./less_equal.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_less_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_less_parser_test.cc index 795acfce7d..1872d2d3f1 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_less_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_less_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserLess : public TestTfliteParser { public: - TestTfliteParserLess() {} + TestTfliteParserLess() = default; void SetUp() override { meta_graph = LoadAndConvert("./less.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_log_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_log_parser_test.cc index fe869019ce..22976eceb8 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_log_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_log_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserLog : public TestTfliteParser { public: - TestTfliteParserLog() {} + TestTfliteParserLog() = default; void SetUp() override { meta_graph = LoadAndConvert("./log.tflite", ""); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_and_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_and_parser_test.cc index 415dc874ee..a1a5159ae0 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_and_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_and_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteLogicalParserAnd : public TestTfliteParser { public: - TestTfliteLogicalParserAnd() {} + TestTfliteLogicalParserAnd() = default; void SetUp() override { meta_graph = LoadAndConvert("./logical_and.tflite", ""); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_not_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_not_parser_test.cc index a34ae07afe..cb2c21411e 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_not_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_not_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserLogicalNot : public TestTfliteParser { public: - TestTfliteParserLogicalNot() {} + TestTfliteParserLogicalNot() = default; void SetUp() override { meta_graph = LoadAndConvert("./logical_not.tflite", ""); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_or_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_or_parser_test.cc index 19141d6125..508293542f 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_or_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_or_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserLogicalOr : public TestTfliteParser { public: - TestTfliteParserLogicalOr() {} + TestTfliteParserLogicalOr() = default; void SetUp() override { meta_graph = LoadAndConvert("./logical_or.tflite", ""); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_lrn_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_lrn_parser_test.cc new file mode 100644 index 0000000000..88a504a6ae --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_lrn_parser_test.cc @@ -0,0 +1,45 @@ +/** + * 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 "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserLRN : public TestTfliteParser { + public: + TestTfliteParserLRN() = default; + void SetUp() override { meta_graph = LoadAndConvert("./lrn.tflite", ""); } +}; + +TEST_F(TestTfliteParserLRN, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, + schema::PrimitiveType_LocalResponseNormalization) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserLRN, AttrValue) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + + auto val = meta_graph->nodes.front()->primitive->value.AsLocalResponseNormalization(); + ASSERT_EQ(val->alpha, 1); + ASSERT_EQ(val->beta, 0.5); + ASSERT_EQ(val->bias, 1); + ASSERT_EQ(val->depth_radius, 5); +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_maximum_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_maximum_parser_test.cc index a21dba4d8b..b99119df5a 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_maximum_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_maximum_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserMaximum : public TestTfliteParser { public: - TestTfliteParserMaximum() {} + TestTfliteParserMaximum() = default; void SetUp() override { meta_graph = LoadAndConvert("./maximum.tflite"); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_minimum_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_minimum_parser_test.cc index 2999d33b16..431a15e5bd 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_minimum_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_minimum_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserMinimum : public TestTfliteParser { public: - TestTfliteParserMinimum() {} + TestTfliteParserMinimum() = default; void SetUp() override { meta_graph = LoadAndConvert("./minimum.tflite"); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_mul_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_mul_parser_test.cc new file mode 100644 index 0000000000..140960e53b --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_mul_parser_test.cc @@ -0,0 +1,78 @@ +/** + * 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 "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserMul1 : public TestTfliteParser { + public: + TestTfliteParserMul1() = default; + void SetUp() override { meta_graph = LoadAndConvert("./mul1.tflite", ""); } +}; + +TEST_F(TestTfliteParserMul1, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Mul) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserMul1, Tensor) { + ASSERT_GT(meta_graph->allTensors.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(0)->data.size(), 0); + ASSERT_GT(meta_graph->allTensors.at(1)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(2)->data.size(), 0); +} + +class TestTfliteParserMul2 : public TestTfliteParser { + public: + TestTfliteParserMul2() = default; + void SetUp() override { meta_graph = LoadAndConvert("./mul2.tflite", ""); } +}; + +TEST_F(TestTfliteParserMul2, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Mul) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserMul2, Tensor) { + ASSERT_GT(meta_graph->allTensors.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(0)->data.size(), 0); + ASSERT_GT(meta_graph->allTensors.at(1)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(2)->data.size(), 0); +} + +class TestTfliteParserMul3 : public TestTfliteParser { + public: + TestTfliteParserMul3() = default; + void SetUp() override { meta_graph = LoadAndConvert("./mul3.tflite", ""); } +}; + +TEST_F(TestTfliteParserMul3, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Mul) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserMul3, Tensor) { + ASSERT_GT(meta_graph->allTensors.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(0)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(1)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(2)->data.size(), 0); +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_not_equal_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_not_equal_parser_test.cc index e7260a1262..3e697c862e 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_not_equal_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_not_equal_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserNotEqual : public TestTfliteParser { public: - TestTfliteParserNotEqual() {} + TestTfliteParserNotEqual() = default; void SetUp() override { meta_graph = LoadAndConvert("./not_equal.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_one_hot_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_one_hot_parser_test.cc index f1f007e849..ed3d946a96 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_one_hot_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_one_hot_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserOneHot : public TestTfliteParser { public: - TestTfliteParserOneHot() {} + TestTfliteParserOneHot() = default; void SetUp() override { meta_graph = LoadAndConvert("./one_hot.tflite"); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_p_relu_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_p_relu_parser_test.cc index 11e5fe7c14..7b64cb1d02 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_p_relu_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_p_relu_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserPrelu : public TestTfliteParser { public: - TestTfliteParserPrelu() {} + TestTfliteParserPrelu() = default; void SetUp() override { meta_graph = LoadAndConvert("./prelu.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_pad_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_pad_parser_test.cc new file mode 100644 index 0000000000..ada4657759 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_pad_parser_test.cc @@ -0,0 +1,43 @@ +/** + * 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 "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserPad : public TestTfliteParser { + public: + TestTfliteParserPad() = default; + void SetUp() override { meta_graph = LoadAndConvert("./pad.tflite", ""); } +}; + +TEST_F(TestTfliteParserPad, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Pad) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserPad, AttrValue) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + + auto val = meta_graph->nodes.front()->primitive->value.AsPad(); + + std::vector paddings = {1, 1, 2, 2, 3, 3, 4, 4}; + ASSERT_EQ(val->paddings, paddings); +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_parsers_test_utils.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_parsers_test_utils.cc index 881d95b89f..66ec6ad1ec 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_parsers_test_utils.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_parsers_test_utils.cc @@ -22,9 +22,12 @@ namespace mindspore { schema::MetaGraphT *TestTfliteParser::LoadAndConvert(const string &model_path, const string &weight_path) { - schema::MetaGraphT *meta_graph = nullptr; lite::TfliteModelParser parser; meta_graph = parser.Parse(model_path, weight_path); + if (meta_graph == nullptr) { + MS_LOG(ERROR) << "Parse to metaGraph return nullptr"; + return nullptr; + } return meta_graph; } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h index cf592570c3..200e322c7c 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h @@ -24,10 +24,10 @@ namespace mindspore { class TestTfliteParser : public Common { public: - TestTfliteParser() {} + TestTfliteParser() = default; void TearDown() override; schema::MetaGraphT *LoadAndConvert(const std::string &model_path, const std::string &weight_path = ""); - schema::MetaGraphT *meta_graph; + schema::MetaGraphT *meta_graph = nullptr; }; } // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_pow_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_pow_parser_test.cc new file mode 100644 index 0000000000..52188a5d9b --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_pow_parser_test.cc @@ -0,0 +1,44 @@ +/** + * 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 "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserPow : public TestTfliteParser { + public: + TestTfliteParserPow() = default; + void SetUp() override { meta_graph = LoadAndConvert("./pow.tflite", ""); } +}; + +TEST_F(TestTfliteParserPow, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Power) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserPow, AttrValue) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + + auto val = meta_graph->nodes.front()->primitive->value.AsPower(); + + ASSERT_EQ(val->scale, 1.0); + ASSERT_EQ(val->shift, 0.0); + ASSERT_EQ(val->power, 0.0); +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_max_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_max_parser_test.cc index 6c2ff57114..8b5c97a3f8 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_max_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_max_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserReduceMax : public TestTfliteParser { public: - TestTfliteParserReduceMax() {} + TestTfliteParserReduceMax() = default; void SetUp() override { meta_graph = LoadAndConvert("./reduce_max.tflite"); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_min_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_min_parser_test.cc index dce6a95fb0..01995e9bba 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_min_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_min_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserReduceMin : public TestTfliteParser { public: - TestTfliteParserReduceMin() {} + TestTfliteParserReduceMin() = default; void SetUp() override { meta_graph = LoadAndConvert("./reduce_min.tflite"); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_prod_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_prod_parser_test.cc index dc19ad983f..2b0352231f 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_prod_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_prod_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserReduceProd : public TestTfliteParser { public: - TestTfliteParserReduceProd() {} + TestTfliteParserReduceProd() = default; void SetUp() override { meta_graph = LoadAndConvert("./reduce_prod.tflite"); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_relu_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_relu_parser_test.cc new file mode 100644 index 0000000000..a0d44c30cd --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_relu_parser_test.cc @@ -0,0 +1,33 @@ +/** + * 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 "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserRelu : public TestTfliteParser { + public: + TestTfliteParserRelu() = default; + void SetUp() override { meta_graph = LoadAndConvert("./relu.tflite", ""); } +}; + +TEST_F(TestTfliteParserRelu, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Activation) << "wrong Op Type"; +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_resize_nn_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_resize_nn_parser_test.cc new file mode 100644 index 0000000000..199c560f13 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_resize_nn_parser_test.cc @@ -0,0 +1,44 @@ +/** + * 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 "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserResizeNN : public TestTfliteParser { + public: + TestTfliteParserResizeNN() = default; + void SetUp() override { meta_graph = LoadAndConvert("./resize_nearest_neighbor.tflite", ""); } +}; + +TEST_F(TestTfliteParserResizeNN, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Resize) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserResizeNN, AttrValue) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + + auto val = meta_graph->nodes.front()->primitive->value.AsResize(); + + ASSERT_EQ(val->alignCorners, false); + ASSERT_EQ(val->newHeight, 3); + ASSERT_EQ(val->newWidth, 100); +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reverse_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reverse_parser_test.cc new file mode 100644 index 0000000000..ea1ffff935 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reverse_parser_test.cc @@ -0,0 +1,43 @@ +/** + * 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 "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserReverse : public TestTfliteParser { + public: + TestTfliteParserReverse() = default; + void SetUp() override { meta_graph = LoadAndConvert("./reverse.tflite", ""); } +}; + +TEST_F(TestTfliteParserReverse, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Reverse) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserReverse, AttrValue) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + + auto val = meta_graph->nodes.front()->primitive->value.AsReverse(); + + std::vector axis = {3}; + ASSERT_EQ(val->axis, axis); +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reverse_sequence_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reverse_sequence_parser_test.cc index f1a972f6e4..a5f3e58d99 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reverse_sequence_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reverse_sequence_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserReverseSequence : public TestTfliteParser { public: - TestTfliteParserReverseSequence() {} + TestTfliteParserReverseSequence() = default; void SetUp() override { meta_graph = LoadAndConvert("./reverse_sequence.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_round_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_round_parser_test.cc index ffb6a26ffe..9ec5ed9b21 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_round_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_round_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserRound : public TestTfliteParser { public: - TestTfliteParserRound() {} + TestTfliteParserRound() = default; void SetUp() override { meta_graph = LoadAndConvert("./round.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_rsqrt_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_rsqrt_parser_test.cc index c1db7380cb..9b8afe78b3 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_rsqrt_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_rsqrt_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserRsqrt : public TestTfliteParser { public: - TestTfliteParserRsqrt() {} + TestTfliteParserRsqrt() = default; void SetUp() override { meta_graph = LoadAndConvert("./rsqrt.tflite", ""); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sin_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sin_parser_test.cc index a859cabc87..6ad75bb28c 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sin_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sin_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserSin : public TestTfliteParser { public: - TestTfliteParserSin() {} + TestTfliteParserSin() = default; void SetUp() override { meta_graph = LoadAndConvert("./sin.tflite", ""); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_space_to_batch_nd_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_space_to_batch_nd_parser_test.cc index a9d66ceaf4..dab7110c1a 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_space_to_batch_nd_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_space_to_batch_nd_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserSpaceToBatchND : public TestTfliteParser { public: - TestTfliteParserSpaceToBatchND() {} + TestTfliteParserSpaceToBatchND() = default; void SetUp() override { meta_graph = LoadAndConvert("./space_to_batch_nd.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_space_to_depth_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_space_to_depth_parser_test.cc index 76245204a7..785baff517 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_space_to_depth_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_space_to_depth_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserSpaceToDepth : public TestTfliteParser { public: - TestTfliteParserSpaceToDepth() {} + TestTfliteParserSpaceToDepth() = default; void SetUp() override { meta_graph = LoadAndConvert("./space_to_depth.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sparse_to_dense_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sparse_to_dense_parser_test.cc index 043fdbfe63..93e7badacf 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sparse_to_dense_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sparse_to_dense_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserSparseToDense : public TestTfliteParser { public: - TestTfliteParserSparseToDense() {} + TestTfliteParserSparseToDense() = default; void SetUp() override { meta_graph = LoadAndConvert("./sparse_to_dense.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_split_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_split_parser_test.cc index aae2b629d1..b7c9e38cb9 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_split_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_split_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserSplit : public TestTfliteParser { public: - TestTfliteParserSplit() {} + TestTfliteParserSplit() = default; void SetUp() override { meta_graph = LoadAndConvert("./split.tflite"); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_split_v_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_split_v_parser_test.cc index 30a7049a42..76eb564247 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_split_v_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_split_v_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserSplitV : public TestTfliteParser { public: - TestTfliteParserSplitV() {} + TestTfliteParserSplitV() = default; void SetUp() override { meta_graph = LoadAndConvert("./split_v.tflite"); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sqrt_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sqrt_parser_test.cc index 427907dc70..e66b0cb938 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sqrt_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sqrt_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserSqrt : public TestTfliteParser { public: - TestTfliteParserSqrt() {} + TestTfliteParserSqrt() = default; void SetUp() override { meta_graph = LoadAndConvert("./sqrt.tflite", ""); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_square_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_square_parser_test.cc index 96e0e71f0c..7bbfeb3eae 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_square_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_square_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserSquare : public TestTfliteParser { public: - TestTfliteParserSquare() {} + TestTfliteParserSquare() = default; void SetUp() override { meta_graph = LoadAndConvert("./square.tflite", ""); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_squared_difference_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_squared_difference_parser_test.cc index f6be7a992d..74548b4d76 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_squared_difference_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_squared_difference_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserSquaredDifference : public TestTfliteParser { public: - TestTfliteParserSquaredDifference() {} + TestTfliteParserSquaredDifference() = default; void SetUp() override { meta_graph = LoadAndConvert("./squared_difference.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_strided_slice_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_strided_slice_parser_test.cc index bbb327b998..88177cd9aa 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_strided_slice_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_strided_slice_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserStridedSlice : public TestTfliteParser { public: - TestTfliteParserStridedSlice() {} + TestTfliteParserStridedSlice() = default; void SetUp() override { meta_graph = LoadAndConvert("./strided_slice.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sub_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sub_parser_test.cc new file mode 100644 index 0000000000..3b9c0e26a6 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sub_parser_test.cc @@ -0,0 +1,78 @@ +/** + * 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 "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserSub1 : public TestTfliteParser { + public: + TestTfliteParserSub1() = default; + void SetUp() override { meta_graph = LoadAndConvert("./sub1.tflite", ""); } +}; + +TEST_F(TestTfliteParserSub1, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Sub) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserSub1, Tensor) { + ASSERT_GT(meta_graph->allTensors.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(0)->data.size(), 0); + ASSERT_GT(meta_graph->allTensors.at(1)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(2)->data.size(), 0); +} + +class TestTfliteParserSub2 : public TestTfliteParser { + public: + TestTfliteParserSub2() = default; + void SetUp() override { meta_graph = LoadAndConvert("./sub2.tflite", ""); } +}; + +TEST_F(TestTfliteParserSub2, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Sub) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserSub2, Tensor) { + ASSERT_GT(meta_graph->allTensors.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(0)->data.size(), 0); + ASSERT_GT(meta_graph->allTensors.at(1)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(2)->data.size(), 0); +} + +class TestTfliteParserSub3 : public TestTfliteParser { + public: + TestTfliteParserSub3() = default; + void SetUp() override { meta_graph = LoadAndConvert("./sub3.tflite", ""); } +}; + +TEST_F(TestTfliteParserSub3, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Sub) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserSub3, Tensor) { + ASSERT_GT(meta_graph->allTensors.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(0)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(1)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(2)->data.size(), 0); +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sum_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sum_parser_test.cc index f028516da2..49a5a2f091 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sum_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sum_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserSum : public TestTfliteParser { public: - TestTfliteParserSum() {} + TestTfliteParserSum() = default; void SetUp() override { meta_graph = LoadAndConvert("./sum.tflite"); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_tile_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_tile_parser_test.cc index 19401218f7..e025bad6f9 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_tile_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_tile_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserTile : public TestTfliteParser { public: - TestTfliteParserTile() {} + TestTfliteParserTile() = default; void SetUp() override { meta_graph = LoadAndConvert("./tile.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_topk_v2_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_topk_v2_parser_test.cc index d358fdb2d5..68e3629611 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_topk_v2_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_topk_v2_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserTopKV2 : public TestTfliteParser { public: - TestTfliteParserTopKV2() {} + TestTfliteParserTopKV2() = default; void SetUp() override { meta_graph = LoadAndConvert("./topk_v2.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_unique_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_unique_parser_test.cc index 244abf8ee2..5b49883b78 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_unique_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_unique_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserUnique : public TestTfliteParser { public: - TestTfliteParserUnique() {} + TestTfliteParserUnique() = default; void SetUp() override { meta_graph = LoadAndConvert("./unique.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_unstack_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_unstack_parser_test.cc index e2c03a5bec..9c8e59232e 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_unstack_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_unstack_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserUnstack : public TestTfliteParser { public: - TestTfliteParserUnstack() {} + TestTfliteParserUnstack() = default; void SetUp() override { meta_graph = LoadAndConvert("./unstack.tflite"); } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_abs_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_abs_parser.cc index 2ec1f0257d..79ca078daf 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_abs_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_abs_parser.cc @@ -14,9 +14,9 @@ * limitations under the License. */ +#include "tools/converter/parser/tflite/tflite_abs_parser.h" #include #include -#include "tools/converter/parser/tflite/tflite_abs_parser.h" namespace mindspore { namespace lite { diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_add_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_add_parser.cc index 3981b4b6ae..2976b96473 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_add_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_add_parser.cc @@ -24,9 +24,7 @@ STATUS TfliteAddParser::Parse(const std::unique_ptr &tfliteOp const std::vector> &tfliteTensors, const std::vector> &tfliteModelBuffer, const std::vector> &tfliteOpSet, - schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) { + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteAddParser"; std::unique_ptr attr(new schema::AddT()); const auto &tfliteAttr = tfliteOp->builtin_options.AsAddOptions(); @@ -34,14 +32,46 @@ STATUS TfliteAddParser::Parse(const std::unique_ptr &tfliteOp MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; return RET_NULL_PTR; } + attr->activationType = GetActivationFunctionType(tfliteAttr->fused_activation_function); - auto weight_index = tfliteOp->inputs[1]; - const auto &weight_tensor = tfliteTensors[weight_index]; - std::vector weight_tensors{weight_tensor.get()}; - if (RET_OK != ParseWeight(weight_tensors, tfliteModelBuffer, tensor_cache, schema::Format_KHWC)) { - return RET_ERROR; + auto x_index = tfliteOp->inputs[0]; + const auto &x_tensor = tfliteTensors[x_index]; + if (x_tensor == nullptr) { + MS_LOG(ERROR) << "the first input is null"; + return RET_NULL_PTR; } - attr->activationType = GetActivationFunctionType(tfliteAttr->fused_activation_function); + auto &x_data = tfliteModelBuffer.at(x_tensor->buffer); + if (x_data == nullptr) { + MS_LOG(ERROR) << "the data of the first input is null"; + return RET_NULL_PTR; + } + if (x_data->data.size() > 0) { + std::vector x_tensors{x_tensor.get()}; + if (RET_OK != ParseTensor(x_tensors, tfliteModelBuffer, tensor_cache, TF_CONST, true)) { + MS_LOG(ERROR) << "parse the first tensor failed"; + return RET_ERROR; + } + } + + auto y_index = tfliteOp->inputs[1]; + const auto &y_tensor = tfliteTensors[y_index]; + if (y_tensor == nullptr) { + MS_LOG(ERROR) << "the second input is null"; + return RET_NULL_PTR; + } + auto &y_data = tfliteModelBuffer.at(y_tensor->buffer); + if (y_data == nullptr) { + MS_LOG(ERROR) << "the data of the second input is null"; + return RET_NULL_PTR; + } + if (y_data->data.size() > 0) { + std::vector y_tensors{y_tensor.get()}; + if (RET_OK != ParseTensor(y_tensors, tfliteModelBuffer, tensor_cache, TF_CONST, true)) { + MS_LOG(ERROR) << "parse the second tensor failed"; + return RET_ERROR; + } + } + if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Add; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_addn_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_addn_parser.cc index 5dc9ee5bfd..5dd1bffd61 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_addn_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_addn_parser.cc @@ -15,22 +15,22 @@ * limitations under the License. */ +#include "tools/converter/parser/tflite/tflite_addn_parser.h" #include #include -#include "tools/converter/parser/tflite/tflite_addn_parser.h" namespace mindspore { namespace lite { -STATUS TfliteAddNParser::Parse(const std::unique_ptr &tflite_op, - const std::vector> &tflite_tensors, - const std::vector> &tflite_model_buffer, - const std::vector> &tflite_opset, - schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantized_model) { +STATUS TfliteAddNParser::Parse(const std::unique_ptr &tfliteOp, + const std::vector> &tfliteTensors, + const std::vector> &tfliteModelBuffer, + const std::vector> &tfliteOpSet, + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteAddNParser"; std::unique_ptr attr(new schema::AddNT()); - attr->N = tflite_tensors.size() - 1; + + attr->N = tfliteTensors.size() - 1; + if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_AddN; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_argmax_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_argmax_parser.cc index 30706902b8..832c881044 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_argmax_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_argmax_parser.cc @@ -29,11 +29,25 @@ STATUS TfliteArgmaxParser::Parse(const std::unique_ptr &tflit bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteArgmaxParser"; std::unique_ptr attr(new schema::ArgMaxT()); - // These are caffe attributes, set to default value. - attr->axisType = 1; + attr->outMaxValue = false; attr->topK = 1; attr->keepDims = false; + attr->axisType = 1; + + auto axis_idx = tfliteOp->inputs[1]; + std::for_each(tfliteTensors[axis_idx]->shape.begin(), tfliteTensors[axis_idx]->shape.end(), [&](int32_t sha){}); + auto &buf_data = tfliteModelBuffer[tfliteTensors[axis_idx]->buffer]; + if (buf_data == nullptr) { + MS_LOG(ERROR) << "the buf data is null"; + return RET_NULL_PTR; + } + auto data_ptr = buf_data->data.data(); + if (data_ptr == nullptr) { + MS_LOG(ERROR) << "the data is null"; + return RET_NULL_PTR; + } + attr->axis = *(static_cast(static_cast(data_ptr))); if (op != nullptr) { op->primitive = std::make_unique(); diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_argmin_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_argmin_parser.cc index 2ff86ae045..56cdec82f4 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_argmin_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_argmin_parser.cc @@ -24,29 +24,29 @@ STATUS TfliteArgminParser::Parse(const std::unique_ptr &tflit const std::vector> &tfliteTensors, const std::vector> &tfliteModelBuffer, const std::vector> &tfliteOpSet, - schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) { + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteArgminParser"; std::unique_ptr attr(new schema::ArgMinT()); - const auto &tflite_attr = tfliteOp->builtin_options.AsArgMinOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - } - // get axis + attr->outMaxValue = false; + attr->topK = 1; + attr->keepDims = false; + attr->axisType = 1; + auto axis_idx = tfliteOp->inputs[1]; std::for_each(tfliteTensors[axis_idx]->shape.begin(), tfliteTensors[axis_idx]->shape.end(), [&](int32_t sha){}); auto &buf_data = tfliteModelBuffer[tfliteTensors[axis_idx]->buffer]; + if (buf_data == nullptr) { + MS_LOG(ERROR) << "the buf data is null"; + return RET_NULL_PTR; + } auto data_ptr = buf_data->data.data(); + if (data_ptr == nullptr) { + MS_LOG(ERROR) << "the data is null"; + return RET_NULL_PTR; + } attr->axis = *(static_cast(static_cast(data_ptr))); - // the following use default values - attr->outMaxValue = false; - attr->topK = 1; - attr->keepDims = false; - attr->axisType = 0; - if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_ArgMin; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_batch_to_sapce_nd_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_batch_to_sapce_nd_parser.cc index 6ed52bfb12..3ddb49bac2 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_batch_to_sapce_nd_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_batch_to_sapce_nd_parser.cc @@ -14,9 +14,9 @@ * limitations under the License. */ +#include "tools/converter/parser/tflite/tflite_batch_to_sapce_nd_parser.h" #include #include -#include "tools/converter/parser/tflite/tflite_batch_to_sapce_nd_parser.h" namespace mindspore { namespace lite { @@ -32,11 +32,11 @@ STATUS TfliteBatchToSpaceNDParser::Parse(const std::unique_ptrinputs[1], tfliteTensors, tfliteModelBuffer, attr->blockShape)) { - MS_LOG(ERROR) << "BatchToSpaceNd get blockShape attr failed"; + MS_LOG(ERROR) << "get BatchToSpaceNd -> blockShape failed"; return RET_ERROR; } if (GetTfliteData(tfliteOp->inputs[2], tfliteTensors, tfliteModelBuffer, attr->crops)) { - MS_LOG(ERROR) << "BatchToSpaceNd get crops attr failed"; + MS_LOG(ERROR) << "get BatchToSpaceNd -> crops failed"; return RET_ERROR; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_batch_to_space_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_batch_to_space_parser.cc index 6fe391f4b6..00514a098f 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_batch_to_space_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_batch_to_space_parser.cc @@ -15,26 +15,26 @@ * limitations under the License. */ +#include "tools/converter/parser/tflite/tflite_batch_to_space_parser.h" #include #include -#include "tools/converter/parser/tflite/tflite_batch_to_space_parser.h" namespace mindspore { namespace lite { -STATUS TfliteBatchToSpaceParser::Parse(const std::unique_ptr &tflite_op, - const std::vector> &tflite_tensors, - const std::vector> &tflite_model_buffer, - const std::vector> &tflite_opset, - schema::CNodeT *op, - TensorCache *tensor_cache, bool quantized_model) { +STATUS TfliteBatchToSpaceParser::Parse(const std::unique_ptr &tfliteOp, + const std::vector> &tfliteTensors, + const std::vector> &tfliteModelBuffer, + const std::vector> &tfliteOpSet, + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteBatchToSpaceParser"; std::unique_ptr attr(new schema::BatchToSpaceT()); - if (GetTfliteData(tflite_op->inputs[1], tflite_tensors, tflite_model_buffer, attr->blockShape)) { - MS_LOG(ERROR) << "batchToSpace -> blockShape get failed"; + + if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->blockShape)) { + MS_LOG(ERROR) << "get batchToSpace -> blockShape failed"; return RET_ERROR; } - if (GetTfliteData(tflite_op->inputs[2], tflite_tensors, tflite_model_buffer, attr->crops)) { - MS_LOG(ERROR) << "batchToSpace -> crops get failed"; + if (GetTfliteData(tfliteOp->inputs[2], tfliteTensors, tfliteModelBuffer, attr->crops)) { + MS_LOG(ERROR) << "get batchToSpace -> crops failed"; return RET_ERROR; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_broadcast_to_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_broadcast_to_parser.cc index bc508ef7d6..6c6cd70568 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_broadcast_to_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_broadcast_to_parser.cc @@ -15,31 +15,31 @@ * limitations under the License. */ +#include "tools/converter/parser/tflite/tflite_broadcast_to_parser.h" #include #include -#include "tools/converter/parser/tflite/tflite_broadcast_to_parser.h" namespace mindspore { namespace lite { -STATUS TfliteBroadcastToParser::Parse(const std::unique_ptr &tflite_op, - const std::vector> &tflite_tensors, - const std::vector> &tflite_model_buffer, - const std::vector> &tflite_opset, - schema::CNodeT *op, - TensorCache *tensor_cache, bool quantized_model) { +STATUS TfliteBroadcastToParser::Parse(const std::unique_ptr &tfliteOp, + const std::vector> &tfliteTensors, + const std::vector> &tfliteModelBuffer, + const std::vector> &tfliteOpSet, + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteBroadcastToParser"; std::unique_ptr attr(new schema::BroadcastToT()); - if (GetTfliteData(tflite_op->inputs[1], tflite_tensors, tflite_model_buffer, attr->dst_shape)) { - MS_LOG(ERROR) << "broadCastTo -> dst_shape get failed"; + + if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->dst_shape)) { + MS_LOG(ERROR) << "get broadCastTo -> dst_shape failed"; return RET_ERROR; } - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_BroadcastTo; - op->primitive->value.value = attr.release(); - } - return RET_OK; + if (op != nullptr) { + op->primitive = std::make_unique(); + op->primitive->value.type = schema::PrimitiveType_BroadcastTo; + op->primitive->value.value = attr.release(); + } + return RET_OK; } TfliteNodeRegister g_tfliteBroadcastToParser("BroadcastTo", new TfliteBroadcastToParser()); diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_cast_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_cast_parser.cc index a7cce134a6..c8d71de685 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_cast_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_cast_parser.cc @@ -15,23 +15,33 @@ * limitations under the License. */ +#include "tools/converter/parser/tflite/tflite_cast_parser.h" #include #include -#include "tools/converter/parser/tflite/tflite_cast_parser.h" namespace mindspore { namespace lite { -STATUS TfliteCastParser::Parse(const std::unique_ptr &tflite_op, - const std::vector> &tflite_tensors, - const std::vector> &tflite_model_buffer, - const std::vector> &tflite_opset, - schema::CNodeT *op, - TensorCache *tensor_cache, bool quantized_model) { +STATUS TfliteCastParser::Parse(const std::unique_ptr &tfliteOp, + const std::vector> &tfliteTensors, + const std::vector> &tfliteModelBuffer, + const std::vector> &tfliteOpSet, + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteCastParser"; std::unique_ptr attr(new schema::CastT()); - attr->srcT = dtype_map[tflite_tensors[tflite_op->inputs[0]]->type]; - attr->dstT = dtype_map[tflite_tensors[tflite_op->outputs[0]]->type]; + const auto &in_tensor = tfliteTensors[tfliteOp->inputs[0]]; + if (in_tensor == nullptr) { + MS_LOG(ERROR) << "tensor is null"; + return RET_NULL_PTR; + } + attr->srcT = dtype_map[in_tensor->type]; + + const auto &out_tensor = tfliteTensors[tfliteOp->outputs[0]]; + if (out_tensor == nullptr) { + MS_LOG(ERROR) << "tensor is null"; + return RET_NULL_PTR; + } + attr->dstT = dtype_map[out_tensor->type]; if (op != nullptr) { op->primitive = std::make_unique(); diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_ceil_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_ceil_parser.cc index c8902c5f41..de924ce6b8 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_ceil_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_ceil_parser.cc @@ -14,9 +14,9 @@ * limitations under the License. */ +#include "tools/converter/parser/tflite/tflite_ceil_parser.h" #include #include -#include "tools/converter/parser/tflite/tflite_ceil_parser.h" namespace mindspore { namespace lite { @@ -24,9 +24,7 @@ STATUS TfliteCeilParser::Parse(const std::unique_ptr &tfliteO const std::vector> &tfliteTensors, const std::vector> &tfliteModelBuffer, const std::vector> &tfliteOpSet, - schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) { + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteCeilParser"; std::unique_ptr attr(new schema::CeilT()); diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_concat_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_concat_parser.cc index 5dbe6b2fea..31c7174799 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_concat_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_concat_parser.cc @@ -14,9 +14,9 @@ * limitations under the License. */ +#include "tools/converter/parser/tflite/tflite_concat_parser.h" #include #include -#include "tools/converter/parser/tflite/tflite_concat_parser.h" namespace mindspore { namespace lite { @@ -24,18 +24,17 @@ STATUS TfliteConcatParser::Parse(const std::unique_ptr &tflit const std::vector> &tfliteTensors, const std::vector> &tfliteModelBuffer, const std::vector> &tfliteOpSet, - schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) { + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteConcatParser"; std::unique_ptr attr(new schema::ConcatT()); + const auto &tfliteAttr = tfliteOp->builtin_options.AsConcatenationOptions(); if (tfliteAttr == nullptr) { MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; return RET_NULL_PTR; } - attr->axis = tfliteAttr->axis; + attr->n = tfliteOp->inputs.size(); if (op != nullptr) { diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_conv_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_conv_parser.cc index 66c2c13492..6a32fa75dd 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_conv_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_conv_parser.cc @@ -14,21 +14,20 @@ * limitations under the License. */ +#include "tools/converter/parser/tflite/tflite_conv_parser.h" #include #include -#include "tools/converter/parser/tflite/tflite_conv_parser.h" namespace mindspore { namespace lite { -STATUS TfliteConvParser::Parse(const std::unique_ptr &tflite_op, - const std::vector> &tflite_tensors, +STATUS TfliteConvParser::Parse(const std::unique_ptr &tfliteOp, + const std::vector> &tfliteTensors, const std::vector> &tfliteModelBuffer, const std::vector> &tfliteOpSet, - schema::CNodeT *op, - TensorCache *tensor_cache, bool quantizedModel) { + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteConvParser"; std::unique_ptr attr(new schema::Conv2DT()); - const auto &tfliteAttr = tflite_op->builtin_options.AsConv2DOptions(); + const auto &tfliteAttr = tfliteOp->builtin_options.AsConv2DOptions(); if (tfliteAttr == nullptr) { MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; return RET_NULL_PTR; @@ -41,11 +40,15 @@ STATUS TfliteConvParser::Parse(const std::unique_ptr &tflite_ attr->padMode = GetPadMode(tfliteAttr->padding); attr->format = schema::Format_NHWC; attr->activationType = GetActivationFunctionType(tfliteAttr->fused_activation_function); + // get the conv op weight tensor - auto weight_index = tflite_op->inputs[1]; - const auto &weight_tensor = tflite_tensors[weight_index]; + auto weight_index = tfliteOp->inputs[1]; + const auto &weight_tensor = tfliteTensors[weight_index]; + if (weight_tensor == nullptr) { + MS_LOG(ERROR) << "weight_tensor is null"; + return RET_NULL_PTR; + } std::vector weight_tensors{weight_tensor.get()}; - if (RET_OK != ParseWeight(weight_tensors, tfliteModelBuffer, tensor_cache, schema::Format_KHWC)) { MS_LOG(ERROR) << "parse weight failed"; return RET_ERROR; @@ -55,16 +58,23 @@ STATUS TfliteConvParser::Parse(const std::unique_ptr &tflite_ attr->channelOut = weight_shape[KHWC_K]; attr->kernelW = weight_shape[KHWC_W]; attr->kernelH = weight_shape[KHWC_H]; - if (tflite_op->inputs.size() == 3) { + + // get the conv op bias tensor + if (tfliteOp->inputs.size() == 3) { attr->hasBias = true; - auto bias_index = tflite_op->inputs[2]; - const auto &bias_tensor = tflite_tensors[bias_index]; + auto bias_index = tfliteOp->inputs[2]; + const auto &bias_tensor = tfliteTensors[bias_index]; + if (bias_tensor == nullptr) { + MS_LOG(ERROR) << "bias_tensor is null"; + return RET_NULL_PTR; + } std::vector bias_tensors{bias_tensor.get()}; if (RET_OK != ParseBias(bias_tensors, tfliteModelBuffer, tensor_cache)) { MS_LOG(ERROR) << "parse bias failed"; return RET_ERROR; } } + // calculate pad params if (op != nullptr) { diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_cos_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_cos_parser.cc index a61d95aaf7..3696bc5212 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_cos_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_cos_parser.cc @@ -14,17 +14,17 @@ * limitations under the License. */ +#include "tools/converter/parser/tflite/tflite_cos_parser.h" #include #include -#include "tools/converter/parser/tflite/tflite_cos_parser.h" namespace mindspore { namespace lite { STATUS TfliteCosParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + const std::vector> &tfliteTensors, + const std::vector> &tfliteModelBuffer, + const std::vector> &tfliteOpSet, + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(INFO) << "parse TfliteCosParser"; std::unique_ptr attr(new schema::CosT()); diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_deconv_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_deconv_parser.cc index 50ca889d87..606cccd1a2 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_deconv_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_deconv_parser.cc @@ -14,25 +14,25 @@ * limitations under the License. */ +#include "tools/converter/parser/tflite/tflite_deconv_parser.h" #include #include -#include "tools/converter/parser/tflite/tflite_deconv_parser.h" namespace mindspore { namespace lite { -STATUS TfliteDeConvParser::Parse(const std::unique_ptr &tflite_op, - const std::vector> &tflite_tensors, - const std::vector> &tflite_model_buffer, - const std::vector> &tflite_op_set, - schema::CNodeT *op, - TensorCache *tensor_cache, bool quantized_model) { +STATUS TfliteDeConvParser::Parse(const std::unique_ptr &tfliteOp, + const std::vector> &tfliteTensors, + const std::vector> &tfliteModelBuffer, + const std::vector> &tfliteOpSet, + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(DEBUG) << "parse tflite Transpose_Conv parser"; std::unique_ptr attr(new schema::DeConv2DT()); - const auto &tflite_attr = tflite_op->builtin_options.AsTransposeConvOptions(); + const auto &tflite_attr = tfliteOp->builtin_options.AsTransposeConvOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op: %s attr failed", op->name.c_str(); return RET_NULL_PTR; } + attr->group = 1; attr->strideW = tflite_attr->stride_w; attr->strideH = tflite_attr->stride_h; @@ -40,12 +40,16 @@ STATUS TfliteDeConvParser::Parse(const std::unique_ptr &tflit attr->dilateW = 1; attr->padMode = GetPadMode(tflite_attr->padding); attr->format = schema::Format_NHWC; + // get the conv op weight tensor - auto weight_index = tflite_op->inputs[1]; - const auto &weight_tensor = tflite_tensors[weight_index]; + auto weight_index = tfliteOp->inputs[1]; + const auto &weight_tensor = tfliteTensors[weight_index]; + if (weight_tensor == nullptr) { + MS_LOG(ERROR) << "weight_tensor is null"; + return RET_NULL_PTR; + } std::vector weight_tensors{weight_tensor.get()}; - - if (RET_OK != ParseWeight(weight_tensors, tflite_model_buffer, tensor_cache, schema::Format_KHWC)) { + if (RET_OK != ParseWeight(weight_tensors, tfliteModelBuffer, tensor_cache, schema::Format_KHWC)) { return RET_ERROR; } auto weight_shape = weight_tensor->shape; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_depth_to_space_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_depth_to_space_parser.cc index 0c441396c8..ed9c897003 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_depth_to_space_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_depth_to_space_parser.cc @@ -15,26 +15,27 @@ * limitations under the License. */ +#include "tools/converter/parser/tflite/tflite_depth_to_space_parser.h" #include #include -#include "tools/converter/parser/tflite/tflite_depth_to_space_parser.h" namespace mindspore { namespace lite { -STATUS TfliteDepthToSpaceParser::Parse(const std::unique_ptr &tflite_op, - const std::vector> &tflite_tensors, - const std::vector> &tflite_model_buffer, - const std::vector> &tflite_opset, - schema::CNodeT *op, - TensorCache *tensor_cache, bool quantized_model) { +STATUS TfliteDepthToSpaceParser::Parse(const std::unique_ptr &tfliteOp, + const std::vector> &tfliteTensors, + const std::vector> &tfliteModelBuffer, + const std::vector> &tfliteOpSet, + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteDepthToSpaceParser"; std::unique_ptr attr(new schema::DepthToSpaceT()); - const auto &tflite_attr = tflite_op->builtin_options.AsDepthToSpaceOptions(); + + const auto &tflite_attr = tfliteOp->builtin_options.AsDepthToSpaceOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op: %s attr failed", op->name.c_str(); return RET_NULL_PTR; } attr->blockSize = tflite_attr->block_size; + attr->format = schema::Format_NHWC; if (op != nullptr) { diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_depthwise_conv_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_depthwise_conv_parser.cc index 0d231d73dd..7c4e8d9225 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_depthwise_conv_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_depthwise_conv_parser.cc @@ -14,9 +14,9 @@ * limitations under the License. */ +#include "tools/converter/parser/tflite/tflite_depthwise_conv_parser.h" #include #include -#include "tools/converter/parser/tflite/tflite_depthwise_conv_parser.h" #include "tools/common/node_util.h" namespace mindspore { @@ -26,6 +26,7 @@ STATUS TfliteDepthwiseConv2DParser::ParseGroupDepthwiseConv(schema::CNodeT *op, const std::unique_ptr &weightTensor, TensorCache *tensor_cache) { std::unique_ptr convAttr(new schema::Conv2DT); + convAttr->format = attr->format; convAttr->channelIn = attr->channelIn; convAttr->channelOut = attr->channelIn * attr->channelMultiplier; @@ -64,9 +65,12 @@ STATUS TfliteDepthwiseConv2DParser::ParseGroupDepthwiseConv(schema::CNodeT *op, } } } - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Conv2D; - op->primitive->value.value = convAttr.release(); + + if (op != nullptr) { + op->primitive = std::make_unique(); + op->primitive->value.type = schema::PrimitiveType_Conv2D; + op->primitive->value.value = convAttr.release(); + } return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_div_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_div_parser.cc index b7b6efe123..f55652515c 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_div_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_div_parser.cc @@ -14,9 +14,9 @@ * limitations under the License. */ +#include "tools/converter/parser/tflite/tflite_div_parser.h" #include #include -#include "tools/converter/parser/tflite/tflite_div_parser.h" namespace mindspore { namespace lite { @@ -24,25 +24,55 @@ STATUS TfliteDivParser::Parse(const std::unique_ptr &tfliteOp const std::vector> &tfliteTensors, const std::vector> &tfliteModelBuffer, const std::vector> &tfliteOpSet, - schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) { + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteDivParser"; std::unique_ptr attr(new schema::DivT()); + const auto &tfliteAttr = tfliteOp->builtin_options.AsDivOptions(); - if (tfliteAttr == nullptr) { + if (nullptr == tfliteAttr) { MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; return RET_NULL_PTR; } + attr->activationType = GetActivationFunctionType(tfliteAttr->fused_activation_function); - auto weight_index = tfliteOp->inputs[1]; - const auto &weight_tensor = tfliteTensors[weight_index]; - std::vector weight_tensors{weight_tensor.get()}; - if (RET_OK != ParseWeight(weight_tensors, tfliteModelBuffer, tensor_cache, schema::Format_KHWC)) { - MS_LOG(ERROR) << "parse weight failed"; - return RET_ERROR; + auto x_index = tfliteOp->inputs[0]; + const auto &x_tensor = tfliteTensors[x_index]; + if (x_tensor == nullptr) { + MS_LOG(ERROR) << "the first input is null"; + return RET_NULL_PTR; } - attr->activationType = GetActivationFunctionType(tfliteAttr->fused_activation_function); + auto &x_data = tfliteModelBuffer.at(x_tensor->buffer); + if (x_data == nullptr) { + MS_LOG(ERROR) << "the data of the first input is null"; + return RET_NULL_PTR; + } + if (x_data->data.size() > 0) { + std::vector x_tensors{x_tensor.get()}; + if (RET_OK != ParseTensor(x_tensors, tfliteModelBuffer, tensor_cache, TF_CONST, true)) { + MS_LOG(ERROR) << "parse the first tensor failed"; + return RET_ERROR; + } + } + + auto y_index = tfliteOp->inputs[1]; + const auto &y_tensor = tfliteTensors[y_index]; + if (y_tensor == nullptr) { + MS_LOG(ERROR) << "the second input is null"; + return RET_NULL_PTR; + } + auto &y_data = tfliteModelBuffer.at(y_tensor->buffer); + if (y_data == nullptr) { + MS_LOG(ERROR) << "the data of the second input is null"; + return RET_NULL_PTR; + } + if (y_data->data.size() > 0) { + std::vector y_tensors{y_tensor.get()}; + if (RET_OK != ParseTensor(y_tensors, tfliteModelBuffer, tensor_cache, TF_CONST, true)) { + MS_LOG(ERROR) << "parse the second tensor failed"; + return RET_ERROR; + } + } + if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Div; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_expand_dims_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_expand_dims_parser.cc index 3c42bf4d3b..21172cb4f9 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_expand_dims_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_expand_dims_parser.cc @@ -29,24 +29,26 @@ STATUS TfliteExpandDimsParser::Parse(const std::unique_ptr &t bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteExpandDimsParser"; std::unique_ptr attr(new schema::ExpandDimsT()); + const auto &tflite_attr = tfliteOp->builtin_options.AsExpandDimsOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; + return RET_NULL_PTR; } - // get axis - auto axis_idx = tfliteOp->inputs[1]; - std::for_each(tfliteTensors[axis_idx]->shape.begin(), tfliteTensors[axis_idx]->shape.end(), [&](int32_t sha){}); - auto &buf_data = tfliteModelBuffer[tfliteTensors[axis_idx]->buffer]; - auto data_ptr = buf_data->data.data(); - attr->dim = *(static_cast(static_cast(data_ptr))); + attr->dim = -1; + + MS_LOG(ERROR) << "The attr dim is folded by TFLite."; + return RET_ERROR; + /* if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_ExpandDims; op->primitive->value.value = attr.release(); } return RET_OK; + */ } TfliteNodeRegister g_tfliteExpandDimsParser("ExpandDims", new TfliteExpandDimsParser()); diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_fakequant_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_fakequant_parser.cc index 9d2dfddcfb..b785eb4b1e 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_fakequant_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_fakequant_parser.cc @@ -29,15 +29,24 @@ STATUS TfliteFakeQuantParser::Parse(const std::unique_ptr &tf auto weight_index = tfliteOp->inputs[1]; const auto &weight_tensor = tfliteTensors[weight_index]; + if (weight_tensor == nullptr) { + MS_LOG(ERROR) << "weight_tensor is null"; + return RET_NULL_PTR; + } std::vector weight_tensors{weight_tensor.get()}; if (RET_OK != ParseWeight(weight_tensors, tfliteModelBuffer, tensor_cache, schema::Format_NHWC)) { MS_LOG(ERROR) << "parse weight failed"; return RET_ERROR; } + if (tfliteOp->inputs.size() == 3) { attr->hasBias = true; auto bias_index = tfliteOp->inputs[2]; const auto &bias_tensor = tfliteTensors[bias_index]; + if (bias_tensor == nullptr) { + MS_LOG(ERROR) << "bias_tensor is null"; + return RET_NULL_PTR; + } std::vector bias_tensors{bias_tensor.get()}; if (RET_OK != ParseBias(bias_tensors, tfliteModelBuffer, tensor_cache)) { MS_LOG(ERROR) << "parse bias failed"; @@ -45,6 +54,7 @@ STATUS TfliteFakeQuantParser::Parse(const std::unique_ptr &tf } } attr->axis = 1; + if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_FullConnection; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_fill_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_fill_parser.cc index e41141b560..06b56df1e5 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_fill_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_fill_parser.cc @@ -32,6 +32,7 @@ STATUS TfliteFillParser::Parse(const std::unique_ptr &tfliteO if (tfliteOp->inputs.size() > 1) { if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->dims)) { + MS_LOG(ERROR) << "get Fill -> dims failed"; return RET_ERROR; } } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_floor_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_floor_parser.cc index 70abaef920..2325cd07be 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_floor_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_floor_parser.cc @@ -38,7 +38,7 @@ STATUS TfliteFloorParser::Parse(const std::unique_ptr &tflite return RET_OK; } -TfliteNodeRegister g_tfliteFloorParser("Floor", new TfliteFloorParser()); +TfliteNodeRegister g_tfliteFloorParser("flOOR", new TfliteFloorParser()); } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_floor_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_floor_parser.h index 7db0e83324..6f828a1e50 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_floor_parser.h +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_floor_parser.h @@ -26,7 +26,7 @@ namespace mindspore { namespace lite { class TfliteFloorParser : public TfliteNodeParser { public: - TfliteFloorParser() : TfliteNodeParser("Floor") {} + TfliteFloorParser() : TfliteNodeParser("flOOR") {} STATUS Parse(const std::unique_ptr &tfliteOp, const std::vector> &tfliteTensors, diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_fullyconnected_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_fullyconnected_parser.cc index 8ee363335f..61e40382ae 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_fullyconnected_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_fullyconnected_parser.cc @@ -30,16 +30,24 @@ STATUS TfliteFullyConnectedParser::Parse(const std::unique_ptrinputs[1]; const auto &weight_tensor = tfliteTensors[weight_index]; - + if (weight_tensor == nullptr) { + MS_LOG(ERROR) << "weight_tensor is null"; + return RET_NULL_PTR; + } std::vector weight_tensors{weight_tensor.get()}; if (RET_OK != ParseWeight(weight_tensors, tfliteModelBuffer, tensor_cache, schema::Format_NHWC)) { MS_LOG(ERROR) << "parse weight failed"; return RET_ERROR; } + if (tfliteOp->inputs.size() == 3) { attr->hasBias = true; auto bias_index = tfliteOp->inputs[2]; const auto &bias_tensor = tfliteTensors[bias_index]; + if (bias_tensor == nullptr) { + MS_LOG(ERROR) << "bias_tensor is null"; + return RET_NULL_PTR; + } std::vector bias_tensors{bias_tensor.get()}; if (RET_OK != ParseBias(bias_tensors, tfliteModelBuffer, tensor_cache)) { MS_LOG(ERROR) << "parse bias failed"; @@ -47,6 +55,7 @@ STATUS TfliteFullyConnectedParser::Parse(const std::unique_ptraxis = 1; + if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_FullConnection; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_gather_nd_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_gather_nd_parser.cc index 41841f4a28..18b4d49aa0 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_gather_nd_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_gather_nd_parser.cc @@ -29,12 +29,8 @@ STATUS TfliteGatherNdParser::Parse(const std::unique_ptr &tfl bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteGatherNdParser"; std::unique_ptr attr(new schema::GatherNdT()); - const auto &tflite_attr = tfliteOp->builtin_options.AsGatherNdOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - } - attr->batchDims = 0; // default + attr->batchDims = 0; if (op != nullptr) { op->primitive = std::make_unique(); @@ -44,7 +40,7 @@ STATUS TfliteGatherNdParser::Parse(const std::unique_ptr &tfl return RET_OK; } -TfliteNodeRegister g_tfliteGatherNdParser("GatherNd", new TfliteGatherNdParser()); +TfliteNodeRegister g_tfliteGatherNdParser("GatherND", new TfliteGatherNdParser()); } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_gather_nd_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_gather_nd_parser.h index 18b8b5531d..c79d8aa753 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_gather_nd_parser.h +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_gather_nd_parser.h @@ -26,7 +26,7 @@ namespace mindspore { namespace lite { class TfliteGatherNdParser : public TfliteNodeParser { public: - TfliteGatherNdParser() : TfliteNodeParser("GatherNd") {} + TfliteGatherNdParser() : TfliteNodeParser("GatherND") {} STATUS Parse(const std::unique_ptr &tfliteOp, const std::vector> &tfliteTensors, diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_gather_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_gather_parser.cc index 4c9efde2b4..2526e1665f 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_gather_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_gather_parser.cc @@ -29,13 +29,15 @@ STATUS TfliteGatherParser::Parse(const std::unique_ptr &tflit bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteGatherParser"; std::unique_ptr attr(new schema::GatherT()); + const auto &tflite_attr = tfliteOp->builtin_options.AsGatherOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; + return RET_NULL_PTR; } - attr->axis = tflite_attr->axis; - attr->batchDims = 0; // default + + attr->batchDims = 0; if (op != nullptr) { op->primitive = std::make_unique(); diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_gather_v2_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_gather_v2_parser.cc deleted file mode 100644 index 514fe5280c..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_gather_v2_parser.cc +++ /dev/null @@ -1,52 +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 "tools/converter/parser/tflite/tflite_gather_v2_parser.h" -#include -#include - -namespace mindspore { -namespace lite { -STATUS TfliteGatherV2Parser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) { - MS_LOG(DEBUG) << "parse TfliteGatherV2Parser"; - std::unique_ptr attr(new schema::GatherT()); - const auto &tflite_attr = tfliteOp->builtin_options.AsGatherOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - } - - attr->axis = tflite_attr->axis; - attr->batchDims = 0; // default - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Gather; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_tfliteGatherV2Parser("GatherV2", new TfliteGatherV2Parser()); -} // namespace lite -} // namespace mindspore - - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_gather_v2_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_gather_v2_parser.h deleted file mode 100644 index d9acc3721d..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_gather_v2_parser.h +++ /dev/null @@ -1,42 +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 PREDICT_TFLITE_GATHER_V2_PARSER_H -#define PREDICT_TFLITE_GATHER_V2_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteGatherV2Parser : public TfliteNodeParser { - public: - TfliteGatherV2Parser() : TfliteNodeParser("GatherV2") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_GATHER_V2_PARSER_H - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_inner_product_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_inner_product_parser.cc deleted file mode 100644 index aaf9366e81..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_inner_product_parser.cc +++ /dev/null @@ -1,63 +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 "tools/converter/parser/tflite/tflite_inner_product_parser.h" -#include -#include - -namespace mindspore { -namespace lite { -STATUS TfliteInnerProductParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) { - MS_LOG(DEBUG) << "parse TfliteInnerProductParser"; - std::unique_ptr attr(new schema::FullConnectionT()); - - auto weight_index = tfliteOp->inputs[1]; - const auto &weight_tensor = tfliteTensors[weight_index]; - std::vector weight_tensors{weight_tensor.get()}; - if (RET_OK != ParseWeight(weight_tensors, tfliteModelBuffer, tensor_cache, schema::Format_NHWC)) { - MS_LOG(ERROR) << "parse weight failed"; - return RET_ERROR; - } - if (tfliteOp->inputs.size() == 3) { - attr->hasBias = true; - auto bias_index = tfliteOp->inputs[2]; - const auto &bias_tensor = tfliteTensors[bias_index]; - std::vector bias_tensors{bias_tensor.get()}; - if (RET_OK != ParseBias(bias_tensors, tfliteModelBuffer, tensor_cache)) { - MS_LOG(ERROR) << "parse bias failed"; - return RET_ERROR; - } - } - attr->axis = 1; - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_FullConnection; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_tfliteInnerProductParser("InnerProduct", new TfliteInnerProductParser()); -} // namespace lite -} // namespace mindspore - - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_inner_product_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_inner_product_parser.h deleted file mode 100644 index 0505e8ce23..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_inner_product_parser.h +++ /dev/null @@ -1,42 +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 PREDICT_TFLITE_INNER_PRODUCT_PARSER_H -#define PREDICT_TFLITE_INNER_PRODUCT_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteInnerProductParser : public TfliteNodeParser { - public: - TfliteInnerProductParser() : TfliteNodeParser("InnerProduct") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_INNER_PRODUCT_PARSER_H - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_leaky_relu_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_leaky_relu_parser.cc index f04c65c4d3..c805e6f649 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_leaky_relu_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_leaky_relu_parser.cc @@ -27,16 +27,17 @@ STATUS TfliteLeakyReluParser::Parse(const std::unique_ptr &tf schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteLeakyReluParser"; std::unique_ptr attr(new schema::LeakyReLUT()); + const auto &tflite_attr = tfliteOp->builtin_options.AsLeakyReluOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; + return RET_NULL_PTR; } - attr->negativeSlope = tflite_attr->alpha; if (op != nullptr) { op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Activation; + op->primitive->value.type = schema::PrimitiveType_LeakyReLU; op->primitive->value.value = attr.release(); } return RET_OK; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_lrn_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_lrn_parser.cc index 3ac19a2920..789d2ec203 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_lrn_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_lrn_parser.cc @@ -29,11 +29,12 @@ STATUS TfliteLRNParser::Parse(const std::unique_ptr &tfliteOp bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteLRNParser"; std::unique_ptr attr(new schema::LocalResponseNormalizationT()); + const auto &tflite_attr = tfliteOp->builtin_options.AsLocalResponseNormalizationOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; + return RET_NULL_PTR; } - attr->depth_radius = tflite_attr->radius; attr->alpha = tflite_attr->alpha; attr->beta = tflite_attr->beta; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_max_pooling_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_max_pooling_parser.cc index 387b0302e2..7658a04a4a 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_max_pooling_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_max_pooling_parser.cc @@ -31,7 +31,9 @@ STATUS TfliteMaxPoolingParser::Parse(const std::unique_ptr &t const auto &tflite_attr = tflite_op->builtin_options.AsPool2DOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; + return RET_NULL_PTR; } + attr->format = schema::Format_NHWC; // attr->global attr->poolingMode = schema::PoolMode_MAX_POOLING; @@ -40,6 +42,7 @@ STATUS TfliteMaxPoolingParser::Parse(const std::unique_ptr &t attr->strideW = tflite_attr->stride_w; attr->strideH = tflite_attr->stride_h; attr->padMode = GetPadMode(tflite_attr->padding); + // calculate pad params if (op != nullptr) { diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_mean_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_mean_parser.cc index caaf43a09f..9a8e490c45 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_mean_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_mean_parser.cc @@ -27,13 +27,14 @@ STATUS TfliteMeanParser::Parse(const std::unique_ptr &tfliteO schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteMeanParser"; std::unique_ptr attr(new schema::MeanT()); + const auto &tflite_attr = tfliteOp->builtin_options.AsReducerOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - return RET_ERROR; + return RET_NULL_PTR; } - attr->keepDims = tflite_attr->keep_dims; + if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->axis)) { MS_LOG(ERROR) << "Mean get axis attr failed"; return RET_ERROR; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_mean_pooling_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_mean_pooling_parser.cc index 2ec3e0221f..ec34e12bb4 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_mean_pooling_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_mean_pooling_parser.cc @@ -27,18 +27,22 @@ STATUS TfliteMeanPoolingParser::Parse(const std::unique_ptr & schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(DEBUG) << "parser TfliteMeanPoolingParser"; std::unique_ptr attr(new schema::PoolingT()); + const auto &tflite_attr = tflite_op->builtin_options.AsPool2DOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; + return RET_NULL_PTR; } - attr->format = schema::Format_NHWC; - // attr->global - attr->poolingMode = schema::PoolMode_MEAN_POOLING; attr->windowW = tflite_attr->filter_width; attr->windowH = tflite_attr->filter_height; attr->strideW = tflite_attr->stride_w; attr->strideH = tflite_attr->stride_h; attr->padMode = GetPadMode(tflite_attr->padding); + + attr->format = schema::Format_NHWC; + // attr->global + attr->poolingMode = schema::PoolMode_MEAN_POOLING; + // calculate pad params if (op != nullptr) { 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 eebe4941f5..1a7ce0c399 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_model_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_model_parser.cc @@ -211,12 +211,18 @@ MetaGraphT *TfliteModelParser::Parse(const std::string &modelFile, const std::st // MS_LOGE("INPUT ILLEGAL: modelFile must be *.tflite"); return nullptr; } + + MS_LOG(INFO) << "modelFile is :" << modelFile; + std::unique_ptr tflite_model(new tflite::ModelT()); tflite_model = ReadTfliteModelFromFlat(modelFile.c_str()); if (tflite_model == nullptr) { // MS_LOGE("read tflite model failed"); return nullptr; } + + MS_LOG(INFO) << "after read model"; + TensorCache tensorCache; if (tflite_model->subgraphs.size() != 1) { MS_LOG(ERROR) << "read tflite model subgraphs failed"; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_mul_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_mul_parser.cc index efdefbc743..8c2d3e9a94 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_mul_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_mul_parser.cc @@ -29,21 +29,52 @@ STATUS TfliteMulParser::Parse(const std::unique_ptr &tfliteOp bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteMulParser"; std::unique_ptr attr(new schema::MulT()); + const auto &tfliteAttr = tfliteOp->builtin_options.AsMulOptions(); - if (tfliteAttr == nullptr) { + if (nullptr == tfliteAttr) { MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; return RET_NULL_PTR; } + attr->activationType = GetActivationFunctionType(tfliteAttr->fused_activation_function); - auto weight_index = tfliteOp->inputs[1]; - const auto &weight_tensor = tfliteTensors[weight_index]; - std::vector weight_tensors{weight_tensor.get()}; + auto x_index = tfliteOp->inputs[0]; + const auto &x_tensor = tfliteTensors[x_index]; + if (x_tensor == nullptr) { + MS_LOG(ERROR) << "the first input is null"; + return RET_NULL_PTR; + } + auto &x_data = tfliteModelBuffer.at(x_tensor->buffer); + if (x_data == nullptr) { + MS_LOG(ERROR) << "the data of the first input is null"; + return RET_NULL_PTR; + } + if (x_data->data.size() > 0) { + std::vector x_tensors{x_tensor.get()}; + if (RET_OK != ParseTensor(x_tensors, tfliteModelBuffer, tensor_cache, TF_CONST, true)) { + MS_LOG(ERROR) << "parse the first tensor failed"; + return RET_ERROR; + } + } - if (RET_OK != ParseWeight(weight_tensors, tfliteModelBuffer, tensor_cache, schema::Format_KHWC)) { - MS_LOG(ERROR) << "parse weight failed"; - return RET_ERROR; + auto y_index = tfliteOp->inputs[1]; + const auto &y_tensor = tfliteTensors[y_index]; + if (y_tensor == nullptr) { + MS_LOG(ERROR) << "the second input is null"; + return RET_NULL_PTR; } - attr->activationType = GetActivationFunctionType(tfliteAttr->fused_activation_function); + auto &y_data = tfliteModelBuffer.at(y_tensor->buffer); + if (y_data == nullptr) { + MS_LOG(ERROR) << "the data of the second input is null"; + return RET_NULL_PTR; + } + if (y_data->data.size() > 0) { + std::vector y_tensors{y_tensor.get()}; + if (RET_OK != ParseTensor(y_tensors, tfliteModelBuffer, tensor_cache, TF_CONST, true)) { + MS_LOG(ERROR) << "parse the second tensor failed"; + return RET_ERROR; + } + } + if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Mul; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser.cc index 54167499b6..6e1c7e32d4 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser.cc @@ -86,6 +86,29 @@ STATUS TfliteNodeParser::ParseBias(const std::vector &bias_te return RET_OK; } +STATUS TfliteNodeParser::ParseTensor(const std::vector &ts, + const std::vector> &tfliteModelBuffer, + mindspore::lite::TensorCache *tensor_cache, int node_type, + bool ifCopy) { + for (const auto &t : ts) { + auto idx = tensor_cache->FindTensor(t->name); + if (idx < 0) { + std::unique_ptr tensor(new schema::TensorT); + tensor->dataType = GetTfliteDataType(t->type); + tensor->dims = t->shape; + + // memcpy tensor data, buffer is 0 (which refers to an always existent empty buffer) + if (ifCopy && t->buffer > 0) { + CopyTfliteTensorData(tfliteModelBuffer, t, tensor.get()); + } + + MS_LOG(DEBUG) << "add weight tensor name: %s", t->name.c_str(); + tensor_cache->AddTensor(t->name, tensor.release(), node_type); + } + } + return RET_OK; +} + TypeId TfliteNodeParser::GetTfliteDataType(const tflite::TensorType &tflite_data_type) { static std::unordered_map type_map = { {tflite::TensorType_FLOAT32, TypeId::kNumberTypeFloat32}, {tflite::TensorType_FLOAT16, TypeId::kNumberTypeFloat16}, diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser.h index 3eeea81f83..4f8c0d7c05 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser.h +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser.h @@ -49,9 +49,10 @@ class TfliteNodeParser { STATUS ParseBias(const std::vector &weight_tenosr, const std::vector> &tfliteModelBuffer, TensorCache *tensor_cache); - STATUS ParseAttr(const std::vector &attr_tenosrs, - const std::vector> &tfliteModelBuffer, - mindspore::lite::TensorCache *tensor_cache, schema::Format format); + STATUS ParseTensor(const std::vector &ts, + const std::vector> &tfliteModelBuffer, + mindspore::lite::TensorCache *tensor_cache, int node_type, + bool ifCopy); STATUS CopyTfliteTensorData(const std::vector> &tfliteModelBuffer, const tflite::TensorT *tflite_tensor, schema::TensorT *tensor); diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_one_hot_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_one_hot_parser.cc index 8694a71840..9ecf8e7b07 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_one_hot_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_one_hot_parser.cc @@ -27,13 +27,20 @@ STATUS TfliteOneHotParser::Parse(const std::unique_ptr &tflit schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(INFO) << "parse TfliteOneHotParser"; std::unique_ptr attr(new schema::OneHotT()); + const auto &tflite_attr = tfliteOp->builtin_options.AsOneHotOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op: " << op->name << " attr failed"; return RET_NULL_PTR; } + auto axis = tflite_attr->axis; - const auto tensor_shape = tfliteTensors[tfliteOp->inputs[0]].get()->shape; + const auto &tensor = tfliteTensors[tfliteOp->inputs[0]]; + if (tensor == nullptr) { + MS_LOG(ERROR) << "tensor is null"; + return RET_NULL_PTR; + } + const auto tensor_shape = tensor->shape; if (axis < 0) { axis += tensor_shape.size(); } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_p_relu_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_p_relu_parser.cc index 92ec67de8f..169aa9d65b 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_p_relu_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_p_relu_parser.cc @@ -28,10 +28,12 @@ STATUS TflitePreluParser::Parse(const std::unique_ptr &tflite schema::CNodeT *op, TensorCache *tensor_cache, bool quantized_model) { MS_LOG(DEBUG) << "paser TflitePreluParser"; std::unique_ptr attr(new schema::PreluT()); + if (GetTfliteData(tflite_op->inputs[1], tflite_tensors, tflite_model_buffer, attr->slope)) { - MS_LOG(ERROR) << "pRelu -> slope get failed"; + MS_LOG(ERROR) << "get pRelu -> slope failed"; return RET_ERROR; } + if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Prelu; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_pad_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_pad_parser.cc index a49e032894..6bbadb7f6f 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_pad_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_pad_parser.cc @@ -30,15 +30,15 @@ STATUS TflitePadParser::Parse(const std::unique_ptr &tfliteOp const auto &tflite_attr = tfliteOp->builtin_options.AsPadOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; + return RET_NULL_PTR; } attr->paddingMode = schema::PaddingMode_CONSTANT; - if (tfliteOp->inputs.size() > 1) { - if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->paddings)) { - return RET_ERROR; - } + attr->constantValue = 0.0f; + if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->paddings)) { + MS_LOG(ERROR) << "get pad -> paddings failed"; + return RET_ERROR; } - // attr->constantValue = 0.0f; if (op != nullptr) { op->primitive = std::make_unique(); diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_pow_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_pow_parser.cc index aac929ff7a..a21986123d 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_pow_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_pow_parser.cc @@ -29,14 +29,9 @@ STATUS TflitePowParser::Parse(const std::unique_ptr &tfliteOp bool quantizedModel) { MS_LOG(DEBUG) << "parse TflitePowParser"; std::unique_ptr attr(new schema::PowerT()); - const auto &tflite_attr = tfliteOp->builtin_options.AsPowOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - } - // the following use default values. This op is doing... attr->power = 0.0f; - attr->scale = 0.0f; + attr->scale = 1.0f; attr->shift = 0.0f; if (op != nullptr) { diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_range_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_range_parser.cc index ee7e66d2db..4f8330c7bc 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_range_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_range_parser.cc @@ -29,34 +29,8 @@ STATUS TfliteRangeParser::Parse(const std::unique_ptr &tflite bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteRangeParser"; std::unique_ptr attr(new schema::RangeT()); - const auto &tflite_attr = tfliteOp->builtin_options.AsRangeOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - } - - auto start_idx = tfliteOp->inputs[1]; - std::for_each(tfliteTensors[start_idx]->shape.begin(), tfliteTensors[start_idx]->shape.end(), [&](int32_t sha){}); - auto &start_buf_data = tfliteModelBuffer[tfliteTensors[start_idx]->buffer]; - auto start_data_ptr = start_buf_data->data.data(); - attr->start = *(static_cast(static_cast(start_data_ptr))); - - auto limit_idx = tfliteOp->inputs[2]; - std::for_each(tfliteTensors[limit_idx]->shape.begin(), tfliteTensors[limit_idx]->shape.end(), [&](int32_t sha){}); - auto &limit_buf_data = tfliteModelBuffer[tfliteTensors[limit_idx]->buffer]; - auto limit_data_ptr = limit_buf_data->data.data(); - attr->limit = *(static_cast(static_cast(limit_data_ptr))); - - if (tfliteOp->inputs.size() > 2) { - auto delta_idx = tfliteOp->inputs[3]; - std::for_each(tfliteTensors[delta_idx]->shape.begin(), tfliteTensors[delta_idx]->shape.end(), [&](int32_t sha){}); - auto &delta_buf_data = tfliteModelBuffer[tfliteTensors[delta_idx]->buffer]; - auto delta_data_ptr = delta_buf_data->data.data(); - attr->delta = *(static_cast(static_cast(delta_data_ptr))); - } else { - attr->delta = 0; // default - } - attr->dType = 0; // default + attr->dType = 0; if (op != nullptr) { op->primitive = std::make_unique(); diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_rank_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_rank_parser.cc index bb64242230..002071d3e4 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_rank_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_rank_parser.cc @@ -29,10 +29,6 @@ STATUS TfliteRankParser::Parse(const std::unique_ptr &tfliteO bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteRankParser"; std::unique_ptr attr(new schema::RankT()); - const auto &tflite_attr = tfliteOp->builtin_options.AsRankOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - } if (op != nullptr) { op->primitive = std::make_unique(); diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_any_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_any_parser.cc index 10f6489575..98fae8209a 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_any_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_any_parser.cc @@ -32,15 +32,17 @@ STATUS TfliteReduceAnyParser::Parse(const std::unique_ptr &tf MS_LOG(ERROR) << "get op: " << op->name << " attr failed"; return RET_NULL_PTR; } + + attr->keepDims = tflite_attr->keep_dims; // attr->mode = schema::; MS_LOG(ERROR) << "ms-lite haven't supported REDUCE_ANY now"; return RET_NOT_FIND_OP; if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->axes)) { - MS_LOG(ERROR) << "REDUCE_ANY get axes attr failed"; + MS_LOG(ERROR) << "get reduce_any->axes failed"; return RET_ERROR; } - attr->keepDims = tflite_attr->keep_dims; + if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Reduce; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_max_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_max_parser.cc index 85e9dc70d6..a7bf6ef101 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_max_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_max_parser.cc @@ -32,12 +32,14 @@ STATUS TfliteReduceMaxParser::Parse(const std::unique_ptr &tf MS_LOG(ERROR) << "get op: " << op->name << " attr failed"; return RET_NULL_PTR; } + attr->mode = schema::ReduceMode_ReduceMax; + attr->keepDims = tflite_attr->keep_dims; if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->axes)) { - MS_LOG(ERROR) << "REDUCE_MAX get axes attr failed"; + MS_LOG(ERROR) << "get reduce_max -> axes failed"; return RET_ERROR; } - attr->keepDims = tflite_attr->keep_dims; + if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Reduce; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_min_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_min_parser.cc index 5c385b43a4..6185b208ab 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_min_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_min_parser.cc @@ -32,12 +32,14 @@ STATUS TfliteReduceMinParser::Parse(const std::unique_ptr &tf MS_LOG(ERROR) << "get op: " << op->name << " attr failed"; return RET_NULL_PTR; } + attr->mode = schema::ReduceMode_ReduceMin; + attr->keepDims = tflite_attr->keep_dims; if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->axes)) { - MS_LOG(ERROR) << "REDUCE_MIN get axes attr failed"; + MS_LOG(ERROR) << "get reduce_min -> axes failed"; return RET_ERROR; } - attr->keepDims = tflite_attr->keep_dims; + if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Reduce; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_prod_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_prod_parser.cc index 4d40540bf8..457fcbd2a7 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_prod_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_prod_parser.cc @@ -32,12 +32,14 @@ STATUS TfliteReduceProdParser::Parse(const std::unique_ptr &t MS_LOG(ERROR) << "get op: " << op->name << " attr failed"; return RET_NULL_PTR; } + attr->mode = schema::ReduceMode_ReduceProd; + attr->keepDims = tflite_attr->keep_dims; if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->axes)) { - MS_LOG(ERROR) << "REDUCE_PROD get axes attr failed"; + MS_LOG(ERROR) << "get reduce_prod -> axes failed"; return RET_ERROR; } - attr->keepDims = tflite_attr->keep_dims; + if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Reduce; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_relu6_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_relu6_parser.cc index 657c3eaf17..05106948f1 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_relu6_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_relu6_parser.cc @@ -27,6 +27,7 @@ STATUS TfliteRelu6Parser::Parse(const std::unique_ptr &tflite schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteRelu6Parser"; std::unique_ptr attr(new schema::ActivationT()); + attr->type = schema::ActivationType_RELU6; if (op != nullptr) { diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_relu_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_relu_parser.cc index 31877c8d8f..467cbe9714 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_relu_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_relu_parser.cc @@ -27,6 +27,7 @@ STATUS TfliteReluParser::Parse(const std::unique_ptr &tfliteO schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteReluParser"; std::unique_ptr attr(new schema::ActivationT()); + attr->type = schema::ActivationType_RELU; if (op != nullptr) { diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_reshape_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_reshape_parser.cc index 968989f0c2..9fdf2ba11c 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_reshape_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_reshape_parser.cc @@ -37,6 +37,10 @@ STATUS TfliteReshapeParser::Parse(const std::unique_ptr &tfli } auto shape_tensor_index = tfliteOp->inputs[1]; const auto & shape_tensor = tfliteTensors[shape_tensor_index]; + if (shape_tensor == nullptr) { + MS_LOG(ERROR) << "shape_tensor is null"; + return RET_NULL_PTR; + } std::vector shape_tensors{shape_tensor.get()}; if (RET_OK != ParseWeight(shape_tensors, tfliteModelBuffer, tensor_cache, schema::Format_KHWC)) { MS_LOG(ERROR) << "parse shape tensor error"; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_resize_bilinear_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_resize_bilinear_parser.cc index 13c7eb48c1..4c86861de2 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_resize_bilinear_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_resize_bilinear_parser.cc @@ -27,23 +27,35 @@ STATUS TfliteResizeBilinearParser::Parse(const std::unique_ptr attr(new schema::ResizeT()); + const auto &tfliteAttr = tfliteOp->builtin_options.AsResizeBilinearOptions(); if (tfliteAttr == nullptr) { MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; return RET_NULL_PTR; } + attr->alignCorners = tfliteAttr->align_corners; attr->format = schema::Format_NHWC; attr->method = schema::ResizeMethod_BILINEAR; - attr->alignCorners = tfliteAttr->align_corners; + attr->preserveAspectRatio = false; + auto tfliteResizeTensorIndex = tfliteOp->inputs[1]; - auto resizeTensorBufferIndex = tfliteTensors.at(tfliteResizeTensorIndex)->buffer; - auto buffData = reinterpret_cast(tfliteModelBuffer.at(resizeTensorBufferIndex)->data.data()); + const auto & shape_tensor = tfliteTensors[tfliteResizeTensorIndex]; + if (shape_tensor == nullptr) { + MS_LOG(ERROR) << "shape_tensor is null"; + return RET_NULL_PTR; + } + auto resizeTensorBufferIndex = shape_tensor->buffer; + const auto & buff = tfliteModelBuffer.at(resizeTensorBufferIndex); + if (buff == nullptr) { + MS_LOG(ERROR) << "buff_data is null"; + return RET_NULL_PTR; + } + auto buffData = reinterpret_cast(buff->data.data()); auto height = buffData[0]; auto width = buffData[1]; attr->newWidth = width; attr->newHeight = height; - // attr->preserveAspectRatio if (op != nullptr) { op->primitive = std::make_unique(); diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_resize_nearest_neighbor_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_resize_nearest_neighbor_parser.cc index 20438d63a4..384e419f50 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_resize_nearest_neighbor_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_resize_nearest_neighbor_parser.cc @@ -27,23 +27,35 @@ STATUS TfliteResizeNearestNeighborParser::Parse(const std::unique_ptr attr(new schema::ResizeT()); + const auto &tfliteAttr = tfliteOp->builtin_options.AsResizeNearestNeighborOptions(); if (tfliteAttr == nullptr) { MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; return RET_NULL_PTR; } + attr->alignCorners = tfliteAttr->align_corners; attr->format = schema::Format_NHWC; attr->method = schema::ResizeMethod_NEAREST_NEIGHBOR; - attr->alignCorners = tfliteAttr->align_corners; + attr->preserveAspectRatio = false; + auto tfliteResizeTensorIndex = tfliteOp->inputs[1]; - auto resizeTensorBufferIndex = tfliteTensors.at(tfliteResizeTensorIndex)->buffer; - auto buffData = reinterpret_cast(tfliteModelBuffer.at(resizeTensorBufferIndex)->data.data()); + const auto & shape_tensor = tfliteTensors[tfliteResizeTensorIndex]; + if (shape_tensor == nullptr) { + MS_LOG(ERROR) << "shape_tensor is null"; + return RET_NULL_PTR; + } + auto resizeTensorBufferIndex = shape_tensor->buffer; + const auto & buff = tfliteModelBuffer.at(resizeTensorBufferIndex); + if (buff == nullptr) { + MS_LOG(ERROR) << "buff_data is null"; + return RET_NULL_PTR; + } + auto buffData = reinterpret_cast(buff->data.data()); auto height = buffData[0]; auto width = buffData[1]; attr->newWidth = width; attr->newHeight = height; - // attr->preserveAspectRatio if (op != nullptr) { op->primitive = std::make_unique(); diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_parser.cc index f516d7e2d1..8f5f368f8f 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_parser.cc @@ -29,11 +29,6 @@ STATUS TfliteReverseParser::Parse(const std::unique_ptr &tfli bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteReverseParser"; std::unique_ptr attr(new schema::ReverseT()); - const auto &tfliteAttr = tfliteOp->builtin_options.AsReverseV2Options(); - if (tfliteAttr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - return RET_NULL_PTR; - } if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->axis)) { return RET_ERROR; @@ -47,7 +42,7 @@ STATUS TfliteReverseParser::Parse(const std::unique_ptr &tfli return RET_OK; } -TfliteNodeRegister g_tfliteReverseParser("Reverse", new TfliteReverseParser()); +TfliteNodeRegister g_tfliteReverseParser("reverse", new TfliteReverseParser()); } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_parser.h index 1db4301566..3965ab1ece 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_parser.h +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_parser.h @@ -26,7 +26,7 @@ namespace mindspore { namespace lite { class TfliteReverseParser : public TfliteNodeParser { public: - TfliteReverseParser() : TfliteNodeParser("Reverse") {} + TfliteReverseParser() : TfliteNodeParser("reverse") {} STATUS Parse(const std::unique_ptr &tfliteOp, const std::vector> &tfliteTensors, diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_sequence_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_sequence_parser.cc index 3658541d98..7dcedbc168 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_sequence_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_sequence_parser.cc @@ -29,13 +29,20 @@ STATUS TfliteReverseSequenceParser::Parse(const std::unique_ptr attr(new schema::ReverseSequenceT()); - const auto &tflite_attr = tflite_op->builtin_options.AsReverseSequenceOptions(); + const auto &tflite_attr = tflite_op->builtin_options.AsReverseSequenceOptions(); + if (tflite_attr == nullptr) { + MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; + return RET_NULL_PTR; + } attr->seqAxis = tflite_attr->seq_dim; attr->batchAxis = tflite_attr->batch_dim; + if (GetTfliteData(tflite_op->inputs[1], tflite_tensors, tflite_model_buffer, attr->seqLengths)) { + MS_LOG(ERROR) << "get reverse_sequence -> seqLengths failed"; return RET_ERROR; } + if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_ReverseSequence; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_scatter_nd_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_scatter_nd_parser.cc index a113266496..62108b8a17 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_scatter_nd_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_scatter_nd_parser.cc @@ -28,6 +28,7 @@ STATUS TfliteScatterNdParser::Parse(const std::unique_ptr &tf schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(INFO) << "parse TfliteScatterNdParser"; std::unique_ptr attr(new schema::ScatterNDT()); + const auto &tflite_attr = tfliteOp->builtin_options.AsScatterNdOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op: " << op->name << " attr failed"; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_shape_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_shape_parser.cc index eab6694a7a..ac545ccceb 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_shape_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_shape_parser.cc @@ -28,8 +28,6 @@ STATUS TfliteShapeParser::Parse(const std::unique_ptr &tflite MS_LOG(INFO) << "parse TfliteShapeParser"; std::unique_ptr attr(new schema::ShapeT()); - // tflite_attr->out_type; // this attr is dropped - if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Shape; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_sigmoid_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_sigmoid_parser.cc deleted file mode 100644 index fcfe4110d1..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_sigmoid_parser.cc +++ /dev/null @@ -1,42 +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 "tools/converter/parser/tflite/tflite_sigmoid_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteSigmoidParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { - MS_LOG(DEBUG) << "parse TfliteSigmoidParser"; - std::unique_ptr attr(new schema::ActivationT()); - attr->type = schema::ActivationType_SIGMOID; - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Activation; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_TfliteSigmoidParser("Sigmoid", new TfliteSigmoidParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_sigmoid_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_sigmoid_parser.h deleted file mode 100644 index f291125964..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_sigmoid_parser.h +++ /dev/null @@ -1,41 +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 PREDICT_TFLITE_SIGMOID_PARSER_H -#define PREDICT_TFLITE_SIGMOID_PARSER_H - -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" -#include -#include - -namespace mindspore { -namespace lite { -class TfliteSigmoidParser : public TfliteNodeParser { - public: - TfliteSigmoidParser() : TfliteNodeParser("Sigmoid") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_SIGMOID_PARSER_H - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_slice_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_slice_parser.cc index 9f74bddd8f..ced928e48e 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_slice_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_slice_parser.cc @@ -30,9 +30,11 @@ STATUS TfliteSliceParser::Parse(const std::unique_ptr &tflite std::unique_ptr attr(new schema::SliceT()); if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->begin)) { + MS_LOG(ERROR) << "get slice -> begin failed"; return RET_ERROR; } if (GetTfliteData(tfliteOp->inputs[2], tfliteTensors, tfliteModelBuffer, attr->size)) { + MS_LOG(ERROR) << "get slice -> size failed"; return RET_ERROR; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_softmax_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_softmax_parser.cc index 07bb3a9507..9680de53a0 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_softmax_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_softmax_parser.cc @@ -28,11 +28,14 @@ STATUS TfliteSoftmaxParser::Parse(const std::unique_ptr &tfli TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteSoftmaxParser"; std::unique_ptr attr(new schema::SoftMaxT()); + const auto &tflite_attr = tfliteOp->builtin_options.AsSoftmaxOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; + return RET_NULL_PTR; } - // attr->axis + + attr->axis = -1; if (op != nullptr) { op->primitive = std::make_unique(); diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_space_to_batch_nd_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_space_to_batch_nd_parser.cc index ea3c2c8a3f..427e775bd2 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_space_to_batch_nd_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_space_to_batch_nd_parser.cc @@ -29,12 +29,13 @@ STATUS TfliteSpaceToBatchNDParser::Parse(const std::unique_ptr attr(new schema::SpaceToBatchNDT()); + if (GetTfliteData(tflite_op->inputs[1], tflite_tensors, tflite_model_buffer, attr->blockShape)) { - MS_LOG(ERROR) << "spaceToBatchND -> blockShape get failed"; + MS_LOG(ERROR) << "get spaceToBatchND -> blockShape failed"; return RET_ERROR; } if (GetTfliteData(tflite_op->inputs[2], tflite_tensors, tflite_model_buffer, attr->paddings)) { - MS_LOG(ERROR) << "spaceToBatchND -> paddings get failed"; + MS_LOG(ERROR) << "get spaceToBatchND -> paddings failed"; return RET_ERROR; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_space_to_depth_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_space_to_depth_parser.cc index e3435bc5f3..afefcc8101 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_space_to_depth_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_space_to_depth_parser.cc @@ -29,13 +29,14 @@ STATUS TfliteSpaceToDepthParser::Parse(const std::unique_ptr TensorCache *tensor_cache, bool quantized_model) { MS_LOG(DEBUG) << "parse TfliteSpaceToDepthParser"; std::unique_ptr attr(new schema::SpaceToDepthT()); + const auto &tflite_attr = tflite_op->builtin_options.AsSpaceToDepthOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op:" << op->name.c_str() << " attr failed"; return RET_NULL_PTR; } - attr->blockSize = tflite_attr->block_size; + attr->format = schema::Format_NHWC; if (op != nullptr) { diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_sparse_to_dense_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_sparse_to_dense_parser.cc index 86ed3d0a2a..f579574caf 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_sparse_to_dense_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_sparse_to_dense_parser.cc @@ -30,19 +30,21 @@ STATUS TfliteSparseToDenseParser::Parse(const std::unique_ptr MS_LOG(DEBUG) << "parse TfliteSparseToDenseParser"; std::unique_ptr attr(new schema::SparseToDenseT()); + attr->validateIndices = false; + if (GetTfliteData(tflite_op->inputs[1], tflite_tensors, tflite_model_buffer, attr->outputShape)) { - MS_LOG(ERROR) << "sparseToDense -> outputShape get failed"; + MS_LOG(ERROR) << "get sparseToDense -> outputShape failed"; return RET_ERROR; } if (GetTfliteData(tflite_op->inputs[2], tflite_tensors, tflite_model_buffer, attr->sparseValue)) { - MS_LOG(ERROR) << "sparseToDense -> sparseValue get failed"; + MS_LOG(ERROR) << "get sparseToDense -> sparseValue failed"; return RET_ERROR; } if (GetTfliteData(tflite_op->inputs[3], tflite_tensors, tflite_model_buffer, attr->defaultValue)) { - MS_LOG(ERROR) << "sparseToDense -> defaultValue get failed"; + MS_LOG(ERROR) << "get sparseToDense -> defaultValue failed"; return RET_ERROR; } - attr->validateIndices = false; + if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_SparseToDense; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_split_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_split_parser.cc index eeb5d7c226..946f81482d 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_split_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_split_parser.cc @@ -29,15 +29,26 @@ STATUS TfliteSplitParser::Parse(const std::unique_ptr &tflite bool quantizedModel) { MS_LOG(INFO) << "parse TfliteSplitParser"; std::unique_ptr attr(new schema::SplitT()); + const auto &tflite_attr = tfliteOp->builtin_options.AsSplitOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op: " << op->name << " attr failed"; return RET_NULL_PTR; } + auto num_splits = tflite_attr->num_splits; - const auto tensor_shape = tfliteTensors[tfliteOp->inputs[1]].get()->shape; - auto axis = - *(reinterpret_cast(tfliteModelBuffer[tfliteTensors[tfliteOp->inputs[0]]->buffer]->data.data())); + const auto &shape_tensor = tfliteTensors[tfliteOp->inputs[1]]; + if (shape_tensor == nullptr) { + MS_LOG(ERROR) << "shape_tensor is null"; + return RET_NULL_PTR; + } + const auto tensor_shape = shape_tensor->shape; + const auto &axis_tensor = tfliteTensors[tfliteOp->inputs[0]]; + if (axis_tensor == nullptr) { + MS_LOG(ERROR) << "axis_tensor is null"; + return RET_NULL_PTR; + } + auto axis = *(reinterpret_cast(tfliteModelBuffer[axis_tensor->buffer]->data.data())); if (axis < 0) { axis += tensor_shape.size(); } @@ -46,8 +57,6 @@ STATUS TfliteSplitParser::Parse(const std::unique_ptr &tflite return RET_ERROR; } attr->splitDim = axis; - - auto num_splits = tflite_attr->num_splits; if (tensor_shape[axis] % num_splits != 0) { MS_LOG(ERROR) << "num_splits can't divide tensor's length at axis " << axis; return RET_ERROR; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_split_v_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_split_v_parser.cc index 938ce612c2..214e32617d 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_split_v_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_split_v_parser.cc @@ -27,21 +27,31 @@ STATUS TfliteSplitVParser::Parse(const std::unique_ptr &tflit schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(INFO) << "parse TfliteSplitVParser"; std::unique_ptr attr(new schema::SplitT()); + const auto &tflite_attr = tfliteOp->builtin_options.AsSplitVOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op: " << op->name << " attr failed"; return RET_NULL_PTR; } - attr->numberSplit = tflite_attr->num_splits; + if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->sizeSplits)) { - MS_LOG(ERROR) << "SPLIT_V get sizeSplits attr failed"; + MS_LOG(ERROR) << "get splite_v -> sizeSplits failed"; return RET_ERROR; } - auto axis = - *(reinterpret_cast(tfliteModelBuffer[tfliteTensors[tfliteOp->inputs[2]]->buffer]->data.data())); - const auto tensor_shape = tfliteTensors[tfliteOp->inputs[0]].get()->shape; + const auto &tensor = tfliteTensors[tfliteOp->inputs[0]]; + if (tensor == nullptr) { + MS_LOG(ERROR) << "tensor_shape is null"; + return RET_NULL_PTR; + } + auto tensor_shape = tensor->shape; + const auto &axis_tensor = tfliteTensors[tfliteOp->inputs[2]]; + if (axis_tensor == nullptr) { + MS_LOG(ERROR) << "axis_tensor is null"; + return RET_NULL_PTR; + } + auto axis = *(reinterpret_cast(tfliteModelBuffer[axis_tensor->buffer]->data.data())); if (axis < 0) { axis += tensor_shape.size(); } @@ -49,6 +59,7 @@ STATUS TfliteSplitVParser::Parse(const std::unique_ptr &tflit MS_LOG(ERROR) << "axis value too large"; return RET_ERROR; } + if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Split; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_squeeze_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_squeeze_parser.cc index 932acb90b0..521793c7f3 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_squeeze_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_squeeze_parser.cc @@ -27,12 +27,12 @@ STATUS TfliteSqueezeParser::Parse(const std::unique_ptr &tfli schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(INFO) << "parse TfliteSqueezeParser"; std::unique_ptr attr(new schema::SqueezeT()); + const auto &tflite_attr = tfliteOp->builtin_options.AsSqueezeOptions(); if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name << " attr failed"; + MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; return RET_NULL_PTR; } - attr->axis = tflite_attr->squeeze_dims; if (op != nullptr) { diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_stack_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_stack_parser.cc index 43d76b3c56..13dbb78375 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_stack_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_stack_parser.cc @@ -30,6 +30,7 @@ STATUS TfliteStackParser::Parse(const std::unique_ptr &tflite const auto &tflite_attr = tfliteOp->builtin_options.AsPackOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; + return RET_NULL_PTR; } attr->axis = tflite_attr->axis; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_sub_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_sub_parser.cc index 1a517f1490..4748e83983 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_sub_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_sub_parser.cc @@ -29,18 +29,52 @@ STATUS TfliteSubParser::Parse(const std::unique_ptr &tfliteOp bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteSubParser"; std::unique_ptr attr(new schema::SubT()); + const auto &tfliteAttr = tfliteOp->builtin_options.AsSubOptions(); - if (tfliteAttr == nullptr) { + if (nullptr == tfliteAttr) { MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; + return RET_NULL_PTR; } + attr->activationType = GetActivationFunctionType(tfliteAttr->fused_activation_function); - auto weight_index = tfliteOp->inputs[1]; - const auto &weight_tensor = tfliteTensors[weight_index]; - std::vector weight_tensors{weight_tensor.get()}; - if (RET_OK != ParseWeight(weight_tensors, tfliteModelBuffer, tensor_cache, schema::Format_KHWC)) { - MS_LOG(ERROR) << "parse weight failed"; + auto x_index = tfliteOp->inputs[0]; + const auto &x_tensor = tfliteTensors[x_index]; + if (x_tensor == nullptr) { + MS_LOG(ERROR) << "the first input is null"; + return RET_NULL_PTR; } - attr->activationType = GetActivationFunctionType(tfliteAttr->fused_activation_function); + auto &x_data = tfliteModelBuffer.at(x_tensor->buffer); + if (x_data == nullptr) { + MS_LOG(ERROR) << "the data of the first input is null"; + return RET_NULL_PTR; + } + if (x_data->data.size() > 0) { + std::vector x_tensors{x_tensor.get()}; + if (RET_OK != ParseTensor(x_tensors, tfliteModelBuffer, tensor_cache, TF_CONST, true)) { + MS_LOG(ERROR) << "parse the first tensor failed"; + return RET_ERROR; + } + } + + auto y_index = tfliteOp->inputs[1]; + const auto &y_tensor = tfliteTensors[y_index]; + if (y_tensor == nullptr) { + MS_LOG(ERROR) << "the second input is null"; + return RET_NULL_PTR; + } + auto &y_data = tfliteModelBuffer.at(y_tensor->buffer); + if (y_data == nullptr) { + MS_LOG(ERROR) << "the data of the second input is null"; + return RET_NULL_PTR; + } + if (y_data->data.size() > 0) { + std::vector y_tensors{y_tensor.get()}; + if (RET_OK != ParseTensor(y_tensors, tfliteModelBuffer, tensor_cache, TF_CONST, true)) { + MS_LOG(ERROR) << "parse the second tensor failed"; + return RET_ERROR; + } + } + if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Sub; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_sum_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_sum_parser.cc index 9844d45467..0ee5fb7ce3 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_sum_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_sum_parser.cc @@ -27,18 +27,20 @@ STATUS TfliteSumParser::Parse(const std::unique_ptr &tfliteOp schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(INFO) << "parse TfliteSumParser"; std::unique_ptr attr(new schema::ReduceT()); + const auto &tflite_attr = tfliteOp->builtin_options.AsReducerOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op: " << op->name << " attr failed"; return RET_NULL_PTR; } + attr->keepDims = tflite_attr->keep_dims; + attr->mode = schema::ReduceMode_ReduceSum; + if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->axes)) { - MS_LOG(ERROR) << "SUM get axes attr failed"; + MS_LOG(ERROR) << "get sum -> axes failed"; return RET_ERROR; } - attr->keepDims = tflite_attr->keep_dims; - if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Reduce; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_tanh_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_tanh_parser.cc index f78b8fa71e..1991cfad01 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_tanh_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_tanh_parser.cc @@ -27,6 +27,7 @@ STATUS TfliteTanhParser::Parse(const std::unique_ptr &tfliteO schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteTanhParser"; std::unique_ptr attr(new schema::ActivationT()); + attr->type = schema::ActivationType_TANH; if (op != nullptr) { diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_tile_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_tile_parser.cc index c3e259fa27..b0ce2de061 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_tile_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_tile_parser.cc @@ -31,7 +31,7 @@ STATUS TfliteTileParser::Parse(const std::unique_ptr &tflite_ std::unique_ptr attr(new schema::TileT()); if (GetTfliteData(tflite_op->inputs[1], tflite_tensors, tflite_model_buffer, attr->multiples)) { - MS_LOG(ERROR) << "tile -> multiples get failed"; + MS_LOG(ERROR) << "get tile -> multiples failed"; return RET_ERROR; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_topk_v2_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_topk_v2_parser.cc index c086eab7d4..a9c285ace1 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_topk_v2_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_topk_v2_parser.cc @@ -31,9 +31,10 @@ STATUS TfliteTopKV2Parser::Parse(const std::unique_ptr &tflit std::unique_ptr attr(new schema::TopKV2T()); if (GetTfliteData(tflite_op->inputs[1], tflite_tensors, tflite_model_buffer, attr->k)) { - MS_LOG(ERROR) << "topKV2 -> k get failed"; + MS_LOG(ERROR) << "get topKV2 -> k failed"; return RET_ERROR; } + if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_TopKV2; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_transpose_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_transpose_parser.cc index 829a813701..349dd921a0 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_transpose_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_transpose_parser.cc @@ -29,12 +29,16 @@ STATUS TfliteTransposeParser::Parse(const std::unique_ptr &tf std::unique_ptr attr(new schema::TransposeT()); if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->perm)) { - MS_LOG(ERROR) << "parse Transpose attr perm failed"; + MS_LOG(ERROR) << "get transpose -> perm failed"; return RET_ERROR; } auto weight_index = tfliteOp->inputs[1]; const auto &weight_tensor = tfliteTensors[weight_index]; + if (weight_tensor == nullptr) { + MS_LOG(ERROR) << "weight_tensor is null"; + return RET_ERROR; + } std::vector weight_tensors{weight_tensor.get()}; if (RET_OK != ParseWeight(weight_tensors, tfliteModelBuffer, tensor_cache, schema::Format_KHWC)) { MS_LOG(ERROR) << "parse weight failed"; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_unique_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_unique_parser.cc index 12131d606f..70405ec766 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_unique_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_unique_parser.cc @@ -29,6 +29,7 @@ STATUS TfliteUniqueParser::Parse(const std::unique_ptr &tflit TensorCache *tensor_cache, bool quantized_model) { MS_LOG(DEBUG) << "parse TfliteUniqueParser"; std::unique_ptr attr(new schema::UniqueT()); + const auto &tflite_attr = tflite_op->builtin_options.AsUniqueOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op: %s attr failed", op->name.c_str(); @@ -36,6 +37,7 @@ STATUS TfliteUniqueParser::Parse(const std::unique_ptr &tflit } attr->outType = dtype_map[tflite_attr->idx_out_type]; + if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Unique; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_unstack_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_unstack_parser.cc index eca413ba7a..dc94140e32 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_unstack_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_unstack_parser.cc @@ -28,12 +28,12 @@ STATUS TfliteUnstackParser::Parse(const std::unique_ptr &tfli schema::CNodeT *op, TensorCache *tensor_cache, bool quantized_model) { MS_LOG(DEBUG) << "paser TfliteUnstackParser"; std::unique_ptr attr(new schema::UnstackT()); + const auto &tflite_attr = tflite_op->builtin_options.AsUnpackOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op: %s attr failed", op->name.c_str(); return RET_NULL_PTR; } - attr->num = tflite_attr->num; attr->axis = tflite_attr->axis; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_where_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_where_parser.cc index e05e7cb507..0476a4ab32 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_where_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_where_parser.cc @@ -31,9 +31,10 @@ STATUS TfliteWhereParser::Parse(const std::unique_ptr &tflite std::unique_ptr attr(new schema::WhereT()); if (GetTfliteData(tflite_op->inputs[0], tflite_tensors, tflite_model_buffer, attr->condition)) { - MS_LOG(ERROR) << "where -> condition get failed"; + MS_LOG(ERROR) << "get where -> condition failed"; return RET_ERROR; } + if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Where;