From b35c4c53eee68e0ec32244ea0169348f4c43deb6 Mon Sep 17 00:00:00 2001 From: wangzhe Date: Wed, 5 Aug 2020 19:52:54 +0800 Subject: [PATCH] add ut for 21 tflite op parsers --- mindspore/lite/test/CMakeLists.txt | 4 ++ mindspore/lite/test/run_test.sh | 3 ++ .../parser/tflite/test_data/abs.tflite | Bin 0 -> 408 bytes .../tflite/test_data/batch_to_space_nd.tflite | Bin 0 -> 792 bytes .../parser/tflite/test_data/cos.tflite | Bin 0 -> 488 bytes .../test_data/exp.tflite} | Bin .../parser/tflite/test_data/log.tflite | Bin 0 -> 412 bytes .../tflite/test_data/logical_and.tflite | Bin 0 -> 612 bytes .../tflite/test_data/logical_not.tflite | Bin 0 -> 504 bytes .../parser/tflite/test_data/logical_or.tflite | Bin 0 -> 612 bytes .../parser/tflite/test_data/maximum.tflite | Bin 0 -> 516 bytes .../parser/tflite/test_data/minimum.tflite | Bin 0 -> 516 bytes .../parser/tflite/test_data/one_hot.tflite | Bin 0 -> 780 bytes .../parser/tflite/test_data/reduce_max.tflite | Bin 0 -> 528 bytes .../parser/tflite/test_data/reduce_min.tflite | Bin 0 -> 532 bytes .../tflite/test_data/reduce_prod.tflite | Bin 0 -> 536 bytes .../parser/tflite/test_data/rsqrt.tflite | Bin 0 -> 412 bytes .../parser/tflite/test_data/sin.tflite | Bin 0 -> 412 bytes .../parser/tflite/test_data/split.tflite | Bin 0 -> 692 bytes .../parser/tflite/test_data/split_v.tflite | Bin 0 -> 772 bytes .../parser/tflite/test_data/sqrt.tflite | Bin 0 -> 412 bytes .../parser/tflite/test_data/square.tflite | Bin 0 -> 412 bytes .../parser/tflite/test_data/sum.tflite | Bin 0 -> 528 bytes .../parser/tflite/tflite_abs_parser_test.cc | 34 +++++++++++++ .../tflite_batch_to_space_nd_parser_test.cc | 45 +++++++++++++++++ .../parser/tflite/tflite_cos_parser_test.cc | 34 +++++++++++++ .../parser/tflite/tflite_exp_parser_test.cc | 29 ++++------- .../parser/tflite/tflite_log_parser_test.cc | 34 +++++++++++++ .../tflite/tflite_logical_and_parser_test.cc | 34 +++++++++++++ .../tflite/tflite_logical_not_parser_test.cc | 34 +++++++++++++ .../tflite/tflite_logical_or_parser_test.cc | 34 +++++++++++++ .../tflite/tflite_maximum_parser_test.cc | 34 +++++++++++++ .../tflite/tflite_minimum_parser_test.cc | 34 +++++++++++++ .../tflite/tflite_one_hot_parser_test.cc | 43 ++++++++++++++++ .../tflite/tflite_parsers_test_utils.cc | 33 ++++++++++++ .../parser/tflite/tflite_parsers_test_utils.h | 35 +++++++++++++ .../tflite/tflite_reduce_max_parser_test.cc | 46 +++++++++++++++++ .../tflite/tflite_reduce_min_parser_test.cc | 46 +++++++++++++++++ .../tflite/tflite_reduce_prod_parser_test.cc | 46 +++++++++++++++++ .../parser/tflite/tflite_rsqrt_parser_test.cc | 34 +++++++++++++ .../parser/tflite/tflite_sin_parser_test.cc | 34 +++++++++++++ .../parser/tflite/tflite_split_parser_test.cc | 46 +++++++++++++++++ .../tflite/tflite_split_v_parser_test.cc | 46 +++++++++++++++++ .../parser/tflite/tflite_sqrt_parser_test.cc | 34 +++++++++++++ .../tflite/tflite_square_parser_test.cc | 34 +++++++++++++ .../parser/tflite/tflite_sum_parser_test.cc | 47 ++++++++++++++++++ .../tflite/tflite_batch_to_sapce_nd_parser.cc | 7 +-- .../parser/tflite/tflite_one_hot_parser.cc | 8 ++- .../parser/tflite/tflite_scatter_nd_parser.cc | 2 + .../parser/tflite/tflite_split_parser.cc | 2 +- 50 files changed, 871 insertions(+), 25 deletions(-) create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/abs.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/batch_to_space_nd.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/cos.tflite rename mindspore/lite/test/ut/tools/converter/parser/{test_data/tflite_exp_model/Exp.tflite => tflite/test_data/exp.tflite} (100%) create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/log.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/logical_and.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/logical_not.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/logical_or.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/maximum.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/minimum.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/one_hot.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/reduce_max.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/reduce_min.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/reduce_prod.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/rsqrt.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sin.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/split.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/split_v.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sqrt.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/square.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sum.tflite create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_abs_parser_test.cc create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_batch_to_space_nd_parser_test.cc create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_cos_parser_test.cc create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_log_parser_test.cc create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_and_parser_test.cc create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_not_parser_test.cc create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_or_parser_test.cc create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_maximum_parser_test.cc create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_minimum_parser_test.cc create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_one_hot_parser_test.cc create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_parsers_test_utils.cc create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_max_parser_test.cc create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_min_parser_test.cc create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_prod_parser_test.cc create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_rsqrt_parser_test.cc create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sin_parser_test.cc create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_split_parser_test.cc create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_split_v_parser_test.cc create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sqrt_parser_test.cc create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_square_parser_test.cc create mode 100644 mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sum_parser_test.cc diff --git a/mindspore/lite/test/CMakeLists.txt b/mindspore/lite/test/CMakeLists.txt index 6c09c96f4d..c9ff6db684 100644 --- a/mindspore/lite/test/CMakeLists.txt +++ b/mindspore/lite/test/CMakeLists.txt @@ -191,8 +191,12 @@ if (SUPPORT_GPU) endif() ### converter if(BUILD_CONVERTER) + file(GLOB_RECURSE TEST_CASE_TFLITE_PARSERS_SRC + ${TEST_DIR}/ut/tools/converter/parser/tflite/*.cc + ) set(TEST_LITE_SRC ${TEST_LITE_SRC} + ${TEST_CASE_TFLITE_PARSERS_SRC} ${TOP_DIR}/mindspore/core/utils/flags.cc ${LITE_DIR}/tools/converter/optimizer.cc ${LITE_DIR}/src/common/anf_importer/anf_importer.cc diff --git a/mindspore/lite/test/run_test.sh b/mindspore/lite/test/run_test.sh index 4571fae6e7..adfb48130f 100755 --- a/mindspore/lite/test/run_test.sh +++ b/mindspore/lite/test/run_test.sh @@ -7,6 +7,7 @@ mkdir -pv ${CUR_DIR}/do_test cd ${CUR_DIR}/do_test cp ${BUILD_DIR}/test/lite-test ./ cp -r ${CUR_DIR}/ut/src/runtime/kernel/arm/test_data/* ./ +cp -r ${CUR_DIR}/ut/tools/converter/parser/tflite/test_data/* ./ ## prepare data for dataset TEST_DATA_DIR=${CUR_DIR}/../../../tests/ut/data/dataset/ cp -fr $TEST_DATA_DIR/testPK ./data @@ -14,6 +15,8 @@ cp -fr $TEST_DATA_DIR/testPK ./data ./lite-test --gtest_filter="*MindDataTestTensorDE*" ./lite-test --gtest_filter="*MindDataTestEager*" +./lite-test --gtest_filter="TestTfliteParser*" + ./lite-test --gtest_filter="*TestHebing*" ./lite-test --gtest_filter=TestFcFp32* diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/abs.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/abs.tflite new file mode 100644 index 0000000000000000000000000000000000000000..29768a273ad18e29c0626c0b1f912b7643937d93 GIT binary patch literal 408 zcmZ9IJr06E5QU#gltiKy6qH+7SP&a8pdqm`!GZ($!zLC)3>sT+<0-rwzQ;;PT=D@k z`*z;UMgX$yZUsyb!Gn(gGlYzQ0Xg)*444B9VTd)Ek}OS9la$w|tsXXCHu{ix={+*9 z>v}yr;rT`he@pWKM*ym?;!%0(n5>P@k<(u~QzIG*jLEOJ{lbI4Ei zbygbZ@k-p62~Mf5)P<(j%+hLKK8F1JDBhgzJf)}8hCdhixuuD_yVJkwwm6N8bsxZx KU5xl{mi+=Lw;zN6 literal 0 HcmV?d00001 diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/batch_to_space_nd.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/batch_to_space_nd.tflite new file mode 100644 index 0000000000000000000000000000000000000000..87f8e477c38ffb45eb1865231e834e7a8f25924f GIT binary patch literal 792 zcmaJ;Lxv6+6dXj<{s2=`oWu%d6l|#hCtEah63h>AaCC4IM+bk3 zIQc7#=e*>R;^2kz?tSOJcfa0?0A$A}ePA6CT=?iBK*$}iLVP+P19Cu2bck;AY<3H*@D^=8{(Tk9X3g=1MfuL>EfU&df*y8z?-p8fmxv^U0 zi!5*I*P=ZX+gq!}`pj`=&?gN&Bk@;Z%6HdwKSpAXdd{`;kt4IOj9po;+n4%K?uxaw z_hnOCD|LNzi*9D%n!Zm1e;gt>HF$e4zO2vxz~L)1m_<%4KFITC@B6U#H4PI{VM9~D zqd`3y?B&14*xa((JQdGPwJqAviD!J!%N+Wpw>-w9UfNes8xMaRcStXHdj8;RIONAY KpM^b}s(t|#D=Q=b literal 0 HcmV?d00001 diff --git a/mindspore/lite/test/ut/tools/converter/parser/test_data/tflite_exp_model/Exp.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/exp.tflite similarity index 100% rename from mindspore/lite/test/ut/tools/converter/parser/test_data/tflite_exp_model/Exp.tflite rename to mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/exp.tflite diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/log.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/log.tflite new file mode 100644 index 0000000000000000000000000000000000000000..734fa6e775a35f90bfd118e61381ccca23c5af41 GIT binary patch literal 412 zcmZ9IF$%&!5JkTlG@z(Oij+Bk*m#79Ct~c{E3&v-sg4|GZQ!B!c@$J z2YNh4=HH|1-1@lP<%i;!<>#uBp6P>H+^CmsX}$maqK^V?y_op-ew?ZKQfum%_mKMz J)$zAli#P0F9t{8h literal 0 HcmV?d00001 diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/logical_and.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/logical_and.tflite new file mode 100644 index 0000000000000000000000000000000000000000..a26b1bebf086d63662d44b0b4e81298e3892b641 GIT binary patch literal 612 zcmah`yH3ME5FEfH7777@ixeqRP^3U8f-gXpQbh`dMQft?1eTn$WCAS>1w{(JfSM2D zd$`Q_VxWmQYrLm@%+B8S0VLze6>x$+0)*(`7!kcadVoD*xC{EgIB-sMh#g|Ju?g)F zkxb+1ATI5*sg@?Yz&?E=Vn_^#9-&&G#XbT5s5`xWJNHJch<8F6fpadDB~FP&Zqw?? zF7t&+$^V#_mR!+~V)334Qm(oY1xlk1<=1yv&GSXv5#k=R4^2z+DJG55t9w(YyhGxq zn9a>YS!AY4`C#~Dt?Cr_y3(LUU~62fE}8(Ppmp)nzVE zJ%==Go8y47NqL{oXT`P6q+OraubODnQN8`qEBn34DyMmu#`-+Z@w?x4yL^XA^yHv+J{O>TfIjL<@W9xf3wJ7fkpBX1{Q4m=0Oq(_*-OA`~u z3$mQY^C-6Elc{QxO{fN3lZXt7?g4FjwD|U#AK%V>k}smu%sCe@%6CAvd6`y^Wu0$L zO5I&R9*QiF(sg6sKfQ)XyvR8QS_E<<-}e$WMFKtL~gEiuJ}k*djAk zI^$lm(S+oq`>OL^&#{k8pij*J9oA}&eWe;d)yPjXIri%^m)QG!vo7vzEp0tsUw6XB dQQm%O3Vx>QMc>l@g`bC|{r}uMhq*Jg`T<8#GOqvt literal 0 HcmV?d00001 diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/logical_or.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/logical_or.tflite new file mode 100644 index 0000000000000000000000000000000000000000..ac539be1b78999e777a873f6e40f340e797a250b GIT binary patch literal 612 zcmah`yH3ME5FEfHMhXFeixeqRP^3U8f={rNDw0#UccSD3mK<9$ftH4XA_ZSS%?I&4 z95Z(@q=`6dyr+H4&ffL`q~pmQaDhGogy`TL5xqTnfFojf2>QS{a7}cG17fqaDeW1N zCUG)|tMb{@YqPw;F?}OqNDPP`p<1BDJ^}x5onF7KeIqu+JE4rgS{up|m&7VBv-+uA z=PQ$u|1qyhaz($2#d}3ax#~s~D2+Ol@9wgi=ZlyT;vTaPO-u7BCXLdodsC;pQ({`o z7v`ZVmZr}5VEAOM>J<0AUgD6ot>~qJr*fks^hKg|#SK_yB>$LQy2Whz1nYKv1#sUAFciEVi)lnH0ffKZAK)84K2bmk6?nV>S#tgWEuamk5njck|_D$xMCscrUG_ns#ZTcHY{h>E_^e8)r2%b0Ei_^Zegd`wDr> BG@Sqd literal 0 HcmV?d00001 diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/minimum.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/minimum.tflite new file mode 100644 index 0000000000000000000000000000000000000000..691b3c25d633a2723caf031704a3faf057c34d3c GIT binary patch literal 516 zcmZ{gKWoBJ6va<%Q9)}RGGxf$;9QhWode=vQ6#&F1`H$-LhI^x>FkH-&>@4L$>%w~ zJStLO_~pHK|D1c@^#Meq$s5ptk0&(IMi(A$z#}<6fELgO^a!sQlNS>x%GUk_*`IIlc0lC$CrtL~^G2~sd(p%J*`uR^=bJdG& zboVk>#j5tb-W&9NBzcm3Wz5v~7w=V-RMRd^)XrPGG~FEBZsV+mW)9TZbA$iOdOrhs C0W_Te literal 0 HcmV?d00001 diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/one_hot.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/one_hot.tflite new file mode 100644 index 0000000000000000000000000000000000000000..3e81d98f450bc25490862967369a7ad9f3e81a5e GIT binary patch literal 780 zcmYjPu}%U(5Pjka6o{x46ciK`#u$`HL8BHJD-$d*u`sz1S#l(BNARH4udt%9GFDc` z@9;A${Q*7SyS*cB?qzmoXWq=by()m-#pN-ugDM>4Q9uc0dMoq*>%?aU^nv%l0Z|~< zh}XnUX}5@8x6`e40)JsSBRzT#9D zc<5LQoRUAilfHFAasRnhS6T+XalIf!i#dxVPw$h?$8B6Ei8~B@chMiujr<Cdii;>q@)`NX4nw6=+qCm0S_ zjXBI!w(ZU8BaO?k(o!%N&m@oDhwDUo)d;GkZ literal 0 HcmV?d00001 diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/reduce_max.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/reduce_max.tflite new file mode 100644 index 0000000000000000000000000000000000000000..96fde48b3a143d1b897bdfd88e97d954fd2d3ece GIT binary patch literal 528 zcmZ9Ju}Z{16h*IVFaZ~}h!D^sg@uKv;3ovElwD*?L6#(7V97#U#m?5k!mqIQ6Z{On z#&}OcSaHIcFmK*__s&crX?A&aA?+wpph#owDfUX*G~XL?M2<~eR4+T^`~v$%)1#|Z&0QtHL;0IU_mq){Hev)mr2aj z^xh+df4n<5!ZW$_JTi=Zb3K1PYs%s=UscQcuBwYFFCQE~Y}@w3P=^lvPYgX+qmTb> zGhNK{@_xA}%BH(B{NtBea(d4%+29?IoRU*~mJM&=_>kv`>B74>|0|-AsMh e)e@oB!fYho%lV(h;N$rpRW5bQ)iEz>6IDuF}NW;S?uVTi@Xc-Y2Ms} z`G})S4S9fu_;pq5tDgm*v7$Afq@pLEy3EfyFxH*6p?oe@Ra4(rby*eR$#LA^gL`9o zrsd|iH)_$BIgSne$63hSF*nPHB0M(BGPJ!C|M*2q&fxhqANK!xNne#-QJ;%rJbN9Y crRUM#zJ3Q|9e;9to}ngwhyN4x|Hp^hUr-e;L;wH) literal 0 HcmV?d00001 diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/reduce_prod.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/reduce_prod.tflite new file mode 100644 index 0000000000000000000000000000000000000000..7eaa9f4f24f28793895b07b34e7af167da2388d7 GIT binary patch literal 536 zcmYk3!AgZt6h(J0Ng=5Q5<(3eG>i)R1ffyz4Bjw^P~iy=1+%72`<%X`ujos%y%gbH zSYFS$_w2Kerjj-fkN47vQU!_>>r9Cw>CpTh$Qd~&WyYbN&8gX}^L3VY?MK}Yb#>!v z>CRjlYKXUg<2a1tC>>cl@N>>{wlZHnkKJ$SOkHLY6Pefz>AB$7$yec>^KbKGef;5< zy3C*r)X}TxyUN?-fS7sdiV71mFB;UO=GvgQuW{_S*u9qZw%b*8KULxzAJn2oKj|}{ zci#D~k;1+2>g0<1++p4;!#X$kyzT4iy&RgZeQDaNDeE`S=^43?w`6+aJDmEGVQ#Mr cbh(2jJN{YA9E-2OZWq6JnEy{W{T~NU|KMaVs{jB1 literal 0 HcmV?d00001 diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/rsqrt.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/rsqrt.tflite new file mode 100644 index 0000000000000000000000000000000000000000..6275509186137ff51f45070f33caac27e5206219 GIT binary patch literal 412 zcmZ9I!3u&v6h&`kB_!6uh09sEXc2Atfk0>_7|{% zX(F;D9&2{hwQq>DE_oBx?O=!@(OyAbJTHIcLb4*do7OrbuNm1Fr*nQOi!85fAM#TT zos~vf;2F2GV&C3MPU>1cORIhPMC9LR%-rFAt7^`U{d#@yb&_X0)OG)UiaT%3zp>r~ LnD8c3{_RLU2HqfZ literal 0 HcmV?d00001 diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sin.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sin.tflite new file mode 100644 index 0000000000000000000000000000000000000000..a06748d47c2a38d4ff5050960f0b267a680dd28b GIT binary patch literal 412 zcmZ9I!3u&<5Jhh#B_!3th0FH=(WXDhXeAir4@5pF5Cw_0{a9bn7qtlN-e+R;;ONY7 z=gzzr0mydA8kix12Oj|z2$=yRk`KTNSOW}UiY=LwER9nWSLMytSDUY#K4M*ZkGz_u zc@vMB@_@eG1ZfNjiBBFx-W?1vBneUPlRnx(HO(+Y`zcqCG|CT`lJVH(x|1eqf^MZd z$wPX1EXlvel(l_vJlS(qb;}D6ylvqxFMej_Rmm3h64atMro>cuWqP9qy#Mi(b?14m zLuK;Y#RonMuCnLROZhKHA!qRBJu@#f0Tz~;Xx^-n6rpl=N4{CrbECKF&lZyN1HWTU A`2YX_ literal 0 HcmV?d00001 diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/split_v.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/split_v.tflite new file mode 100644 index 0000000000000000000000000000000000000000..61405534dca0c64228d7e2cfad76d3d420cf3d13 GIT binary patch literal 772 zcmYk4u}T9$5QfJXlZYWkO_Ab?D^gfU^hhIOAq1?1Sfmt!m=h0@izKJ5ozIX;EUc`> zXYeVkeF;6kfA3D*<7a07*`4`kZap&_o}Ts0w#~D$)vRt!Yr(c*%vQli$>5B**&e8a z74VYV33d|<2mOKHpT+m#JPF5LtHPatL!f&d&<4s?22bB3OSM!85vht|n^R!p_$>~&tg?(F8i_Bta?>tJy^iIP!p#Ms~}jyG#?r$+wl zKR1Z6oDS91ynLXw1@avGnH@({xHsynMz$Jm+UB}$l0EBLI;5=w3SEUZ^_J&FlfF#1 x&bQnxy~3)Sofy4F)<8Y$4ITg=6nSx-|Np;=(<`ZwU2jD()mMKRUv)g2>tDDFU5Wqz literal 0 HcmV?d00001 diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sqrt.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sqrt.tflite new file mode 100644 index 0000000000000000000000000000000000000000..984f61353de65b256a75607e10c9aa08598333ca GIT binary patch literal 412 zcmZ9IF$%&!6huc28ZbnQ6e+hzVIekNKnU0R}S+EEOL$LKWp2M5PnT;XhhL`>O zclOWzjRBmt`!x_Eh6f)3=7_igMkF7A888PJ!X-9jMow9pnY6q;Y*pKQ<@6Er(tE@- zO_PuX30SkMu6;wK^~sy4ZU;jQiS`Qe;(7Ti7n3E?-L%#jc}>ZoIA83wEOJ}9KIEqw zIxCH|z%y-U#i6^EoYb{?mR9@nNyxvC>KyM?&51Sj_4?@RB+quJ>;C-|cix(RW4#G5 L=1nI2yRrKK+1wxh literal 0 HcmV?d00001 diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/square.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/square.tflite new file mode 100644 index 0000000000000000000000000000000000000000..8bd23c38c7eda6abecf226bb9a8bbacdd9616d85 GIT binary patch literal 412 zcmZ9I!3u&v6h&_(CM4Fvh09sEXc2Atfk0>#804}|W!IG*geEOJ{leaKHW zbXFQ^foIarii74>a#GjoSz7JOCnowpn32Bd^rJd;y0n`YBA ztE+d@tW9yvY~Yq$l9VV9IAP6zZ@6=5y5wVT?I-yn1NQTsm6MW~L?mEC_4IJ*e9ig& zCDOItBZNoZ8SKilW>C#B(Q{6oHg7kLDK`1KtgDx@D$3lf7{9RAeiP-%V?wToYG^MH z^4}+q%h%j2>SbXXcW3f1zsi+HT40;CU#*93N=>C3*8NJWbIqV$>f!sSCw=0Fex%WP m?B2=`U9KYS{1~a0G@8@b;_^_>`v~aH`}_Ytq5D6S-~Ry-yD~Tc 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 new file mode 100644 index 0000000000..c90ff924a1 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_abs_parser_test.cc @@ -0,0 +1,34 @@ +/** + * 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 TestTfliteParserAbs : public TestTfliteParser { + public: + TestTfliteParserAbs() {} + void SetUp() override { meta_graph = LoadAndConvert("./abs.tflite", ""); } +}; + +TEST_F(TestTfliteParserAbs, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_Abs) << "wrong Op Type"; +} + +} // 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 new file mode 100644 index 0000000000..4d37fa506a --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_batch_to_space_nd_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 TestTfliteParserBatchToSpaceNd : public TestTfliteParser { + public: + TestTfliteParserBatchToSpaceNd() {} + void SetUp() override { meta_graph = LoadAndConvert("./batch_to_space_nd.tflite"); } +}; + +TEST_F(TestTfliteParserBatchToSpaceNd, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_BatchToSpace) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserBatchToSpaceNd, AttrValue) { + const std::vector blockShape{2, 2}; + const std::vector crops{0, 0, 2, 0}; + ASSERT_NE(meta_graph, nullptr); + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_NE(meta_graph->nodes.front()->primitive->value.AsBatchToSpace(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsBatchToSpace()->blockShape, blockShape); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsBatchToSpace()->crops, crops); +} + +} // 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 new file mode 100644 index 0000000000..785cd35e44 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_cos_parser_test.cc @@ -0,0 +1,34 @@ +/** + * 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 TestTfliteParserCos : public TestTfliteParser { + public: + TestTfliteParserCos() {} + void SetUp() override { meta_graph = LoadAndConvert("./cos.tflite", ""); } +}; + +TEST_F(TestTfliteParserCos, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_Cos) << "wrong Op Type"; +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_exp_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_exp_parser_test.cc index eec816f2a3..5a09b9e428 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_exp_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_exp_parser_test.cc @@ -13,31 +13,22 @@ * 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 "mindspore/core/utils/log_adapter.h" #include "common/common_test.h" -#include "tools/converter/converter_flags.h" -#include "schema/inner/model_generated.h" -#include "tools/converter/parser/tflite/tflite_converter.h" -#include "tools/converter/parser/tflite/tflite_exp_parser.h" -#include "src/kernel_registry.h" -#include "src/lite_kernel.h" namespace mindspore { - -class TestTfliteExpParser : public mindspore::Common { +class TestTfliteParserExp : public TestTfliteParser { public: - TestTfliteExpParser() {} + TestTfliteParserExp() {} + void SetUp() override { meta_graph = LoadAndConvert("./exp.tflite", ""); } }; -TEST_F(TestTfliteExpParser, ExpParser) { - lite::converter::Flags flags; - flags.modelFile = "./test_data/Exp.tflite"; - flags.fmk = lite::converter::FmkType_TFLITE; - lite::TfliteConverter converter; - schema::MetaGraphT *fb_graph = nullptr; - fb_graph = converter.Convert(&flags); - const auto &nodes = fb_graph->nodes; - nodes.back(); +TEST_F(TestTfliteParserExp, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_Exp) << "wrong Op Type"; } + } // namespace mindspore 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 new file mode 100644 index 0000000000..fe869019ce --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_log_parser_test.cc @@ -0,0 +1,34 @@ +/** + * 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 TestTfliteParserLog : public TestTfliteParser { + public: + TestTfliteParserLog() {} + void SetUp() override { meta_graph = LoadAndConvert("./log.tflite", ""); } +}; + +TEST_F(TestTfliteParserLog, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_Log) << "wrong Op Type"; +} + +} // namespace mindspore 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 new file mode 100644 index 0000000000..415dc874ee --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_and_parser_test.cc @@ -0,0 +1,34 @@ +/** + * 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 TestTfliteLogicalParserAnd : public TestTfliteParser { + public: + TestTfliteLogicalParserAnd() {} + void SetUp() override { meta_graph = LoadAndConvert("./logical_and.tflite", ""); } +}; + +TEST_F(TestTfliteLogicalParserAnd, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_LogicalAnd) << "wrong Op Type"; +} + +} // namespace mindspore 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 new file mode 100644 index 0000000000..a34ae07afe --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_not_parser_test.cc @@ -0,0 +1,34 @@ +/** + * 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 TestTfliteParserLogicalNot : public TestTfliteParser { + public: + TestTfliteParserLogicalNot() {} + void SetUp() override { meta_graph = LoadAndConvert("./logical_not.tflite", ""); } +}; + +TEST_F(TestTfliteParserLogicalNot, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_LogicalNot) << "wrong Op Type"; +} + +} // namespace mindspore 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 new file mode 100644 index 0000000000..19141d6125 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_or_parser_test.cc @@ -0,0 +1,34 @@ +/** + * 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 TestTfliteParserLogicalOr : public TestTfliteParser { + public: + TestTfliteParserLogicalOr() {} + void SetUp() override { meta_graph = LoadAndConvert("./logical_or.tflite", ""); } +}; + +TEST_F(TestTfliteParserLogicalOr, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_LogicalOr) << "wrong Op Type"; +} + +} // 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 new file mode 100644 index 0000000000..a21dba4d8b --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_maximum_parser_test.cc @@ -0,0 +1,34 @@ +/** + * 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 TestTfliteParserMaximum : public TestTfliteParser { + public: + TestTfliteParserMaximum() {} + void SetUp() override { meta_graph = LoadAndConvert("./maximum.tflite"); } +}; + +TEST_F(TestTfliteParserMaximum, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_Maximum) << "wrong Op Type"; +} + +} // namespace mindspore 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 new file mode 100644 index 0000000000..2999d33b16 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_minimum_parser_test.cc @@ -0,0 +1,34 @@ +/** + * 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 TestTfliteParserMinimum : public TestTfliteParser { + public: + TestTfliteParserMinimum() {} + void SetUp() override { meta_graph = LoadAndConvert("./minimum.tflite"); } +}; + +TEST_F(TestTfliteParserMinimum, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_Minimum) << "wrong Op Type"; +} + +} // namespace mindspore 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 new file mode 100644 index 0000000000..f1f007e849 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_one_hot_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 TestTfliteParserOneHot : public TestTfliteParser { + public: + TestTfliteParserOneHot() {} + void SetUp() override { meta_graph = LoadAndConvert("./one_hot.tflite"); } +}; + +TEST_F(TestTfliteParserOneHot, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_OneHot) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserOneHot, AttrValue) { + ASSERT_NE(meta_graph, nullptr); + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_NE(meta_graph->nodes.front()->primitive->value.AsOneHot(), nullptr); + // in OneHot parser axis = axis > 0 ? axis : axis + tensor_shape.size() + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsOneHot()->axis, 2); +} + +} // 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 new file mode 100644 index 0000000000..881d95b89f --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_parsers_test_utils.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 "schema/inner/model_generated.h" +#include "tools/converter/parser/tflite/tflite_model_parser.h" + +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); + return meta_graph; +} + +void TestTfliteParser::TearDown() { free(meta_graph); } + +} // namespace mindspore 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 new file mode 100644 index 0000000000..cf592570c3 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h @@ -0,0 +1,35 @@ +/** + * 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 MINDSPORE_LITE_TEST_UT_TOOLS_CONVERTER_PARSER_TFLITE_TFLITE_PARSERS_TEST_H_ +#define MINDSPORE_LITE_TEST_UT_TOOLS_CONVERTER_PARSER_TFLITE_TFLITE_PARSERS_TEST_H_ + +#include +#include "common/common_test.h" +#include "schema/inner/model_generated.h" + +namespace mindspore { +class TestTfliteParser : public Common { + public: + TestTfliteParser() {} + void TearDown() override; + schema::MetaGraphT *LoadAndConvert(const std::string &model_path, const std::string &weight_path = ""); + schema::MetaGraphT *meta_graph; +}; + +} // namespace mindspore + +#endif // MINDSPORE_LITE_TEST_UT_TOOLS_CONVERTER_PARSER_TFLITE_TFLITE_PARSERS_TEST_H_ 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 new file mode 100644 index 0000000000..6c2ff57114 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_max_parser_test.cc @@ -0,0 +1,46 @@ +/** + * 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 TestTfliteParserReduceMax : public TestTfliteParser { + public: + TestTfliteParserReduceMax() {} + void SetUp() override { meta_graph = LoadAndConvert("./reduce_max.tflite"); } +}; + +TEST_F(TestTfliteParserReduceMax, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_Reduce) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserReduceMax, AttrValue) { + ASSERT_NE(meta_graph, nullptr); + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_NE(meta_graph->nodes.front()->primitive->value.AsReduce(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->mode, schema::ReduceMode_ReduceMax) + << "wrong reduce mode"; + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->keepDims, false); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->axes.size(), 1); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->axes[0], 2); +} + +} // namespace mindspore 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 new file mode 100644 index 0000000000..dce6a95fb0 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_min_parser_test.cc @@ -0,0 +1,46 @@ +/** + * 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 TestTfliteParserReduceMin : public TestTfliteParser { + public: + TestTfliteParserReduceMin() {} + void SetUp() override { meta_graph = LoadAndConvert("./reduce_min.tflite"); } +}; + +TEST_F(TestTfliteParserReduceMin, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_Reduce) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserReduceMin, AttrValue) { + ASSERT_NE(meta_graph, nullptr); + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_NE(meta_graph->nodes.front()->primitive->value.AsReduce(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->mode, schema::ReduceMode_ReduceMin) + << "wrong reduce mode"; + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->keepDims, false); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->axes.size(), 1); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->axes[0], 2); +} + +} // namespace mindspore 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 new file mode 100644 index 0000000000..dc19ad983f --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_prod_parser_test.cc @@ -0,0 +1,46 @@ +/** + * 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 TestTfliteParserReduceProd : public TestTfliteParser { + public: + TestTfliteParserReduceProd() {} + void SetUp() override { meta_graph = LoadAndConvert("./reduce_prod.tflite"); } +}; + +TEST_F(TestTfliteParserReduceProd, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_Reduce) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserReduceProd, AttrValue) { + ASSERT_NE(meta_graph, nullptr); + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_NE(meta_graph->nodes.front()->primitive->value.AsReduce(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->mode, schema::ReduceMode_ReduceProd) + << "wrong reduce mode"; + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->keepDims, false); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->axes.size(), 1); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->axes[0], 2); +} + +} // namespace mindspore 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 new file mode 100644 index 0000000000..c1db7380cb --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_rsqrt_parser_test.cc @@ -0,0 +1,34 @@ +/** + * 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 TestTfliteParserRsqrt : public TestTfliteParser { + public: + TestTfliteParserRsqrt() {} + void SetUp() override { meta_graph = LoadAndConvert("./rsqrt.tflite", ""); } +}; + +TEST_F(TestTfliteParserRsqrt, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_Rsqrt) << "wrong Op Type"; +} + +} // namespace mindspore 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 new file mode 100644 index 0000000000..a859cabc87 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sin_parser_test.cc @@ -0,0 +1,34 @@ +/** + * 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 TestTfliteParserSin : public TestTfliteParser { + public: + TestTfliteParserSin() {} + void SetUp() override { meta_graph = LoadAndConvert("./sin.tflite", ""); } +}; + +TEST_F(TestTfliteParserSin, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_Sin) << "wrong Op Type"; +} + +} // namespace mindspore 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 new file mode 100644 index 0000000000..aae2b629d1 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_split_parser_test.cc @@ -0,0 +1,46 @@ +/** + * 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 TestTfliteParserSplit : public TestTfliteParser { + public: + TestTfliteParserSplit() {} + + void SetUp() override { meta_graph = LoadAndConvert("./split.tflite"); } +}; + +TEST_F(TestTfliteParserSplit, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_Split) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserSplit, AttrValue) { + ASSERT_NE(meta_graph, nullptr); + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_NE(meta_graph->nodes.front()->primitive->value.AsSplit(), nullptr); + const std::vector sizeSplits{2, 2}; + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsSplit()->splitDim, 2); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsSplit()->numberSplit, 2); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsSplit()->sizeSplits, sizeSplits); +} + +} // namespace mindspore 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 new file mode 100644 index 0000000000..30a7049a42 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_split_v_parser_test.cc @@ -0,0 +1,46 @@ +/** + * 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 TestTfliteParserSplitV : public TestTfliteParser { + public: + TestTfliteParserSplitV() {} + + void SetUp() override { meta_graph = LoadAndConvert("./split_v.tflite"); } +}; + +TEST_F(TestTfliteParserSplitV, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_Split) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserSplitV, AttrValue) { + ASSERT_NE(meta_graph, nullptr); + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_NE(meta_graph->nodes.front()->primitive->value.AsSplit(), nullptr); + const std::vector sizeSplits{1, 3}; + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsSplit()->splitDim, 0); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsSplit()->numberSplit, 2); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsSplit()->sizeSplits, sizeSplits); +} + +} // namespace mindspore 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 new file mode 100644 index 0000000000..427907dc70 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sqrt_parser_test.cc @@ -0,0 +1,34 @@ +/** + * 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 TestTfliteParserSqrt : public TestTfliteParser { + public: + TestTfliteParserSqrt() {} + void SetUp() override { meta_graph = LoadAndConvert("./sqrt.tflite", ""); } +}; + +TEST_F(TestTfliteParserSqrt, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_Sqrt) << "wrong Op Type"; +} + +} // namespace mindspore 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 new file mode 100644 index 0000000000..5301c2302a --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_square_parser_test.cc @@ -0,0 +1,34 @@ +/** + * 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 TestTfliteParserSquare : public TestTfliteParser { + public: + TestTfliteParserSquare() {} + void SetUp() override { meta_graph = LoadAndConvert("./square.tflite", ""); } +}; + +TEST_F(TestTfliteParserSquare, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_Square) << "wrong Op Type"; +} + +} // 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 new file mode 100644 index 0000000000..f028516da2 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sum_parser_test.cc @@ -0,0 +1,47 @@ +/** + * 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 TestTfliteParserSum : public TestTfliteParser { + public: + TestTfliteParserSum() {} + + void SetUp() override { meta_graph = LoadAndConvert("./sum.tflite"); } +}; + +TEST_F(TestTfliteParserSum, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_Reduce) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserSum, AttrValue) { + ASSERT_NE(meta_graph, nullptr); + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_NE(meta_graph->nodes.front()->primitive->value.AsReduce(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->mode, schema::ReduceMode_ReduceSum) + << "wrong reduce mode"; + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->keepDims, false); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->axes.size(), 1); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->axes[0], 2); +} + +} // namespace mindspore 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 a7f12d9e17..6ed52bfb12 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 @@ -24,12 +24,13 @@ STATUS TfliteBatchToSpaceNDParser::Parse(const std::unique_ptr> &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(INFO) << "parse TfliteBatchToSpaceNDParser"; std::unique_ptr attr(new schema::BatchToSpaceT()); + // in tflite + // blockShape should be a 1D tensor with dimension [spatial_dims_num] + // crops should be a 2D tensor with dimension [spatial_dims_num, 2] if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->blockShape)) { MS_LOG(ERROR) << "BatchToSpaceNd get blockShape attr failed"; return RET_ERROR; 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 57660c1fb8..8694a71840 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 @@ -32,8 +32,12 @@ STATUS TfliteOneHotParser::Parse(const std::unique_ptr &tflit MS_LOG(ERROR) << "get op: " << op->name << " attr failed"; return RET_NULL_PTR; } - - attr->axis = tflite_attr->axis; + auto axis = tflite_attr->axis; + const auto tensor_shape = tfliteTensors[tfliteOp->inputs[0]].get()->shape; + if (axis < 0) { + axis += tensor_shape.size(); + } + attr->axis = axis; if (op != nullptr) { op->primitive = std::make_unique(); 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 f416db2e5e..a113266496 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 @@ -39,6 +39,8 @@ STATUS TfliteScatterNdParser::Parse(const std::unique_ptr &tf MS_LOG(DEBUG) << i; } */ + // in tflite, kIndices = 0, kUpdates = 1, kShape = 2 + // in mslite, kScatterShapeIndex = 0, kScatterIndicesIndex = 1, kScatterUpdateIndex = 2; std::swap(op->inputIndex[0], op->inputIndex[2]); std::swap(op->inputIndex[1], op->inputIndex[2]); /* 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 b2d5f1246e..eeb5d7c226 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_split_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_split_parser.cc @@ -54,7 +54,7 @@ STATUS TfliteSplitParser::Parse(const std::unique_ptr &tflite } attr->numberSplit = num_splits; - for (int i = 0; i <= num_splits; i++) { + for (int i = 0; i < num_splits; i++) { attr->sizeSplits.push_back(tensor_shape[axis] / num_splits); }