Move enum flag - tensor_format into tensors-info struct.
To pass flexible tensors to filter sub-plugins, we should indicate tensor format in tensors-info struct, not tensors-config.
Internally tensors-config struct is used for caps negotiation.
TODO: need discussion, should we separate format in each tensor info, so that each mem chunk can express its format. (then, nnstreamer will combine memories: static+flexible in gst-buffer.)
Signed-off-by: Jaeyun <jy1210.jung@samsung.com>
flatbuffers::Offset<Tensors> tensors;
std::vector<flatbuffers::Offset<Tensor>> tensor_vector;
Tensor_type tensor_type;
- Tensor_format format = (Tensor_format) config_->format;
+ Tensor_format format = (Tensor_format) config_->info.format;
unsigned int num_tensors = config_->info.num_tensors;
frame_rate fr = frame_rate (config_->rate_n, config_->rate_d);
fr->set_rate_d (pbd_config.rate_d);
tensors.set_format (
- (nnstreamer::protobuf::Tensors::Tensor_format) pbd_config.format);
+ (nnstreamer::protobuf::Tensors::Tensor_format) pbd_config.info.format);
for (unsigned int i = 0; i < num_tensors; ++i) {
nnstreamer::protobuf::Tensor *tensor = tensors.add_tensor ();
tensors.ParseFromArray (in_info.data, in_info.size);
config->info.num_tensors = tensors.num_tensor ();
- config->format = (tensor_format) tensors.format ();
+ config->info.format = (tensor_format) tensors.format ();
fr = tensors.mutable_fr ();
config->rate_n = fr->rate_n ();
config->rate_d = fr->rate_d ();
g_assert (tensors);
config->info.num_tensors = tensors->num_tensor ();
- config->format = (tensor_format) tensors->format ();
+ config->info.format = (tensor_format) tensors->format ();
if (tensors->num_tensor () > NNS_TENSOR_SIZE_LIMIT) {
nns_loge ("The number of tensors is limited to %d", NNS_TENSOR_SIZE_LIMIT);
}
config->rate_n = tensors["rate_n"].AsInt32 ();
config->rate_d = tensors["rate_d"].AsInt32 ();
- config->format = (tensor_format) tensors["format"].AsInt32 ();
+ config->info.format = (tensor_format) tensors["format"].AsInt32 ();
out_buf = gst_buffer_new ();
for (guint i = 0; i < config->info.num_tensors; i++) {
num_tensors = fbd_config.info.num_tensors;
fr = frame_rate (fbd_config.rate_n, fbd_config.rate_d);
- format = (Tensor_format) fbd_config.format;
+ format = (Tensor_format) fbd_config.info.format;
/* Fill the info in tensor and puth to tensor vector */
for (i = 0; i < num_tensors; i++) {
unsigned char *tmp_buf;
fbb.UInt ("num_tensors", num_tensors);
fbb.Int ("rate_n", flxd_config.rate_n);
fbb.Int ("rate_d", flxd_config.rate_d);
- fbb.Int ("format", flxd_config.format);
+ fbb.Int ("format", flxd_config.info.format);
for (i = 0; i < num_tensors; i++) {
gchar *tensor_key = g_strdup_printf ("tensor_%d", i);
gchar *tensor_name = NULL;
tmp.rate_n = config->rate_n;
tmp.rate_d = config->rate_d;
- tmp.format = _NNS_TENSOR_FORMAT_FLEXIBLE;
+ tmp.info.format = _NNS_TENSOR_FORMAT_FLEXIBLE;
buf = gst_tensor_buffer_from_config (buf, &tmp);
/* type and dimension from buffer */
- tmp.format = _NNS_TENSOR_FORMAT_STATIC;
+ tmp.info.format = _NNS_TENSOR_FORMAT_STATIC;
tmp.info.num_tensors = gst_buffer_n_memory (buf);
/* compare data size and append memory */
goto error;
}
self->do_not_append_header =
- (new_config.format == _NNS_TENSOR_FORMAT_FLEXIBLE);
+ (new_config.info.format == _NNS_TENSOR_FORMAT_FLEXIBLE);
frames_in = 1;
frame_size = gst_buffer_get_size (inbuf);
* If output is flexible, dimension should be updated in chain function with buffer size.
*/
if (flexible) {
- config->format = _NNS_TENSOR_FORMAT_FLEXIBLE;
+ config->info.format = _NNS_TENSOR_FORMAT_FLEXIBLE;
config->info.num_tensors = 1;
config->info.info[0].type = _NNS_UINT8;
* Output is always flexible tensor.
*/
gst_tensors_config_init (&config);
- config.format = _NNS_TENSOR_FORMAT_FLEXIBLE;
+ config.info.format = _NNS_TENSOR_FORMAT_FLEXIBLE;
walk = self->collect->data;
while (walk) {
&tensor_demux->tensors_config.info.info[nth]);
}
- config->format = tensor_demux->tensors_config.format;
+ config->info.format = tensor_demux->tensors_config.info.format;
config->rate_n = tensor_demux->tensors_config.rate_n;
config->rate_d = tensor_demux->tensors_config.rate_d;
return TRUE;
if (gst_tensors_config_is_flexible (&in_config)) {
/* output caps is also flexible */
- out_config.format = _NNS_TENSOR_FORMAT_FLEXIBLE;
+ out_config.info.format = _NNS_TENSOR_FORMAT_FLEXIBLE;
} else {
for (j = 0; j < in_config.info.num_tensors; j++) {
gst_tensor_transform_convert_dimension (filter, direction,
/* compare type and dimension */
gst_tensors_config_init (&config);
- config.format = out_config.format;
+ config.info.format = out_config.info.format;
config.rate_n = in_config.rate_n;
config.rate_d = in_config.rate_d;
/**
* @brief Macro to check stream format (static tensors for caps negotiation)
*/
-#define gst_tensors_config_is_static(c) ((c)->format == _NNS_TENSOR_FORMAT_STATIC)
+#define gst_tensors_config_is_static(c) ((c)->info.format == _NNS_TENSOR_FORMAT_STATIC)
/**
* @brief Macro to check stream format (flexible tensors for caps negotiation)
*/
-#define gst_tensors_config_is_flexible(c) ((c)->format == _NNS_TENSOR_FORMAT_FLEXIBLE)
+#define gst_tensors_config_is_flexible(c) ((c)->info.format == _NNS_TENSOR_FORMAT_FLEXIBLE)
/**
* @brief Macro to check stream format (sparse tensors for caps negotiation)
*/
-#define gst_tensors_config_is_sparse(c) ((c)->format == _NNS_TENSOR_FORMAT_SPARSE)
+#define gst_tensors_config_is_sparse(c) ((c)->info.format == _NNS_TENSOR_FORMAT_SPARSE)
/**
* @brief Check the tensor dimension is valid
{
unsigned int num_tensors; /**< The number of tensors */
GstTensorInfo info[NNS_TENSOR_SIZE_LIMIT]; /**< The list of tensor info */
+ tensor_format format; /**< tensor stream type */
} GstTensorsInfo;
/**
typedef struct
{
GstTensorsInfo info; /**< tensor info*/
- tensor_format format; /**< tensor stream type */
int rate_n; /**< framerate is in fraction, which is numerator/denominator */
int rate_d; /**< framerate is in fraction, which is numerator/denominator */
} GstTensorsConfig;
g_assert ((counting + n_mem) < NNS_TENSOR_SIZE_LIMIT);
if (gst_tensors_config_is_flexible (&in_configs))
- configs->format = _NNS_TENSOR_FORMAT_FLEXIBLE;
+ configs->info.format = _NNS_TENSOR_FORMAT_FLEXIBLE;
for (i = 0; i < n_mem; ++i) {
in_mem[counting] = gst_buffer_get_memory (buf, i);
configs->info.info[counting] = in_configs.info.info[i];
- in_formats[counting] = in_configs.format;
+ in_formats[counting] = in_configs.info.format;
counting++;
}
("Invalid format %s, it should be one of %s. Suppose tensor format is static.",
_STR_NULL (format_str), GST_TENSOR_FORMAT_ALL);
} else {
- config->format = format;
+ config->info.format = format;
}
}
- if (config->format == _NNS_TENSOR_FORMAT_STATIC) {
+ if (config->info.format == _NNS_TENSOR_FORMAT_STATIC) {
gst_structure_get_int (structure, "num_tensors",
(gint *) (&config->info.num_tensors));
g_return_if_fail (info != NULL);
info->num_tensors = 0;
+ /** @note default format is static */
+ info->format = _NNS_TENSOR_FORMAT_STATIC;
for (i = 0; i < NNS_TENSOR_SIZE_LIMIT; i++) {
gst_tensor_info_init (&info->info[i]);
g_return_val_if_fail (info != NULL, FALSE);
+ /* tensor stream format */
+ if (info->format >= _NNS_TENSOR_FORMAT_END) {
+ nns_logd
+ ("Failed to validate tensors info, format: %s. format should be one of %s.",
+ _STR_NULL (gst_tensor_get_format_string (info->format)),
+ GST_TENSOR_FORMAT_ALL);
+ _nnstreamer_error_write
+ ("Failed to validate tensors info, format: %s. format should be one of %s.",
+ _STR_NULL (gst_tensor_get_format_string (info->format)),
+ GST_TENSOR_FORMAT_ALL);
+ return FALSE;
+ }
+
+ /* cannot check tensor info when tensor is not static */
+ if (info->format != _NNS_TENSOR_FORMAT_STATIC) {
+ return TRUE;
+ }
+
if (info->num_tensors < 1) {
nns_logd
("Failed to validate tensors info. the number of tensors: %d. the number of tensors should be greater than 0.",
g_return_val_if_fail (i1 != NULL, FALSE);
g_return_val_if_fail (i2 != NULL, FALSE);
+ if (i1->format != i2->format || i1->format == _NNS_TENSOR_FORMAT_END) {
+ nns_logd ("Tensors info is not equal. format: %s vs %s ",
+ _STR_NULL (gst_tensor_get_format_string (i1->format)),
+ _STR_NULL (gst_tensor_get_format_string (i2->format)));
+ return FALSE;
+ }
+
+ /* cannot compare tensor info when tensor is not static */
+ if (i1->format != _NNS_TENSOR_FORMAT_STATIC) {
+ return TRUE;
+ }
+
if (!gst_tensors_info_validate (i1) || !gst_tensors_info_validate (i2)) {
return FALSE;
}
gst_tensors_info_init (dest);
num = dest->num_tensors = src->num_tensors;
+ dest->format = src->format;
for (i = 0; i < num; i++) {
gst_tensor_info_copy (&dest->info[i], &src->info[i]);
gst_tensors_info_init (&config->info);
- /** @note default format is static */
- config->format = _NNS_TENSOR_FORMAT_STATIC;
config->rate_n = -1;
config->rate_d = -1;
}
return FALSE;
}
- /* tensor stream format */
- if (config->format >= _NNS_TENSOR_FORMAT_END) {
- nns_logd
- ("Failed to validate tensors config. format: %s. format should be one of %s.",
- _STR_NULL (gst_tensor_get_format_string (config->format)),
- GST_TENSOR_FORMAT_ALL);
- _nnstreamer_error_write
- ("Failed to validate tensors config. format: %s. format should be one of %s.",
- _STR_NULL (gst_tensor_get_format_string (config->format)),
- GST_TENSOR_FORMAT_ALL);
- return FALSE;
- }
-
- /* cannot check tensor info when tensor is not static */
- if (!gst_tensors_config_is_static (config)) {
- return TRUE;
- }
-
return gst_tensors_info_validate (&config->info);
}
return FALSE;
}
- if (c1->format != c2->format || c1->format == _NNS_TENSOR_FORMAT_END) {
- nns_logd ("Tensors config is not equal. format: %s vs %s ",
- _STR_NULL (gst_tensor_get_format_string (c1->format)),
- _STR_NULL (gst_tensor_get_format_string (c2->format)));
- return FALSE;
- }
-
- /* cannot compare tensor info when tensor is not static */
- if (!gst_tensors_config_is_static (c1)) {
- return TRUE;
- }
-
return gst_tensors_info_is_equal (&c1->info, &c2->info);
}
g_return_if_fail (src != NULL);
gst_tensors_info_copy (&dest->info, &src->info);
- dest->format = src->format;
dest->rate_n = src->rate_n;
dest->rate_d = src->rate_d;
}
gst_tensors_config_to_string (const GstTensorsConfig * config)
{
GString *gstr = g_string_new (NULL);
- const gchar *fmt = gst_tensor_get_format_string (config->format);
+ const gchar *fmt = gst_tensor_get_format_string (config->info.format);
g_string_append_printf (gstr, "Format = %s, Framerate = %d/%d",
fmt, config->rate_n, config->rate_d);
- if (config->format == _NNS_TENSOR_FORMAT_STATIC) {
+ if (config->info.format == _NNS_TENSOR_FORMAT_STATIC) {
gchar *infostr = gst_tensors_info_to_string (&config->info);
g_string_append_printf (gstr, ", %s", infostr);
g_free (infostr);
}
combined->num_tensors = idx;
+ combined->format = out->format;
} else {
gst_tensors_info_copy (combined, out);
}
fill_tensors_config_for_test (&conf1, &conf2);
/* compare flexible tensor */
- conf1.format = conf2.format = _NNS_TENSOR_FORMAT_FLEXIBLE;
+ conf1.info.format = conf2.info.format = _NNS_TENSOR_FORMAT_FLEXIBLE;
EXPECT_TRUE (gst_tensors_config_is_equal (&conf1, &conf2));
}
fill_tensors_config_for_test (&conf1, &conf2);
/* change format, this should not be compatible */
- conf2.format = _NNS_TENSOR_FORMAT_FLEXIBLE;
+ conf2.info.format = _NNS_TENSOR_FORMAT_FLEXIBLE;
EXPECT_FALSE (gst_tensors_config_is_equal (&conf1, &conf2));
}
gsize data_size;
gst_tensors_config_init (&config);
- config.format = _NNS_TENSOR_FORMAT_STATIC;
+ config.info.format = _NNS_TENSOR_FORMAT_STATIC;
config.rate_n = config.rate_d = 1;
config.info.num_tensors = 3U;
gst_tensors_info_parse_dimensions_string (&config.info, "20,40,50");
gsize data_size, offset, hsize[3], dsize[3];
gst_tensors_config_init (&config);
- config.format = _NNS_TENSOR_FORMAT_FLEXIBLE;
+ config.info.format = _NNS_TENSOR_FORMAT_FLEXIBLE;
config.rate_n = config.rate_d = 1;
config.info.num_tensors = 3U;
gst_tensors_info_parse_dimensions_string (&config.info, "20,30,40");
gsize data_size;
gst_tensors_config_init (&config);
- config.format = _NNS_TENSOR_FORMAT_STATIC;
+ config.info.format = _NNS_TENSOR_FORMAT_STATIC;
config.rate_n = config.rate_d = 1;
config.info.num_tensors = 3U;
gst_tensors_info_parse_dimensions_string (&config.info, "20,40,50");
gsize data_size;
gst_tensors_config_init (&config);
- config.format = _NNS_TENSOR_FORMAT_STATIC;
+ config.info.format = _NNS_TENSOR_FORMAT_STATIC;
config.rate_n = config.rate_d = 1;
config.info.num_tensors = 3U;
gst_tensors_info_parse_dimensions_string (&config.info, "20,40,50");
fbb.UInt ("num_tensors", num_tensors);
fbb.Int ("rate_n", config->rate_n);
fbb.Int ("rate_d", config->rate_d);
- fbb.Int ("format", config->format);
+ fbb.Int ("format", config->info.format);
for (i = 0; i < num_tensors; i++) {
gchar *tensor_key = g_strdup_printf ("tensor_%d", i);
gchar *tensor_name = NULL;
gst_tensors_config_init (&config);
config.info.num_tensors = 1;
config.info.info[0] = crop_test->raw_info;
- config.format = crop_test->raw_format;
+ config.info.format = crop_test->raw_format;
config.rate_n = 0;
config.rate_d = 1;