From dabcd1018dbc55f6918cfedd6ccefd19fcea92c2 Mon Sep 17 00:00:00 2001 From: Yongjoo Ahn Date: Tue, 9 Nov 2021 14:57:56 +0900 Subject: [PATCH] [tests/tflite] Add tests for tflite2 - Set tensor_filter_ext_enabled when tflite2_support is available - Add a gtest based test to examine the XNNPACK delegate Signed-off-by: Yongjoo Ahn --- tests/meson.build | 1 + .../unittest_filter_tensorflow2_lite.cc | 41 ++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/tests/meson.build b/tests/meson.build index 413473b..8c9c8ac 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -295,6 +295,7 @@ if gtest_dep.found() endif # gtest_dep.found() tensor_filter_ext_enabled = tflite_support_is_available or \ + tflite2_support_is_available or \ tf_support_is_available or \ have_python3 or \ pytorch_support_is_available or caffe2_support_is_available or \ diff --git a/tests/nnstreamer_filter_tensorflow2_lite/unittest_filter_tensorflow2_lite.cc b/tests/nnstreamer_filter_tensorflow2_lite/unittest_filter_tensorflow2_lite.cc index d19a496..c479886 100644 --- a/tests/nnstreamer_filter_tensorflow2_lite/unittest_filter_tensorflow2_lite.cc +++ b/tests/nnstreamer_filter_tensorflow2_lite/unittest_filter_tensorflow2_lite.cc @@ -226,6 +226,47 @@ TEST (nnstreamerFilterTensorFlow2Lite, floatModelResult) EXPECT_EQ (setPipelineStateSync (gstpipe, GST_STATE_NULL, UNITTEST_STATECHANGE_TIMEOUT), 0); + gst_object_unref (sink_handle); + gst_object_unref (gstpipe); + g_free (pipeline); + g_free (model_file); + g_free (input_file); + g_free (is_float); +} + +/** + * @brief Positive case to launch gst pipeline + */ +TEST (nnstreamerFilterTensorFlow2Lite, floatModelXNNPACKResult) +{ + gchar *pipeline; + GstElement *gstpipe; + GError *err = NULL; + gchar *model_file, *input_file; + + ASSERT_TRUE (_GetModelFilePath (&model_file, 1)); + ASSERT_TRUE (_GetOrangePngFilePath (&input_file)); + + /* create a nnstreamer pipeline */ + pipeline = g_strdup_printf ("filesrc location=\"%s\" ! pngdec ! videoscale ! imagefreeze ! videoconvert ! video/x-raw,format=RGB,width=224,height=224,framerate=20/1 ! tensor_converter ! tensor_transform mode=arithmetic option=typecast:float32,add:-127.5,div:127.5 ! tensor_filter framework=tensorflow2-lite model=\"%s\" custom=Delegate:XNNPACK,NumThreads:4 ! tensor_sink name=sink", + input_file, model_file); + + gstpipe = gst_parse_launch (pipeline, &err); + ASSERT_TRUE (gstpipe != nullptr); + + GstElement *sink_handle = gst_bin_get_by_name (GST_BIN (gstpipe), "sink"); + ASSERT_TRUE (sink_handle != nullptr); + + guint8 *is_float = (guint8 *) g_malloc0 (1); + *is_float = 1; + g_signal_connect (sink_handle, "new-data", (GCallback) check_output, is_float); + + EXPECT_EQ (setPipelineStateSync (gstpipe, GST_STATE_PLAYING, UNITTEST_STATECHANGE_TIMEOUT * 10), 0); + g_usleep (1000 * 1000 * 5); // wait for 5 seconds to check all output is valid + + EXPECT_EQ (setPipelineStateSync (gstpipe, GST_STATE_NULL, UNITTEST_STATECHANGE_TIMEOUT), 0); + + gst_object_unref (sink_handle); gst_object_unref (gstpipe); g_free (pipeline); g_free (model_file); -- 2.7.4