[Example] remove common header
authorJaeyun <jy1210.jung@samsung.com>
Wed, 12 Dec 2018 03:57:27 +0000 (12:57 +0900)
committerMyungJoo Ham <myungjoo.ham@gmail.com>
Thu, 13 Dec 2018 11:08:32 +0000 (20:08 +0900)
In custom filter examples, remove tensor-common header.

Signed-off-by: Jaeyun Jung <jy1210.jung@samsung.com>
nnstreamer_example/custom_example_LSTM/dummy_LSTM.c
nnstreamer_example/custom_example_RNN/dummy_RNN.c
nnstreamer_example/custom_example_opencv/nnstreamer_customfilter_opencv_average.cc
nnstreamer_example/custom_example_opencv/nnstreamer_customfilter_opencv_scaler.cc
nnstreamer_example/custom_example_passthrough/nnstreamer_customfilter_example_passthrough.c
nnstreamer_example/custom_example_passthrough/nnstreamer_customfilter_example_passthrough_variable.c
nnstreamer_example/custom_example_scaler/nnstreamer_customfilter_example_scaler_allocator.c

index 79b0840..d9b5532 100644 (file)
@@ -20,7 +20,6 @@
 #include <errno.h>
 #include <math.h>
 #include <tensor_filter_custom.h>
-#include <tensor_common.h>
 
 #define TSIZE   (4)
 
index efd87b7..17af112 100644 (file)
@@ -19,8 +19,6 @@
 #include <string.h>
 #include <errno.h>
 #include <tensor_filter_custom.h>
-/* To use nnstreamer utilities (not mandatory for custom filters */
-#include <tensor_common.h>
 
 #define TSIZE   (4)
 
index 18ba2ba..79f9d26 100644 (file)
  * @author  Sangjung Woo <sangjung.woo@samsung.com>
  * @bug  No known bugs
  * @see  nnstreamer_customfilter_example_average.c
- * 
- * This example calculates the average value of input tensor for 
+ *
+ * This example calculates the average value of input tensor for
  * each channel (i.e. R, G & B). The shape of the input tensor is
- * [N][y][x][M] and that of the output tensor is [N][1][1][M]. 
+ * [N][y][x][M] and that of the output tensor is [N][1][1][M].
  */
 
 #include <opencv2/opencv.hpp>
 
 #include <glib.h>
 #include <tensor_filter_custom.h>
-#include <tensor_common.h>
 
 /**
  * @brief _pt_data Internal data structure
@@ -33,6 +32,26 @@ typedef struct _pt_data
 } pt_data;
 
 /**
+ * @brief get data size of single tensor
+ */
+static size_t
+get_tensor_data_size (const GstTensorInfo * info)
+{
+  size_t data_size = 0;
+  int i;
+
+  if (info != NULL) {
+    data_size = tensor_element_size[info->type];
+
+    for (i = 0; i < NNS_TENSOR_RANK_LIMIT; i++) {
+      data_size *= info->dimension[i];
+    }
+  }
+
+  return data_size;
+}
+
+/**
  * @brief pt_init
  */
 static void *
