From a154f9b8a579d3ed8cf2a65f4fcb35a8507d3916 Mon Sep 17 00:00:00 2001 From: Jaeyun Date: Wed, 12 Dec 2018 12:57:27 +0900 Subject: [PATCH] [Example] remove common header In custom filter examples, remove tensor-common header. Signed-off-by: Jaeyun Jung --- .../custom_example_LSTM/dummy_LSTM.c | 1 - nnstreamer_example/custom_example_RNN/dummy_RNN.c | 2 - .../nnstreamer_customfilter_opencv_average.cc | 31 +++++++++++--- .../nnstreamer_customfilter_opencv_scaler.cc | 48 +++++++++++++++------- .../nnstreamer_customfilter_example_passthrough.c | 42 ++++++++++++++----- ...mer_customfilter_example_passthrough_variable.c | 40 +++++++++++++----- ...treamer_customfilter_example_scaler_allocator.c | 23 ++++++++++- 7 files changed, 140 insertions(+), 47 deletions(-) diff --git a/nnstreamer_example/custom_example_LSTM/dummy_LSTM.c b/nnstreamer_example/custom_example_LSTM/dummy_LSTM.c index 79b0840..d9b5532 100644 --- a/nnstreamer_example/custom_example_LSTM/dummy_LSTM.c +++ b/nnstreamer_example/custom_example_LSTM/dummy_LSTM.c @@ -20,7 +20,6 @@ #include #include #include -#include #define TSIZE (4) diff --git a/nnstreamer_example/custom_example_RNN/dummy_RNN.c b/nnstreamer_example/custom_example_RNN/dummy_RNN.c index efd87b7..17af112 100644 --- a/nnstreamer_example/custom_example_RNN/dummy_RNN.c +++ b/nnstreamer_example/custom_example_RNN/dummy_RNN.c @@ -19,8 +19,6 @@ #include #include #include -/* To use nnstreamer utilities (not mandatory for custom filters */ -#include #define TSIZE (4) diff --git a/nnstreamer_example/custom_example_opencv/nnstreamer_customfilter_opencv_average.cc b/nnstreamer_example/custom_example_opencv/nnstreamer_customfilter_opencv_average.cc index 18ba2ba..79f9d26 100644 --- a/nnstreamer_example/custom_example_opencv/nnstreamer_customfilter_opencv_average.cc +++ b/nnstreamer_example/custom_example_opencv/nnstreamer_customfilter_opencv_average.cc @@ -10,17 +10,16 @@ * @author Sangjung Woo * @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 #include #include -#include /** * @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 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 */ diff --git a/nnstreamer_example/custom_example_opencv/nnstreamer_customfilter_opencv_scaler.cc b/nnstreamer_example/custom_example_opencv/nnstreamer_customfilter_opencv_scaler.cc index 90a06b3..98000cc 100644 --- a/nnstreamer_example/custom_example_opencv/nnstreamer_customfilter_opencv_scaler.cc +++ b/nnstreamer_example/custom_example_opencv/nnstreamer_customfilter_opencv_scaler.cc @@ -1,6 +1,6 @@ /** * NNStreamer OpenCV Custom Filter Example: Scaler - * + * * Copyright (C) 2018 Sangjung Woo * * LICENSE: LGPL-2.1 @@ -11,8 +11,8 @@ * @author Sangjung Woo * @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. @@ -23,10 +23,8 @@ #include "opencv2/opencv.hpp" #include "opencv2/highgui/highgui.hpp" -#include #include #include -#include /** * @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 (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 (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 */ diff --git a/nnstreamer_example/custom_example_passthrough/nnstreamer_customfilter_example_passthrough.c b/nnstreamer_example/custom_example_passthrough/nnstreamer_customfilter_example_passthrough.c index 9ba4819..dfa2df9 100644 --- a/nnstreamer_example/custom_example_passthrough/nnstreamer_customfilter_example_passthrough.c +++ b/nnstreamer_example/custom_example_passthrough/nnstreamer_customfilter_example_passthrough.c @@ -16,8 +16,8 @@ #include #include #include +#include #include -#include #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; diff --git a/nnstreamer_example/custom_example_passthrough/nnstreamer_customfilter_example_passthrough_variable.c b/nnstreamer_example/custom_example_passthrough/nnstreamer_customfilter_example_passthrough_variable.c index 1ad1840..a21f1c8 100644 --- a/nnstreamer_example/custom_example_passthrough/nnstreamer_customfilter_example_passthrough_variable.c +++ b/nnstreamer_example/custom_example_passthrough/nnstreamer_customfilter_example_passthrough_variable.c @@ -14,8 +14,8 @@ #include #include #include +#include #include -#include /** * @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); } diff --git a/nnstreamer_example/custom_example_scaler/nnstreamer_customfilter_example_scaler_allocator.c b/nnstreamer_example/custom_example_scaler/nnstreamer_customfilter_example_scaler_allocator.c index b060e11..d40ed67 100644 --- a/nnstreamer_example/custom_example_scaler/nnstreamer_customfilter_example_scaler_allocator.c +++ b/nnstreamer_example/custom_example_scaler/nnstreamer_customfilter_example_scaler_allocator.c @@ -24,7 +24,6 @@ #include #include #include -#include /** * @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); -- 2.7.4