[Filter] support flex tensor
authorJaeyun <jy1210.jung@samsung.com>
Mon, 3 May 2021 09:17:55 +0000 (18:17 +0900)
committerjaeyun-jung <39614140+jaeyun-jung@users.noreply.github.com>
Mon, 17 May 2021 08:47:16 +0000 (17:47 +0900)
Add pad template to support flex tensor in tensor-filter.

If incoming tensor is flexible, tensor-filter cannot get the meta from caps.
In this case, tensor-filter gets model info from subplugin and compares buffer size in transform().
That means, if the model handles non-static info (e.g., set-dimension with input info), it cannot support flex tensor.

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

index f6ca710..b2c4471 100644 (file)
@@ -119,7 +119,7 @@ GST_DEBUG_CATEGORY_STATIC (gst_tensor_filter_debug);
 /**
  * @brief Default caps string for both sink and source pad.
  */
-#define CAPS_STRING GST_TENSOR_CAP_DEFAULT "; " GST_TENSORS_CAP_DEFAULT
+#define CAPS_STRING GST_TENSOR_CAP_DEFAULT ";" GST_TENSORS_CAP_DEFAULT ";" GST_TENSORS_FLEX_CAP_DEFAULT
 
 /**
  * @brief The capabilities of the inputs
@@ -765,6 +765,7 @@ gst_tensor_filter_configure_tensor (GstTensorFilter * self,
   GstStructure *structure;
   GstTensorsConfig in_config, out_config;
   GstTensorsInfo in_info, out_info;
+  gboolean flexible;
 
   g_return_val_if_fail (incaps != NULL, FALSE);
 
@@ -801,15 +802,31 @@ gst_tensor_filter_configure_tensor (GstTensorFilter * self,
     goto done;
   }
 
+  /* flexible tensor case, we cannot get the exact info from caps. */
+  flexible = gst_tensors_info_is_flexible (&in_info);
+
   /** if set-property called and already has info, verify it! */
   if (prop->input_meta.num_tensors > 0) {
-    if (!gst_tensors_info_is_equal (&in_info, &prop->input_meta)) {
+    if (flexible) {
+      /**
+       * If incoming tensor is flexible, we cannot validate tensor info here.
+       * Need to compare buffer size in transform().
+       */
+      GST_INFO_OBJECT (self, "The input tensor is flexible.");
+    } else if (!gst_tensors_info_is_equal (&in_info, &prop->input_meta)) {
       GST_ERROR_OBJECT (self, "The input tensor is not compatible.");
       gst_tensor_filter_compare_tensors (&in_info, &prop->input_meta);
       goto done;
     }
   } else {
-    gst_tensors_info_copy (&prop->input_meta, &in_info);
+    if (flexible) {
+      /* cannot update meta from caps */
+      GST_ERROR_OBJECT (self,
+          "The input tensor is flexible, cannot configure input info.");
+      goto done;
+    } else {
+      gst_tensors_info_copy (&prop->input_meta, &in_info);
+    }
   }
 
   prop->input_configured = TRUE;
@@ -909,6 +926,16 @@ gst_tensor_filter_caps_from_config (GstTensorFilter * self,
   /* other/tensors */
   gst_caps_append (caps, gst_tensors_caps_from_config (config));
 
+  /* other/tensors-flexible */
+  if (!gst_tensors_info_is_flexible (&config->info)) {
+    GstTensorsConfig c;
+
+    c = *config;
+    c.info.info[0].format = _NNS_TENSOR_FORMAT_FLEXIBLE;
+
+    gst_caps_append (caps, gst_tensors_caps_from_config (&c));
+  }
+
   return gst_caps_simplify (caps);
 }
 
@@ -1100,7 +1127,9 @@ gst_tensor_filter_set_caps (GstBaseTransform * trans,
   structure = gst_caps_get_structure (outcaps, 0);
   gst_tensors_config_from_structure (&config, structure);
 
-  if (!gst_tensors_config_is_equal (&priv->out_config, &config)) {
+  if (gst_tensors_info_is_flexible (&config.info)) {
+    GST_INFO_OBJECT (self, "Output tensor is flexible.");
+  } else if (!gst_tensors_config_is_equal (&priv->out_config, &config)) {
     GST_ERROR_OBJECT (self, "Invalid outcaps.");
     return FALSE;
   }
index 3cc9228..f2e2a8b 100644 (file)
@@ -2223,6 +2223,11 @@ gst_tensor_filter_common_get_out_info (GstTensorFilterPrivate * priv,
 
   gst_tensors_info_init (out);
 
+  if (gst_tensors_info_is_flexible (in)) {
+    nns_logw ("Given input info is flexible, cannot get output info.");
+    return FALSE;
+  }
+
   if (!gst_tensors_info_validate (in)) {
     nns_logw ("Given input info is invalid, cannot get output info.");
     return FALSE;