[Filter/Sub] sub-plugin priority
authorJaeyun <jy1210.jung@samsung.com>
Wed, 9 Dec 2020 10:51:41 +0000 (19:51 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Thu, 10 Dec 2020 09:55:29 +0000 (18:55 +0900)
Set sub-plugin priority in ini.
(For tensorflow-lite, tf2-lite has high priority if tf2-lite is available.)

Signed-off-by: Jaeyun <jy1210.jung@samsung.com>
gst/nnstreamer/tensor_filter/tensor_filter_common.c
meson.build
nnstreamer.ini.in

index d94784b..efb5b4b 100644 (file)
@@ -623,27 +623,36 @@ const GstTensorFilterFramework *
 nnstreamer_filter_find (const char *name)
 {
   const GstTensorFilterFramework *fw;
-  guint i;
 
   g_return_val_if_fail (name != NULL, NULL);
 
   fw = get_subplugin (NNS_SUBPLUGIN_FILTER, name);
 
   if (fw == NULL) {
-    if (g_ascii_strcasecmp (name, "tensorflow-lite") == 0) {
-      /* find sug-plugin name for tf-lite version 2.x or 1.x */
-      /** @todo consider to add subplugin priority in .ini file */
-      const char *tflite_subplugins[] = {
-        "tensorflow2-lite", "tensorflow1-lite"
-      };
-
-      for (i = 0; i < 2; i++) {
-        fw = get_subplugin (NNS_SUBPLUGIN_FILTER, tflite_subplugins[i]);
+    /* get sub-plugin priority from ini file and find sub-plugin */
+    gchar *_str;
+
+    _str = nnsconf_get_custom_value_string (name, "subplugin_priority");
+    if (_str) {
+      gchar **subplugins;
+      guint i, len;
+
+      subplugins = g_strsplit_set (_str, " ,;", -1);
+      len = g_strv_length (subplugins);
+
+      for (i = 0; i < len; i++) {
+        if (strlen (g_strstrip (subplugins[i])) == 0)
+          continue;
+
+        fw = get_subplugin (NNS_SUBPLUGIN_FILTER, subplugins[i]);
         if (fw) {
-          nns_logi ("Found %s for %s.", tflite_subplugins[i], name);
+          nns_logi ("Found %s for %s.", subplugins[i], name);
           break;
         }
       }
+
+      g_strfreev (subplugins);
+      g_free (_str);
     }
   }
 
index cf79478..58f96ff 100644 (file)
@@ -406,7 +406,6 @@ if python2_dep.found()
 
 else
   warning('Python2.7 either not found or disabled')
-
 endif
 
 # Check python 3.x
@@ -442,6 +441,17 @@ else
   warning('python3 either not found or disabled')
 endif
 
+# Set sub-plugin priority
+tflite_subplugin_list = []
+if tflite2_support_is_available
+  tflite_subplugin_list += 'tensorflow2-lite'
+endif
+if tflite_support_is_available
+  tflite_subplugin_list += 'tensorflow1-lite'
+endif
+
+nnstreamer_conf.set('TFLITE_SUBPLUGIN_PRIORITY', ','.join(tflite_subplugin_list))
+
 # Set configuration to install .ini
 nnstreamer_install_conf = configuration_data()
 nnstreamer_install_conf.merge_from(nnstreamer_conf)
index 986d3f0..74b0790 100644 (file)
@@ -22,4 +22,7 @@ converters=@SUBPLUGIN_INSTALL_PREFIX@/converters/
 [pytorch]
 enable_use_gpu=@TORCH_USE_GPU@
 
+[tensorflow-lite]
+subplugin_priority=@TFLITE_SUBPLUGIN_PRIORITY@
+
 @ELEMENT_RESTRICTION_CONFIG@