@@ -100,12 +119,12 @@ pt_invoke (void *private_data, const GstTensorFilterProperties * prop,
   std::vector<cv::Mat> channels;
   cv::Scalar mean_result;
   void *buffer;
-  
+
   g_assert (pdata);
   g_assert (input);
   g_assert (output);
 
-  in_size = gst_tensor_info_get_size (&prop->input_meta.info[0]);
+  in_size = get_tensor_data_size (&prop->input_meta.info[0]);
   buffer = g_malloc (in_size);
 
   /* Get Mat object from input tensor */
index 90a06b3..98000cc 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * NNStreamer OpenCV Custom Filter Example: Scaler
- * 
+ *
  * Copyright (C) 2018 Sangjung Woo <sangjung.woo@samsung.com>
  *
  * LICENSE: LGPL-2.1
@@ -11,8 +11,8 @@
  * @author  Sangjung Woo <sangjung.woo@samsung.com>
  * @bug  No known bugs
  * @see  nnstreamer_customfilter_example_scaler_allocator.c
- * 
- * This example scales an input tensor of [N][input_h][input_w][M] 
+ *
+ * This example scales an input tensor of [N][input_h][input_w][M]
  * to an ouput tensor of [N][output_h][output_w][M].
  *
  * The custom property is to be given as, "custom=[new-x]x[new-y]", where new-x and new-y are unsigned integers.
 #include "opencv2/opencv.hpp"
 #include "opencv2/highgui/highgui.hpp"
 
-#include <cassert>
 #include <glib.h>
 #include <tensor_filter_custom.h>
-#include <tensor_common.h>
 
 /**
  * @brief Private data structure
@@ -40,6 +38,26 @@ typedef struct _pt_data
 } pt_data;
 
 /**
+ * @brief get data size of single tensor
+ */
+static size_t
+get_tensor_data_size (const GstTensorInfo * info)
+{
+  size_t data_size = 0;
+  int i;
+
+  if (info != NULL) {
+    data_size = tensor_element_size[info->type];
+
+    for (i = 0; i < NNS_TENSOR_RANK_LIMIT; i++) {
+      data_size *= info->dimension[i];
+    }
+  }
+
+  return data_size;
+}
+
+/**
  * @brief init callback of tensor_filter custom
  */
 static void *
@@ -76,7 +94,7 @@ static void
 pt_exit (void *private_data, const GstTensorFilterProperties * prop)
 {
   pt_data *pdata = static_cast<pt_data *> (private_data);
-  assert (pdata);
+  g_assert (pdata);
   g_free (pdata);
 }
 
@@ -89,9 +107,9 @@ set_inputDim (void *private_data, const GstTensorFilterProperties * prop,
 {
   pt_data *pdata = static_cast<pt_data *> (private_data);
 
-  assert (pdata);
-  assert (in_info);
-  assert (out_info);
+  g_assert (pdata);
+  g_assert (in_info);
+  g_assert (out_info);
 
   out_info->num_tensors = 1;
 
@@ -125,12 +143,12 @@ pt_allocate_invoke (void *private_data,
   void* buffer;
   cv::Mat img_src, img_dst;
 
-  assert (pdata);
-  assert (input);
-  assert (output);
+  g_assert (pdata);
+  g_assert (input);
+  g_assert (output);
 
-  in_size = gst_tensor_info_get_size (&prop->input_meta.info[0]);
-  out_size = gst_tensor_info_get_size (&prop->output_meta.info[0]);
+  in_size = get_tensor_data_size (&prop->input_meta.info[0]);
+  out_size = get_tensor_data_size (&prop->output_meta.info[0]);
   buffer = g_malloc (in_size);
   output[0].data = g_malloc (out_size);
 
@@ -141,7 +159,7 @@ pt_allocate_invoke (void *private_data,
 
   /* Scale from the shape of input tensor to that of output tensor
    * which is given as custom property */
-  cv::resize (img_src, img_dst, cv::Size(pdata->out_width, pdata->out_height), 
+  cv::resize (img_src, img_dst, cv::Size(pdata->out_width, pdata->out_height),
             0, 0, CV_INTER_NN);
 
   /* Convert Mat object to output tensor */
index 9ba4819..dfa2df9 100644 (file)
@@ -16,8 +16,8 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <assert.h>
 #include <tensor_filter_custom.h>
-#include <tensor_common.h>
 
 #define D1     (3)
 #define D2     (280)
@@ -33,6 +33,26 @@ typedef struct _pt_data
 } pt_data;
 
 /**
+ * @brief get data size of single tensor
+ */
+static size_t
+get_tensor_data_size (const GstTensorInfo * info)
+{
+  size_t data_size = 0;
+  int i;
+
+  if (info != NULL) {
+    data_size = tensor_element_size[info->type];
+
+    for (i = 0; i < NNS_TENSOR_RANK_LIMIT; i++) {
+      data_size *= info->dimension[i];
+    }
+  }
+
+  return data_size;
+}
+
+/**
  * @brief _pt_data
  */
 static void *
@@ -59,7 +79,7 @@ static void
 pt_exit (void *private_data, const GstTensorFilterProperties * prop)
 {
   pt_data *data = private_data;
-  g_assert (data);
+  assert (data);
   free (data);
 }
 
@@ -72,8 +92,8 @@ get_inputDim (void *private_data, const GstTensorFilterProperties * prop,
 {
   pt_data *data = private_data;
 
-  g_assert (data);
-  g_assert (NNS_TENSOR_RANK_LIMIT >= 3);
+  assert (data);
+  assert (NNS_TENSOR_RANK_LIMIT >= 3);
 
   info->num_tensors = 1;
   info->info[0] = data->info;
@@ -89,8 +109,8 @@ get_outputDim (void *private_data, const GstTensorFilterProperties * prop,
 {
   pt_data *data = private_data;
 
-  g_assert (data);
-  g_assert (NNS_TENSOR_RANK_LIMIT >= 3);
+  assert (data);
+  assert (NNS_TENSOR_RANK_LIMIT >= 3);
 
   info->num_tensors = 1;
   info->info[0] = data->info;
@@ -107,13 +127,13 @@ pt_invoke (void *private_data, const GstTensorFilterProperties * prop,
   pt_data *data = private_data;
   size_t size;
 
-  g_assert (data);
-  g_assert (input);
-  g_assert (output);
+  assert (data);
+  assert (input);
+  assert (output);
 
-  size = gst_tensor_info_get_size (&data->info);
+  size = get_tensor_data_size (&data->info);
 
-  g_assert (input[0].data != output[0].data);
+  assert (input[0].data != output[0].data);
   memcpy (output[0].data, input[0].data, size);
 
   return 0;
index 1ad1840..a21f1c8 100644 (file)
@@ -14,8 +14,8 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <assert.h>
 #include <tensor_filter_custom.h>
-#include <tensor_common.h>
 
 /**
  * @brief _pt_data
@@ -26,13 +26,33 @@ typedef struct _pt_data
 } pt_data;
 
 /**
+ * @brief get data size of single tensor
+ */
+static size_t
+get_tensor_data_size (const GstTensorInfo * info)
+{
+  size_t data_size = 0;
+  int i;
+
+  if (info != NULL) {
+    data_size = tensor_element_size[info->type];
+
+    for (i = 0; i < NNS_TENSOR_RANK_LIMIT; i++) {
+      data_size *= info->dimension[i];
+    }
+  }
+
+  return data_size;
+}
+
+/**
  * @brief pt_init
  */
 static void *
 pt_init (const GstTensorFilterProperties * prop)
 {
   pt_data *data = (pt_data *) malloc (sizeof (pt_data));
-  g_assert (data);
+  assert (data);
 
   data->id = 0;
   return data;
@@ -45,7 +65,7 @@ static void
 pt_exit (void *private_data, const GstTensorFilterProperties * prop)
 {
   pt_data *data = private_data;
-  g_assert (data);
+  assert (data);
   free (data);
 }
 
@@ -58,8 +78,8 @@ set_inputDim (void *private_data, const GstTensorFilterProperties * prop,
 {
   int i, t;
 
-  g_assert (in_info);
-  g_assert (out_info);
+  assert (in_info);
+  assert (out_info);
 
   out_info->num_tensors = in_info->num_tensors;
 
@@ -85,14 +105,14 @@ pt_invoke (void *private_data, const GstTensorFilterProperties * prop,
   size_t size;
   int t;
 
-  g_assert (data);
-  g_assert (input);
-  g_assert (output);
+  assert (data);
+  assert (input);
+  assert (output);
 
   for (t = 0; t < prop->output_meta.num_tensors; t++) {
-    size = gst_tensor_info_get_size (&prop->output_meta.info[t]);
+    size = get_tensor_data_size (&prop->output_meta.info[t]);
 
-    g_assert (input[t].data != output[t].data);
+    assert (input[t].data != output[t].data);
     memcpy (output[t].data, input[t].data, size);
   }
 
index b060e11..d40ed67 100644 (file)
@@ -24,7 +24,6 @@
 #include <assert.h>
 #include <glib.h>
 #include <tensor_filter_custom.h>
-#include <tensor_common.h>
 
 /**
  * @brief Private data structure
@@ -51,6 +50,26 @@ _strdup (const char *src)
 }
 
 /**
+ * @brief get data size of single tensor
+ */
+static size_t
+get_tensor_data_size (const GstTensorInfo * info)
+{
+  size_t data_size = 0;
+  int i;
+
+  if (info != NULL) {
+    data_size = tensor_element_size[info->type];
+
+    for (i = 0; i < NNS_TENSOR_RANK_LIMIT; i++) {
+      data_size *= info->dimension[i];
+    }
+  }
+
+  return data_size;
+}
+
+/**
  * @brief init callback of tensor_filter custom
  */
 static void *
@@ -148,7 +167,7 @@ pt_allocate_invoke (void *private_data,
 
   /* allocate output data */
   elementsize = tensor_element_size[prop->output_meta.info[0].type];
-  size = gst_tensor_info_get_size (&prop->output_meta.info[0]);
+  size = get_tensor_data_size (&prop->output_meta.info[0]);
 
   output[0].data = malloc (size);