[Transform] option for DC removal
authorJaeyun <jy1210.jung@samsung.com>
Thu, 11 Mar 2021 10:12:23 +0000 (19:12 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Tue, 23 Mar 2021 01:05:21 +0000 (10:05 +0900)
Add new option for DC removal (average value) in stand mode.

Signed-off-by: Jaeyun <jy1210.jung@samsung.com>
gst/nnstreamer/tensor_transform/README.md
gst/nnstreamer/tensor_transform/tensor_transform.c
gst/nnstreamer/tensor_transform/tensor_transform.h

index 1a92209..5e05744 100644 (file)
@@ -74,7 +74,13 @@ title: tensor_transform
         ```
 
     - (4): stand
-      - A Mode for statistical standardization of tensor, option=default
+      - A mode for statistical standardization or normalization of tensor
+      - An option should be provided as option=(default|dc-average)[:TYPE] where `default` for statistical standardization and `dc-average` to remove DC offset (average value). `TYPE` denotes output data type.
+      - Example: Remove DC offset, output type to float32
+
+        ```bash
+        ... ! tensor_converter ! tensor_transform mode=stand option=dc-average:float32 ! ...
+        ```
 
 - acceleration (readable, writable): A flat indicating whether to enable ```orc``` acceleration
 
index 06c5257..3b49b46 100644 (file)
@@ -124,6 +124,7 @@ enum
 
 static const gchar *gst_tensor_transform_stand_string[] = {
   [STAND_DEFAULT] = "default",
+  [STAND_DC_AVERAGE] = "dc-average",
   [STAND_END] = NULL
 };
 
@@ -200,7 +201,7 @@ gst_tensor_transform_mode_get_type (void)
             "option=D1\':D2\':D3\':D4 (fixed to 3)",
           "transpose"},
       {GTT_STAND, "Mode for statistical standardization of tensor, "
-            "option=default[:TYPE]",
+            "option=(default|dc-average)[:TYPE]",
           "stand"},
       {GTT_CLAMP, "Mode for clamping all elements of tensor into the range, "
             "option=CLAMP_MIN:CLAMP_MAX",
@@ -701,7 +702,7 @@ gst_tensor_transform_set_option_data (GstTensorTransform * filter)
 
       if (filter->data_stand.mode == STAND_END) {
         ml_loge
-            ("%s: stand: \'%s\' is not valid option string: it should be \'default\', currently the only supported mode.\n",
+            ("%s: stand: \'%s\' is not valid option string: it should be in the form of (default|dc-average)[:TYPE]\n",
             filter_name, filter->option);
         break;
       }
@@ -1201,6 +1202,21 @@ gst_tensor_transform_stand (GstTensorTransform * filter,
 
       break;
     }
+    case STAND_DC_AVERAGE:
+    {
+      for (i = 0; i < num; i++) {
+        data_idx = in_element_size * i;
+        gst_tensor_data_raw_typecast ((gpointer) (inptr + data_idx),
+            in_tensor_type, &tmp, _NNS_FLOAT64);
+
+        tmp -= average;
+
+        data_idx = out_element_size * i;
+        gst_tensor_data_raw_typecast (&tmp, _NNS_FLOAT64,
+            (gpointer) (outptr + data_idx), out_tensor_type);
+      }
+      break;
+    }
     default:
       GST_ERROR_OBJECT (filter, "Cannot identify mode\n");
       return GST_FLOW_ERROR;
index a37954a..f8f1185 100644 (file)
@@ -79,6 +79,7 @@ typedef enum
 typedef enum
 {
   STAND_DEFAULT = 0,
+  STAND_DC_AVERAGE = 1,
   STAND_END,
 } tensor_transform_stand_mode;