This PR changes caps format for other/tensor.
Caps for tensor stream : other/tensor, framerate = (fraction) [0, max], type = (string) { uint8, .. }, dimension = (string) d1:d2:d3:d4
Related issue : #1027
Signed-off-by: Jaeyun Jung <jy1210.jung@samsung.com>
gboolean
gst_tensor_info_validate (const GstTensorInfo * info)
{
- guint i;
-
g_return_val_if_fail (info != NULL, FALSE);
if (info->type == _NNS_END) {
return FALSE;
}
- for (i = 0; i < NNS_TENSOR_RANK_LIMIT; i++) {
- if (info->dimension[i] == 0) {
- return FALSE;
- }
- }
-
- return TRUE;
+ /* validate tensor dimension */
+ return gst_tensor_dimension_is_valid (info->dimension);
}
/**
const GstStructure * structure)
{
GstTensorInfo *info;
- const gchar *type_string;
g_return_val_if_fail (config != NULL, FALSE);
gst_tensor_config_init (config);
return FALSE;
}
- gst_structure_get_int (structure, "dim1", (gint *) (&info->dimension[0]));
- gst_structure_get_int (structure, "dim2", (gint *) (&info->dimension[1]));
- gst_structure_get_int (structure, "dim3", (gint *) (&info->dimension[2]));
- gst_structure_get_int (structure, "dim4", (gint *) (&info->dimension[3]));
+ if (gst_structure_has_field (structure, "dimension")) {
+ const gchar *dim_str = gst_structure_get_string (structure, "dimension");
+ get_tensor_dimension (dim_str, info->dimension);
+ }
- type_string = gst_structure_get_string (structure, "type");
- info->type = get_tensor_type (type_string);
+ if (gst_structure_has_field (structure, "type")) {
+ const gchar *type_str = gst_structure_get_string (structure, "type");
+ info->type = get_tensor_type (type_str);
+ }
gst_structure_get_fraction (structure, "framerate", &config->rate_n,
&config->rate_d);
caps = gst_caps_from_string (GST_TENSOR_CAP_DEFAULT);
- if (config->info.dimension[0] > 0) {
- gst_caps_set_simple (caps, "dim1", G_TYPE_INT, config->info.dimension[0],
- NULL);
- }
-
- if (config->info.dimension[1] > 0) {
- gst_caps_set_simple (caps, "dim2", G_TYPE_INT, config->info.dimension[1],
- NULL);
- }
-
- if (config->info.dimension[2] > 0) {
- gst_caps_set_simple (caps, "dim3", G_TYPE_INT, config->info.dimension[2],
- NULL);
- }
+ if (gst_tensor_dimension_is_valid (config->info.dimension)) {
+ gchar *dim_str = get_tensor_dimension_string (config->info.dimension);
- if (config->info.dimension[3] > 0) {
- gst_caps_set_simple (caps, "dim4", G_TYPE_INT, config->info.dimension[3],
- NULL);
+ gst_caps_set_simple (caps, "dimension", G_TYPE_STRING, dim_str, NULL);
+ g_free (dim_str);
}
if (config->info.type != _NNS_END) {
config->rate_d = c.rate_d;
config->rate_n = c.rate_n;
} else if (g_str_equal (name, "other/tensors")) {
- const gchar *dims_string;
- const gchar *types_string;
-
gst_structure_get_int (structure, "num_tensors",
(gint *) (&config->info.num_tensors));
gst_structure_get_fraction (structure, "framerate", &config->rate_n,
}
/* parse dimensions */
- dims_string = gst_structure_get_string (structure, "dimensions");
- if (dims_string) {
+ if (gst_structure_has_field (structure, "dimensions")) {
+ const gchar *dims_str;
guint num_dims;
+ dims_str = gst_structure_get_string (structure, "dimensions");
num_dims =
- gst_tensors_info_parse_dimensions_string (&config->info, dims_string);
+ gst_tensors_info_parse_dimensions_string (&config->info, dims_str);
if (config->info.num_tensors != num_dims) {
GST_WARNING ("Invalid param, dimensions (%d) tensors (%d)\n",
}
/* parse types */
- types_string = gst_structure_get_string (structure, "types");
- if (types_string) {
+ if (gst_structure_has_field (structure, "types")) {
+ const gchar *types_str;
guint num_types;
+ types_str = gst_structure_get_string (structure, "types");
num_types =
- gst_tensors_info_parse_types_string (&config->info, types_string);
+ gst_tensors_info_parse_types_string (&config->info, types_str);
if (config->info.num_tensors != num_types) {
GST_WARNING ("Invalid param, types (%d) tensors (%d)\n",
}
/**
+ * @brief Check the tensor dimension is valid
+ * @param dim tensor dimension
+ * @return TRUE if dimension is valid
+ */
+gboolean
+gst_tensor_dimension_is_valid (const tensor_dim dim)
+{
+ guint i;
+
+ for (i = 0; i < NNS_TENSOR_RANK_LIMIT; ++i) {
+ if (dim[i] == 0) {
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+
+/**
* @brief Parse tensor dimension parameter string
* @return The Rank. 0 if error.
* @param dimstr The dimension string in the format of d1:d2:d3:d4, d1:d2:d3, d1:d2, or d1, where dN is a positive integer and d1 is the innermost dimension; i.e., dim[d4][d3][d2][d1];
GST_TENSOR_TEXT_CAPS_STR "; " \
GST_TENSOR_OCTET_CAPS_STR
-/** @todo I'm not sure if the range is to be 1, 65535 or larger */
-#define GST_TENSOR_DIM_RANGE "(int) [ 1, 65535 ]"
-#define GST_TENSOR_RATE_RANGE "(fraction) [ 0/1, 2147483647/1 ]"
+#define GST_TENSOR_RATE_RANGE "(fraction) [ 0, max ]"
#define GST_TENSOR_TYPE_ALL "{ float32, float64, int64, uint64, int32, uint32, int16, uint16, int8, uint8 }"
#define GST_TENSOR_CAP_DEFAULT \
"other/tensor, " \
- "dim1 = " GST_TENSOR_DIM_RANGE ", " \
- "dim2 = " GST_TENSOR_DIM_RANGE ", " \
- "dim3 = " GST_TENSOR_DIM_RANGE ", " \
- "dim4 = " GST_TENSOR_DIM_RANGE ", " \
- "type = (string) " GST_TENSOR_TYPE_ALL ", " \
"framerate = " GST_TENSOR_RATE_RANGE
-
+ /**
+ * type should be one of types in GST_TENSOR_TYPE_ALL
+ * "type = (string) uint8"
+ * dimension shoule be a formatted string with rank NNS_TENSOR_RANK_LIMIT
+ * "dimension = (string) dim1:dim2:dim3:dim4"
+ */
/**
* @brief This value, 16, can be checked with gst_buffer_get_max_memory(),
extern int find_key_strv (const gchar ** strv, const gchar * key);
/**
+ * @brief Check the tensor dimension is valid
+ * @param dim tensor dimension
+ * @return TRUE if dimension is valid
+ */
+extern gboolean
+gst_tensor_dimension_is_valid (const tensor_dim dim);
+
+/**
* @brief Parse tensor dimension parameter string
* @return The Rank. 0 if error.
* @param dimstr The dimension string in the format of d1:d2:d3:d4, d1:d2:d3, d1:d2, or d1, where dN is a positive integer and d1 is the innermost dimension; i.e., dim[d4][d3][d2][d1];
convertBMP2PNG
# Fail Test : Negotiation Error (dimension)
-gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} multifilesrc location=testsequence_%1d.png index=0 caps=\"image/png, framerate=30/1\" ! pngdec ! tensor_converter ! tensor_reposink silent=false slot-index=0 tensor_reposrc silent=false slot-index=0 caps=\"other/tensor, dim1=3, dim2=100, dim3=100, dim4=1, type=uint8, framerate=30/1\" ! multifilesink location=testsequence01_%1d.log" F0 0 1 $PERFORMANCE
+gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} multifilesrc location=testsequence_%1d.png index=0 caps=\"image/png,framerate=(fraction)30/1\" ! pngdec ! tensor_converter ! tensor_reposink silent=false slot-index=0 tensor_reposrc silent=false slot-index=0 caps=\"other/tensor,dimension=(string)3:100:100:1,type=(string)uint8,framerate=(fraction)30/1\" ! multifilesink location=testsequence01_%1d.log" F0 0 1 $PERFORMANCE
# Fail Test : Negotiation Error (type)
-gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} multifilesrc location=testsequence_%1d.png index=0 caps=\"image/png, framerate=30/1\" ! pngdec ! tensor_converter ! tensor_reposink silent=false slot-index=0 tensor_reposrc silent=false slot-index=0 caps=\"other/tensor, dim1=3, dim2=16, dim3=16, dim4=1, type=float32, framerate=30/1\" ! multifilesink location=testsequence01_%1d.log" F1 0 1 $PERFORMANCE
+gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} multifilesrc location=testsequence_%1d.png index=0 caps=\"image/png,framerate=(fraction)30/1\" ! pngdec ! tensor_converter ! tensor_reposink silent=false slot-index=0 tensor_reposrc silent=false slot-index=0 caps=\"other/tensor,dimension=(string)3:16:16:1,type=(string)float32,framerate=(fraction)30/1\" ! multifilesink location=testsequence01_%1d.log" F1 0 1 $PERFORMANCE
# Fail Test : Negotiation Error (MimeType)
-gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} multifilesrc location=testsequence_%1d.png index=0 caps=\"image/png, framerate=30/1\" ! pngdec ! tensor_converter ! tensor_reposink silent=false slot-index=0 tensor_reposrc silent=false slot-index=0 caps=\"other/tensors, num_tensors=1, framerate=30/1, types=uint8, dimensions=3:16:16:1\" ! multifilesink location=testsequence01_%1d.log" F2 0 1 $PERFORMANCE
+gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} multifilesrc location=testsequence_%1d.png index=0 caps=\"image/png,framerate=(fraction)30/1\" ! pngdec ! tensor_converter ! tensor_reposink silent=false slot-index=0 tensor_reposrc silent=false slot-index=0 caps=\"other/tensors,num_tensors=1,framerate=(fraction)30/1,types=(string)uint8,dimensions=(string)3:16:16:1\" ! multifilesink location=testsequence01_%1d.log" F2 0 1 $PERFORMANCE
# The first gst buffer at tensor_reposrc is dummy.
-gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} multifilesrc location=testsequence_%1d.png index=0 caps=\"image/png, framerate=30/1\" ! pngdec ! tensor_converter ! tensor_reposink silent=false slot-index=0 tensor_reposrc silent=false slot-index=0 caps=\"other/tensor, dim1=3, dim2=16, dim3=16, dim4=1, type=uint8, framerate=30/1\" ! multifilesink location=testsequence01_%1d.log" 1 0 0 $PERFORMANCE
+gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} multifilesrc location=testsequence_%1d.png index=0 caps=\"image/png,framerate=(fraction)30/1\" ! pngdec ! tensor_converter ! tensor_reposink silent=false slot-index=0 tensor_reposrc silent=false slot-index=0 caps=\"other/tensor,dimension=(string)3:16:16:1,type=(string)uint8,framerate=(fraction)30/1\" ! multifilesink location=testsequence01_%1d.log" 1 0 0 $PERFORMANCE
callCompareTest testsequence_1.golden testsequence01_1.log 1-1 "Compare 1-1" 1 0
callCompareTest testsequence_2.golden testsequence01_2.log 1-2 "Compare 1-2" 1 0
callCompareTest testsequence_9.golden testsequence01_9.log 1-9 "Compare 1-9" 1 0
callCompareTest testsequence_10.golden testsequence01_10.log 1-10 "Compare 1-10" 1 0
-gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} multifilesrc location=testsequence_%1d.png index=0 caps=\"image/png, framerate=30/1\" ! pngdec ! tensor_converter ! tensor_reposink silent=false slot-index=0 tensor_reposrc silent=false slot-index=0 caps=\"other/tensor, dim1=3, dim2=16, dim3=16, dim4=1, type=uint8, framerate=30/1\" ! multifilesink location=testsequence02_0_%1d.log multifilesrc location=testsequence_%1d.png index=0 caps=\"image/png, framerate=30/1\" ! pngdec ! tensor_converter ! tensor_reposink silent=false slot-index=1 tensor_reposrc silent=false slot-index=1 caps=\"other/tensor, dim1=3, dim2=16, dim3=16, dim4=1, type=uint8, framerate=30/1\" ! multifilesink location=testsequence02_1_%1d.log" 2 0 0 $PERFORMANCE
+gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} multifilesrc location=testsequence_%1d.png index=0 caps=\"image/png,framerate=(fraction)30/1\" ! pngdec ! tensor_converter ! tensor_reposink silent=false slot-index=0 tensor_reposrc silent=false slot-index=0 caps=\"other/tensor,dimension=(string)3:16:16:1,type=(string)uint8,framerate=(fraction)30/1\" ! multifilesink location=testsequence02_0_%1d.log multifilesrc location=testsequence_%1d.png index=0 caps=\"image/png,framerate=(fraction)30/1\" ! pngdec ! tensor_converter ! tensor_reposink silent=false slot-index=1 tensor_reposrc silent=false slot-index=1 caps=\"other/tensor,dimension=(string)3:16:16:1,type=(string)uint8,framerate=(fraction)30/1\" ! multifilesink location=testsequence02_1_%1d.log" 2 0 0 $PERFORMANCE
callCompareTest testsequence_1.golden testsequence02_0_1.log 2-1 "Compare 2-1" 1 0
callCompareTest testsequence_2.golden testsequence02_0_2.log 2-2 "Compare 2-2" 1 0
callCompareTest testsequence_9.golden testsequence02_1_9.log 2-19 "Compare 2-19" 1 0
callCompareTest testsequence_10.golden testsequence02_1_10.log 2-10 "Compare 2-20" 1 0
-gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} multifilesrc location=testsequence_%1d.png index=0 caps=\"image/png, framerate=30/1\" ! pngdec ! tensor_converter ! tensor_reposink silent=false slot-index=0 tensor_reposrc silent=false slot-index=0 caps=\"other/tensor, dim1=3, dim2=16, dim3=16, dim4=1, type=uint8, framerate=30/1\" ! multifilesink location=testsequence03_0_%1d.log multifilesrc location=testsequence_%1d.png index=0 caps=\"image/png, framerate=30/1\" ! pngdec ! tensor_converter ! tensor_reposink silent=false slot-index=1 tensor_reposrc silent=false slot-index=1 caps=\"other/tensor, dim1=3, dim2=16, dim3=16, dim4=1, type=uint8, framerate=30/1\" ! multifilesink location=testsequence03_1_%1d.log multifilesrc location=testsequence_%1d.png index=0 caps=\"image/png, framerate=30/1\" ! pngdec ! tensor_converter ! tensor_reposink silent=false slot-index=2 tensor_reposrc silent=false slot-index=2 caps=\"other/tensor, dim1=3, dim2=16, dim3=16, dim4=1, type=uint8, framerate=30/1\" ! multifilesink location=testsequence03_2_%1d.log" 3 0 0 $PERFORMANCE
+gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} multifilesrc location=testsequence_%1d.png index=0 caps=\"image/png,framerate=(fraction)30/1\" ! pngdec ! tensor_converter ! tensor_reposink silent=false slot-index=0 tensor_reposrc silent=false slot-index=0 caps=\"other/tensor,dimension=(string)3:16:16:1,type=(string)uint8,framerate=(fraction)30/1\" ! multifilesink location=testsequence03_0_%1d.log multifilesrc location=testsequence_%1d.png index=0 caps=\"image/png,framerate=(fraction)30/1\" ! pngdec ! tensor_converter ! tensor_reposink silent=false slot-index=1 tensor_reposrc silent=false slot-index=1 caps=\"other/tensor,dimension=(string)3:16:16:1,type=(string)uint8,framerate=(fraction)30/1\" ! multifilesink location=testsequence03_1_%1d.log multifilesrc location=testsequence_%1d.png index=0 caps=\"image/png,framerate=(fraction)30/1\" ! pngdec ! tensor_converter ! tensor_reposink silent=false slot-index=2 tensor_reposrc silent=false slot-index=2 caps=\"other/tensor,dimension=(string)3:16:16:1,type=(string)uint8,framerate=(fraction)30/1\" ! multifilesink location=testsequence03_2_%1d.log" 3 0 0 $PERFORMANCE
callCompareTest testsequence_1.golden testsequence03_0_1.log 3-1 "Compare 3-1" 1 0
callCompareTest testsequence_2.golden testsequence03_0_2.log 3-2 "Compare 3-2" 1 0
# Generate video_4x4xBGRx.xraw & golden
python generateTestCase.py
-gstTest "--gst-plugin-path=../../build tensor_mux name=mux ! tensor_filter framework=custom model=../../build/nnstreamer_example/custom_example_LSTM/libdummyLSTM.so ! tensor_demux name=demux ! queue ! tensor_reposink slot-index=0 silent=false demux.src_1 ! queue ! tee name=t ! queue ! tensor_reposink slot-index=1 silent=false tensor_reposrc slot-index=0 silent=false caps=\"other/tensor, dim1=4, dim2=4, dim3=4, dim4=1, type=float32\" ! mux.sink_0 tensor_reposrc slot-index=1 silent=false caps=\"other/tensor, dim1=4, dim2=4, dim3=4, dim4=1, type=float32\" ! mux.sink_1 filesrc location=\"video_4x4xBGRx.xraw\" ! application/octet-stream ! tensor_converter input-dim=4:4:4:1 input-type=float32 ! mux.sink_2 t. ! queue ! multifilesink location=\"out_%1d.log\"" 1 0 0 $PERFORMANCE
+gstTest "--gst-plugin-path=../../build tensor_mux name=mux ! tensor_filter framework=custom model=../../build/nnstreamer_example/custom_example_LSTM/libdummyLSTM.so ! tensor_demux name=demux ! queue ! tensor_reposink slot-index=0 silent=false demux.src_1 ! queue ! tee name=t ! queue ! tensor_reposink slot-index=1 silent=false tensor_reposrc slot-index=0 silent=false caps=\"other/tensor,dimension=(string)4:4:4:1,type=(string)float32,framerate=(fraction)0/1\" ! mux.sink_0 tensor_reposrc slot-index=1 silent=false caps=\"other/tensor,dimension=(string)4:4:4:1,type=(string)float32,framerate=(fraction)0/1\" ! mux.sink_1 filesrc location=\"video_4x4xBGRx.xraw\" ! application/octet-stream ! tensor_converter input-dim=4:4:4:1 input-type=float32 ! mux.sink_2 t. ! queue ! multifilesink location=\"out_%1d.log\"" 1 0 0 $PERFORMANCE
callCompareTest lstm.golden out_9.log 1-1 "Compare 1-1" 1 0
# Generate video_4x4xBGRx.xraw
python generateTestCase.py
-gstTest "--gst-plugin-path=../../build tensor_mux name=mux ! tensor_filter framework=custom model=../../build/nnstreamer_example/custom_example_RNN/libdummyRNN.so ! tee name=t ! queue ! tensor_reposink slot-index=0 silent=false filesrc location=\"video_4x4xBGRx.xraw\" ! application/octet-stream ! tensor_converter input-dim=4:4:4:1 input-type=uint8 ! mux.sink_0 tensor_reposrc slot-index=0 silent=false caps=\"other/tensor, dim1=4, dim2=4, dim3=4, dim4=1, type=uint8\" ! mux.sink_1 t. ! queue ! multifilesink location=\"out_%1d.log\"" 1 0 0 $PERFORMANCE
+gstTest "--gst-plugin-path=../../build tensor_mux name=mux ! tensor_filter framework=custom model=../../build/nnstreamer_example/custom_example_RNN/libdummyRNN.so ! tee name=t ! queue ! tensor_reposink slot-index=0 silent=false filesrc location=\"video_4x4xBGRx.xraw\" ! application/octet-stream ! tensor_converter input-dim=4:4:4:1 input-type=uint8 ! mux.sink_0 tensor_reposrc slot-index=0 silent=false caps=\"other/tensor,dimension=(string)4:4:4:1,type=(string)uint8,framerate=(fraction)0/1\" ! mux.sink_1 t. ! queue ! multifilesink location=\"out_%1d.log\"" 1 0 0 $PERFORMANCE
callCompareTest rnn.golden out_9.log 1-1 "Compare 1-1" 1 0