[tensor_filter] Add tensor filter config property
authorlinuxias <linuxias@gmail.com>
Tue, 12 Sep 2023 15:26:33 +0000 (00:26 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Thu, 21 Sep 2023 08:21:01 +0000 (17:21 +0900)
 tensor filter configuration is very complex, so when you set filter,
 property settings become longer and more complicated, making it
 difficult to find them at once even if human errors occur.

 If config is used, readability can be increased and human errors
 can be reduced due to organized properties.

Signed-off-by: linuxias <linuxias@gmail.com>
gst/nnstreamer/tensor_filter/tensor_filter.c
gst/nnstreamer/tensor_filter/tensor_filter_common.c
gst/nnstreamer/tensor_filter/tensor_filter_common.h
tests/nnstreamer_filter_tensorflow2_lite/config_file.0 [new file with mode: 0644]
tests/nnstreamer_filter_tensorflow2_lite/config_file_golden.0 [new file with mode: 0644]
tests/nnstreamer_filter_tensorflow2_lite/config_file_golden.1 [new file with mode: 0644]
tests/nnstreamer_filter_tensorflow2_lite/config_file_golden.2 [new file with mode: 0644]
tests/nnstreamer_filter_tensorflow2_lite/runTest.sh

index 6d5e78b..79ca38d 100644 (file)
@@ -290,8 +290,13 @@ gst_tensor_filter_set_property (GObject * object, guint prop_id,
 
   silent_debug (self, "Setting property for prop %d.\n", prop_id);
 
-  if (!gst_tensor_filter_common_set_property (priv, prop_id, value, pspec))
+  if (prop_id == PROP_CONFIG) {
+    const gchar *config_path = g_value_get_string (value);
+    gst_tensor_parse_config_file (config_path, object);
+  } else if (!gst_tensor_filter_common_set_property (priv, prop_id, value,
+          pspec)) {
     G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+  }
 }
 
 /**
index f755b15..371f24b 100644 (file)
@@ -101,38 +101,6 @@ G_LOCK_DEFINE_STATIC (shared_model_table);
 static GHashTable *shared_model_table = NULL;
 
 /**
- * @brief GstTensorFilter properties.
- */
-enum
-{
-  PROP_0,
-  PROP_SILENT,
-  PROP_FRAMEWORK,
-  PROP_MODEL,
-  PROP_INPUT,
-  PROP_INPUTTYPE,
-  PROP_INPUTNAME,
-  PROP_INPUTLAYOUT,
-  PROP_INPUTRANKS,
-  PROP_OUTPUT,
-  PROP_OUTPUTTYPE,
-  PROP_OUTPUTNAME,
-  PROP_OUTPUTLAYOUT,
-  PROP_OUTPUTRANKS,
-  PROP_CUSTOM,
-  PROP_SUBPLUGINS,
-  PROP_ACCELERATOR,
-  PROP_IS_UPDATABLE,
-  PROP_LATENCY,
-  PROP_THROUGHPUT,
-  PROP_INPUTCOMBINATION,
-  PROP_OUTPUTCOMBINATION,
-  PROP_SHARED_TENSOR_FILTER_KEY,
-  PROP_LATENCY_REPORT,
-  PROP_INVOKE_DYNAMIC,
-};
-
-/**
  * @brief Initialize the tensors layout.
  */
 static void
@@ -1030,6 +998,10 @@ gst_tensor_filter_install_properties (GObjectClass * gobject_class)
           "input and output of the tensor filter. "
           "With this option, the output caps is always in the format of flexible tensors.",
           FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+  g_object_class_install_property (gobject_class, PROP_CONFIG,
+      g_param_spec_string ("config-file", "Configuration-file",
+          "sets config file path which contains plugins properties", "",
+          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 }
 
 /**
index f9cd5b1..9a29324 100644 (file)
@@ -77,6 +77,39 @@ G_BEGIN_DECLS
 #define GST_TF_STAT_MAX_RECENT (10)
 
 /**
+ * @brief GstTensorFilter properties.
+ */
+enum
+{
+  PROP_0,
+  PROP_SILENT,
+  PROP_FRAMEWORK,
+  PROP_MODEL,
+  PROP_INPUT,
+  PROP_INPUTTYPE,
+  PROP_INPUTNAME,
+  PROP_INPUTLAYOUT,
+  PROP_INPUTRANKS,
+  PROP_OUTPUT,
+  PROP_OUTPUTTYPE,
+  PROP_OUTPUTNAME,
+  PROP_OUTPUTLAYOUT,
+  PROP_OUTPUTRANKS,
+  PROP_CUSTOM,
+  PROP_SUBPLUGINS,
+  PROP_ACCELERATOR,
+  PROP_IS_UPDATABLE,
+  PROP_LATENCY,
+  PROP_THROUGHPUT,
+  PROP_INPUTCOMBINATION,
+  PROP_OUTPUTCOMBINATION,
+  PROP_SHARED_TENSOR_FILTER_KEY,
+  PROP_LATENCY_REPORT,
+  PROP_INVOKE_DYNAMIC,
+  PROP_CONFIG
+};
+
+/**
  * @brief Structure definition for tensor-filter statistics
  */
 typedef struct _GstTensorFilterStatistics
diff --git a/tests/nnstreamer_filter_tensorflow2_lite/config_file.0 b/tests/nnstreamer_filter_tensorflow2_lite/config_file.0
new file mode 100644 (file)
index 0000000..b7987a1
--- /dev/null
@@ -0,0 +1,2 @@
+framework=tensorflow2-lite
+model=../test_models/models/sample_4x4x4x4x4_two_input_one_output.tflite
diff --git a/tests/nnstreamer_filter_tensorflow2_lite/config_file_golden.0 b/tests/nnstreamer_filter_tensorflow2_lite/config_file_golden.0
new file mode 100644 (file)
index 0000000..ea8f454
--- /dev/null
@@ -0,0 +1,2 @@
+framework=tensorflow2-lite
+model=../test_models/models/mobilenet_v1_1.0_224_quant.tflite
diff --git a/tests/nnstreamer_filter_tensorflow2_lite/config_file_golden.1 b/tests/nnstreamer_filter_tensorflow2_lite/config_file_golden.1
new file mode 100644 (file)
index 0000000..ab38e95
--- /dev/null
@@ -0,0 +1,4 @@
+framework=tensorflow2-lite
+model=../test_models/models/mobilenet_v1_1.0_224_quant.tflite
+input=7:1
+inputtype=float32
diff --git a/tests/nnstreamer_filter_tensorflow2_lite/config_file_golden.2 b/tests/nnstreamer_filter_tensorflow2_lite/config_file_golden.2
new file mode 100644 (file)
index 0000000..9b3b93e
--- /dev/null
@@ -0,0 +1,3 @@
+framework=tensorflow2-lite
+output=1:7
+outputtype=int8
index 369a863..4db2655 100644 (file)
@@ -82,12 +82,20 @@ gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} filesrc location=${PATH_TO_IMAGE} !
 python3 checkLabel.py tensorfilter.out.log ${PATH_TO_LABEL} orange
 testResult $? 1 "Golden test comparison" 0 1
 
+gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} filesrc location=${PATH_TO_IMAGE} ! pngdec ! videoscale ! imagefreeze ! videoconvert ! video/x-raw,format=RGB,framerate=0/1 ! tensor_converter ! tensor_filter config-file=config_file_golden.0 ! filesink location=tensorfilter.out.log" 1 0 0 $PERFORMANCE
+python3 checkLabel.py tensorfilter.out.log ${PATH_TO_LABEL} orange
+testResult $? 1 "Golden test comparison(with config_file_golden.0)" 0 1
+
 # Fail test for invalid input properties
 gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} filesrc location=${PATH_TO_IMAGE} ! pngdec ! videoscale ! imagefreeze ! videoconvert ! video/x-raw,format=RGB,framerate=0/1 ! tensor_converter ! tensor_filter framework=tensorflow2-lite model=${PATH_TO_MODEL} input=7:1 inputtype=float32 ! filesink location=tensorfilter.out.log" 2F_n 0 1 $PERFORMANCE
 
+gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} filesrc location=${PATH_TO_IMAGE} ! pngdec ! videoscale ! imagefreeze ! videoconvert ! video/x-raw,format=RGB,framerate=0/1 ! tensor_converter ! tensor_filter config-file=config_file_golden.1 ! filesink location=tensorfilter.out.log" "2F_n(with config_file_golden.1)" 0 1 $PERFORMANCE
+
 # Fail test for invalid output properties
 gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} filesrc location=${PATH_TO_IMAGE} ! pngdec ! videoscale ! imagefreeze ! videoconvert ! video/x-raw,format=RGB,framerate=0/1 ! tensor_converter ! tensor_filter framework=tensorflow2-lite model=${PATH_TO_MODEL} output=1:7 outputtype=int8 ! filesink location=tensorfilter.out.log" 3F_n 0 1 $PERFORMANCE
 
+gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} filesrc location=${PATH_TO_IMAGE} ! pngdec ! videoscale ! imagefreeze ! videoconvert ! video/x-raw,format=RGB,framerate=0/1 ! tensor_converter ! tensor_filter model=${PATH_TO_MODEL} config-file=config_file_golden.2 ! filesink location=tensorfilter.out.log" "3F_n(with config_file_golden.2)" 0 1 $PERFORMANCE
+
 PATH_TO_MULTI_TENSOR_OUTPUT_MODEL="../test_models/models/multi_person_mobilenet_v1_075_float.tflite"
 
 # Simple tests for multi-tensor output model
@@ -234,6 +242,9 @@ PATH_TO_MODEL="../test_models/models/sample_4x4x4x4x4_two_input_one_output.tflit
 gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} multifilesrc location=\"test_00.dat\" blocksize=-1 num_buffers=2 ! application/octet-stream ! tensor_converter input-dim=4:4:4:4:4 input-type=float32 ! tee name=t t. ! queue ! mux.sink_0 t. ! queue ! mux.sink_1  tensor_mux name=mux sync_mode=nosync ! queue ! tensor_filter framework=tensorflow2-lite model=${PATH_TO_MODEL} ! multifilesink location=tensorfilter.out.log" 6 0 0 $PERFORMANCE
 callCompareTest test_00.dat.golden tensorfilter.out.log 6 "Compare 6" 1 0
 
+gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} multifilesrc location=\"test_00.dat\" blocksize=-1 num_buffers=2 ! application/octet-stream ! tensor_converter input-dim=4:4:4:4:4 input-type=float32 ! tee name=t t. ! queue ! mux.sink_0 t. ! queue ! mux.sink_1  tensor_mux name=mux sync_mode=nosync ! queue ! tensor_filter config-file=config_file.0 ! multifilesink location=tensorfilter.out.log" "6(with config_file.0)" 0 0 $PERFORMANCE
+callCompareTest test_00.dat.golden tensorfilter.out.log 6 "Compare 6 (with config_file.0)" 1 0
+
 # Cleanup
 rm info *.log *.dat *.golden