[Filter] Update reaction to tensor dimension errors.
authorMyungJoo Ham <myungjoo.ham@samsung.com>
Fri, 23 Nov 2018 02:54:14 +0000 (11:54 +0900)
committerMyungJoo Ham <myungjoo.ham@gmail.com>
Sun, 25 Nov 2018 02:28:22 +0000 (02:28 +0000)
When input/output tensor dimension is not compatible,
don't exit with assert, let gstreamer handle the rest.

This will help looking at the issue of #886

Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
gst/tensor_filter/tensor_filter.c

index ee3de9d..8325928 100644 (file)
@@ -857,6 +857,62 @@ gst_tensor_filter_load_tensor_info (GstTensorFilter * self)
 }
 
 /**
+ * @brief Printout the comparison results of two tensors.
+ * @param[in] info1 The tensors to be shown on the left hand side
+ * @param[in] info2 The tensors to be shown on the right hand side
+ * @return The newly allocated string for the printout. The caller must deallocate it.
+ * @todo If this is going to be used by other elements, move this to nnstreamer/tensor_common.
+ */
+static gchar *
+_compare_tensors (GstTensorsInfo * info1, GstTensorsInfo * info2)
+{
+  gchar null[] = "";
+  gchar *result = null;
+  int i;
+
+  for (i = 0; i < NNS_TENSOR_SIZE_LIMIT; i++) {
+    gchar *line, *tmp;
+    gchar *left = NULL, *right = NULL;
+
+    if (info1->num_tensors <= i && info2->num_tensors <= i)
+      break;
+
+    if (info1->num_tensors > i) {
+      gchar *dimstr = get_tensor_dimension_string (info1->info[i].dimension);
+      left = g_strdup_printf ("%s [%s]",
+          tensor_element_typename[info1->info[i].type], dimstr);
+      g_free (dimstr);
+    } else {
+      left = null;
+    }
+
+    if (info2->num_tensors > i) {
+      gchar *dimstr = get_tensor_dimension_string (info2->info[i].dimension);
+      right = g_strdup_printf ("%s [%s",
+          tensor_element_typename[info2->info[i].type], dimstr);
+      g_free (dimstr);
+    } else {
+      right = null;
+    }
+
+    line = g_strdup_printf ("%2d : %s  | %s\n", i, left, right);
+    if (left[0] != '\0')
+      g_free (left);
+    if (right[0] != '\0')
+      g_free (right);
+
+    tmp = g_strdup_printf ("%s%s", result, line);
+
+    if (result[0] != '\0')
+      g_free (result);
+    result = tmp;
+    g_free (line);
+  }
+
+  return result;
+}
+
+/**
  * @brief Configure input and output tensor info from incaps.
  * @param self "this" pointer
  * @param incaps received caps for sink pad
@@ -893,7 +949,10 @@ gst_tensor_filter_configure_tensor (GstTensorFilter * self,
     /** if set-property called and already has info, verify it! */
     if (prop->input_meta.num_tensors > 0) {
       if (!gst_tensors_info_is_equal (&in_config.info, &prop->input_meta)) {
-        g_assert (0);
+        gchar *str = _compare_tensors (&in_config.info, &prop->input_meta);
+        GST_ERROR_OBJECT (self, "The input tensor is not compatible.\n%s", str);
+        g_free (str);
+
         return FALSE;
       }
     }
@@ -915,7 +974,11 @@ gst_tensor_filter_configure_tensor (GstTensorFilter * self,
           /** if set-property called and already has info, verify it! */
           if (prop->output_meta.num_tensors > 0) {
             if (!gst_tensors_info_is_equal (&prop->output_meta, &out_info)) {
-              g_assert (0);
+              gchar *str =
+                  _compare_tensors (&in_config.info, &prop->input_meta);
+              GST_ERROR_OBJECT (self,
+                  "The output tensor is not compatible.\n%s", str);
+              g_free (str);
               return FALSE;
             }
           }