From: jinhyuck-park Date: Mon, 17 Sep 2018 22:46:30 +0000 (+0900) Subject: [TensorDec]Add set label path property X-Git-Tag: v0.0.2~92 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=641c4300c9c68493fe4cc536882413b0d275eef0;p=platform%2Fupstream%2Fnnstreamer.git [TensorDec]Add set label path property add set label path property and set label infos in tensor decoder Signed-off-by: jinhyuck-park --- diff --git a/gst/tensor_decoder/tensordec.c b/gst/tensor_decoder/tensordec.c index 6da1926..6fcb23d 100644 --- a/gst/tensor_decoder/tensordec.c +++ b/gst/tensor_decoder/tensordec.c @@ -40,12 +40,17 @@ * */ +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + #ifdef HAVE_CONFIG_H #include #endif - +#include #include #include +#include #include "tensordec.h" /** @@ -156,17 +161,55 @@ static gboolean gst_tensordec_transform_size (GstBaseTransform * trans, * @brief initialize data in tensor decoder image labeling info structure. */ static void -gst_tensordec_image_labeling_init (TensorDec_Mode_image_Label * - mode_image_label) +gst_tensordec_image_labeling_init (TensorDec_Image_Label * mode_image_label) { - mode_image_label->image_labeling_info.label_path = NULL; - mode_image_label->image_labeling_info.labels = NULL; - mode_image_label->image_labeling_info.total_labels = 0; + mode_image_label->labeling_info.label_path = NULL; + mode_image_label->labeling_info.labels = NULL; + mode_image_label->labeling_info.total_labels = 0; mode_image_label->current_label_index = 0; mode_image_label->new_label_index = 0; } /** + * @brief set label info data for Tensor decoder. + */ +static gboolean +gst_set_mode_image_label_info (GstTensorDec * self) +{ + FILE *fp; + + if ((fp = + fopen (self->tensordec_image_label.labeling_info.label_path, + "r")) != NULL) { + char *line = NULL; + size_t len = 0; + ssize_t read; + gchar *label; + + while ((read = getline (&line, &len, fp)) != -1) { + label = g_strdup ((gchar *) line); + self->tensordec_image_label.labeling_info.labels = + g_list_append (self->tensordec_image_label.labeling_info.labels, + label); + } + + if (line) { + free (line); + } + + fclose (fp); + } else { + err_print ("cannot find label file in tensor decoder"); + return FALSE; + } + + self->tensordec_image_label.labeling_info.total_labels = + g_list_length (self->tensordec_image_label.labeling_info.labels); + err_print ("finished to load labels"); + return TRUE; +} + +/** * @brief Get video caps from tensor config * @param self "this" pointer * @param config tensor config info @@ -446,7 +489,7 @@ gst_tensordec_init (GstTensorDec * self) self->output_type = OUTPUT_VIDEO; self->mode = Mode[0]; gst_tensor_config_init (&self->tensor_config); - gst_tensordec_image_labeling_init (&self->tensordec_mode_image_label); + gst_tensordec_image_labeling_init (&self->tensordec_image_label); } /** @@ -468,6 +511,13 @@ gst_tensordec_set_property (GObject * object, guint prop_id, case PROP_MODE: self->mode = g_value_dup_string (value); break; + case PROP_MODE_OPTION1: + if (g_strcmp0 (self->mode, "image_labeling") == 0) { + self->tensordec_image_label.labeling_info.label_path = + g_value_dup_string (value); + gst_set_mode_image_label_info (self); + } + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -491,6 +541,11 @@ gst_tensordec_get_property (GObject * object, guint prop_id, g_value_set_boolean (value, self->silent); break; case PROP_MODE: + g_value_set_string (value, self->mode); + break; + case PROP_MODE_OPTION1: + g_value_set_string (value, + self->tensordec_image_label.labeling_info.label_path); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); diff --git a/gst/tensor_decoder/tensordec.h b/gst/tensor_decoder/tensordec.h index 05265d9..0b262b9 100644 --- a/gst/tensor_decoder/tensordec.h +++ b/gst/tensor_decoder/tensordec.h @@ -66,8 +66,8 @@ typedef struct { gint current_label_index; /**< current label index */ gint new_label_index; /**< new label index */ - Mode_image_labeling image_labeling_info; /**< tflite image labeling mode info */ -} TensorDec_Mode_image_Label; + Mode_image_labeling labeling_info; /**< tflite image labeling mode info */ +} TensorDec_Image_Label; /** * @brief Internal data structure for tensordec instances. @@ -86,7 +86,7 @@ struct _GstTensorDec /** For Tensor */ gboolean configured; /**< TRUE if already successfully configured tensor metadata */ GstTensorConfig tensor_config; /**< configured tensor info */ - TensorDec_Mode_image_Label tensordec_mode_image_label;/** tensor decoder image labeling mode info */ + TensorDec_Image_Label tensordec_image_label;/** tensor decoder image labeling mode info */ }; /**