From: Jaeyun Date: Mon, 8 Oct 2018 04:18:18 +0000 (+0900) Subject: [Aggregator] fix out-tensor dimension X-Git-Tag: v0.0.2~33 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7a0961840e3a2c169983269deec0220a4e3b6228;p=platform%2Fupstream%2Fnnstreamer.git [Aggregator] fix out-tensor dimension update output dimension with the properties frames-dim, frames-out. Signed-off-by: Jaeyun Jung --- diff --git a/gst/tensor_aggregator/README.md b/gst/tensor_aggregator/README.md index f4b552d..61ceef9 100644 --- a/gst/tensor_aggregator/README.md +++ b/gst/tensor_aggregator/README.md @@ -60,12 +60,12 @@ It does not support ```other/tensors``` because each frame (or a set of frames c GstTensorAggregator flushes the bytes (```frames-flush``` frames) in GstAdapter after pushing a buffer. If set 0 (default value), all outgoing frames will be flushed. -- frames-dim: The dimension index of frames in tensor. (Default -1) +- frames-dim: The dimension index of frames in tensor. (Default value is (NNS_TENSOR_RANK_LIMIT - 1)) If frames-in and frames-out are different, GstTensorAggregator has to change the dimension of tensor. With this property, GstTensorAggregator changes the out-caps. - If set -1 (default value), GstTensorAggregator does not change the dimension in outgoing tensor. (This may cause an error if in/out frames are different.) + If set this value in 0 ~ (NNS_TENSOR_RANK_LIMIT - 2), GstTensorAggregator will concatenate the output buffer. ### Properties for debugging diff --git a/gst/tensor_aggregator/tensor_aggregator.c b/gst/tensor_aggregator/tensor_aggregator.c index 1978a34..6f32ddf 100644 --- a/gst/tensor_aggregator/tensor_aggregator.c +++ b/gst/tensor_aggregator/tensor_aggregator.c @@ -102,7 +102,7 @@ enum /** * @brief The dimension index of frames in configured tensor. */ -#define DEFAULT_FRAMES_DIMENSION (-1) +#define DEFAULT_FRAMES_DIMENSION (NNS_TENSOR_RANK_LIMIT - 1) /** * @brief Template for sink pad. @@ -204,13 +204,11 @@ gst_tensor_aggregator_class_init (GstTensorAggregatorClass * klass) * The dimension index of frames in tensor. * If frames-in and frames-out are different, GstTensorAggregator has to change the dimension of tensor. * With this property, GstTensorAggregator changes the out-caps. - * If set -1 (default value), GstTensorAggregator does not change the dimension in outgoing tensor. - * (This may cause an error if in/out frames are different.) */ g_object_class_install_property (object_class, PROP_FRAMES_DIMENSION, - g_param_spec_int ("frames-dim", "Dimension index of frames", + g_param_spec_uint ("frames-dim", "Dimension index of frames", "The dimension index of frames in tensor", - -1, (NNS_TENSOR_RANK_LIMIT - 1), DEFAULT_FRAMES_DIMENSION, + 0, (NNS_TENSOR_RANK_LIMIT - 1), DEFAULT_FRAMES_DIMENSION, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); /** @@ -312,7 +310,7 @@ gst_tensor_aggregator_set_property (GObject * object, guint prop_id, self->frames_flush = g_value_get_uint (value); break; case PROP_FRAMES_DIMENSION: - self->frames_dim = g_value_get_int (value); + self->frames_dim = g_value_get_uint (value); break; case PROP_SILENT: self->silent = g_value_get_boolean (value); @@ -345,7 +343,7 @@ gst_tensor_aggregator_get_property (GObject * object, guint prop_id, g_value_set_uint (value, self->frames_flush); break; case PROP_FRAMES_DIMENSION: - g_value_set_int (value, self->frames_dim); + g_value_set_uint (value, self->frames_dim); break; case PROP_SILENT: g_value_set_boolean (value, self->silent); @@ -670,6 +668,7 @@ gst_tensor_aggregator_parse_caps (GstTensorAggregator * self, { GstStructure *structure; GstTensorConfig config; + uint32_t per_frame; g_return_val_if_fail (caps != NULL, FALSE); g_return_val_if_fail (gst_caps_is_fixed (caps), FALSE); @@ -688,10 +687,17 @@ gst_tensor_aggregator_parse_caps (GstTensorAggregator * self, self->in_config = config; - /** update dimension in output tensor */ - if (self->frames_dim >= 0) { - config.info.dimension[self->frames_dim] = self->frames_out; - } + /** + * update dimension in output tensor. + * e.g, in-dimension 2:200:200:1 + * if frames_out=10 and frames_dim=3, then out-dimension is 2:200:200:10. + * if frames_out=10 and frames_dim=2, then out-dimension is 2:200:2000:1. + */ + g_assert (self->frames_dim < NNS_TENSOR_RANK_LIMIT); + g_assert ((config.info.dimension[self->frames_dim] % self->frames_in) == 0); + per_frame = config.info.dimension[self->frames_dim] / self->frames_in; + + config.info.dimension[self->frames_dim] = per_frame * self->frames_out; self->out_config = config; self->tensor_configured = TRUE; diff --git a/gst/tensor_aggregator/tensor_aggregator.h b/gst/tensor_aggregator/tensor_aggregator.h index 4247470..7affbdc 100644 --- a/gst/tensor_aggregator/tensor_aggregator.h +++ b/gst/tensor_aggregator/tensor_aggregator.h @@ -61,7 +61,7 @@ struct _GstTensorAggregator guint frames_in; /**< number of frames in input buffer */ guint frames_out; /**< number of frames in output buffer */ guint frames_flush; /**< number of frames to flush */ - gint frames_dim; /**< index of frames in tensor dimension */ + guint frames_dim; /**< index of frames in tensor dimension */ GstAdapter *adapter; /**< adapt incoming tensor */