From 0a343fa738acf439788e2866ce6e19a492079b73 Mon Sep 17 00:00:00 2001 From: Daniel Morin Date: Fri, 20 Dec 2024 14:51:45 -0500 Subject: [PATCH] analytics: remove batch-size - Batch-size will be the outer-most dimension. Presence of batch dimension can be identified using `dims` and `id`. Part-of: --- .gitlab-image-tags.yml | 2 +- girs/GstAnalytics-1.0.gir | 19 ++++------- .../ext/onnx/gstonnxclient.cpp | 1 - .../gst-libs/gst/analytics/gsttensor.c | 34 +++++++++---------- .../gst-libs/gst/analytics/gsttensor.h | 9 ++--- 5 files changed, 26 insertions(+), 39 deletions(-) diff --git a/.gitlab-image-tags.yml b/.gitlab-image-tags.yml index 751d6cfa02..1ee044dce9 100644 --- a/.gitlab-image-tags.yml +++ b/.gitlab-image-tags.yml @@ -13,6 +13,6 @@ variables: LINT_TAG: '2024-02-20.0' - ABI_CHECK_TAG: '2024-12-09.0' + ABI_CHECK_TAG: '2024-12-20.2' WINDOWS_TAG: '2024-11-29.0' diff --git a/girs/GstAnalytics-1.0.gir b/girs/GstAnalytics-1.0.gir index aab096b2ed..69b91757bd 100644 --- a/girs/GstAnalytics-1.0.gir +++ b/girs/GstAnalytics-1.0.gir @@ -1244,10 +1244,6 @@ pixel to instance of an object is identified. #GstTensorDataType of tensor data - - Model batch size - - #GstBuffer holding tensor data @@ -1262,7 +1258,7 @@ pixel to instance of an object is identified. number of tensor dimensions - + @@ -1297,10 +1293,6 @@ with an interleaved layout #GstTensorDataType of tensor data - - Model batch size - - #GstBuffer holding tensor data @@ -1314,8 +1306,9 @@ with an interleaved layout - tensor dimensions - + tensor dimensions. Value of 0 mean the +dimension is dynamic. + @@ -1419,7 +1412,7 @@ with an interleaved layout Hold properties of the tensor's dimension - Size of the dimension + Size of the dimension. Use 0 for dynamic dimension using. @@ -1447,7 +1440,7 @@ with an interleaved layout Indicate tensor storage in memory. - + indicate the tensor is stored in a dense format in memory diff --git a/subprojects/gst-plugins-bad/ext/onnx/gstonnxclient.cpp b/subprojects/gst-plugins-bad/ext/onnx/gstonnxclient.cpp index f84a6d80cf..4e5172bd8d 100644 --- a/subprojects/gst-plugins-bad/ext/onnx/gstonnxclient.cpp +++ b/subprojects/gst-plugins-bad/ext/onnx/gstonnxclient.cpp @@ -349,7 +349,6 @@ GstOnnxClient::GstOnnxClient (GstElement *debug_parent):debug_parent(debug_paren else tensor->id = 0; tensor->num_dims = tensorShape.size (); - tensor->batch_size = 1; for (size_t j = 0; j < tensorShape.size (); ++j) tensor->dims[j].size = tensorShape[j]; diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.c b/subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.c index c54e9b2fab..d20e353f0f 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.c +++ b/subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.c @@ -88,11 +88,11 @@ size_for_elements (GstTensorDataType data_type, gsize elements) * gst_tensor_new_simple: * @id: semantically identify the contents of the tensor * @data_type: #GstTensorDataType of tensor data - * @batch_size: Model batch size * @data: (transfer full): #GstBuffer holding tensor data * @dims_order: Indicate tensor dimension indexing order * @num_dims: number of tensor dimensions - * @dims: (array length=num_dims): tensor dimensions + * @dims: (array length=num_dims): tensor dimensions. Value of 0 mean the + * dimension is dynamic. * * Allocates a new #GstTensor of @dims_order ROW_MAJOR or COLUMN_MAJOR and * with an interleaved layout @@ -102,31 +102,35 @@ size_for_elements (GstTensorDataType data_type, gsize elements) * Since: 1.26 */ GstTensor * -gst_tensor_new_simple (GQuark id, GstTensorDataType data_type, - gsize batch_size, GstBuffer * data, +gst_tensor_new_simple (GQuark id, GstTensorDataType data_type, GstBuffer * data, GstTensorDimOrder dims_order, gsize num_dims, gsize * dims) { GstTensor *tensor; gsize num_elements = 1; gsize i; + gboolean dynamic_tensor_size = FALSE; /* Update this if adding more to GstTensorDataType */ g_return_val_if_fail (data_type <= GST_TENSOR_DATA_TYPE_BFLOAT16, NULL); - g_return_val_if_fail (batch_size > 0, NULL); g_return_val_if_fail (GST_IS_BUFFER (data), NULL); g_return_val_if_fail (dims_order == GST_TENSOR_DIM_ORDER_ROW_MAJOR || dims_order == GST_TENSOR_DIM_ORDER_COL_MAJOR, NULL); g_return_val_if_fail (num_dims > 0, NULL); - for (i = 0; i < num_dims; i++) { - g_return_val_if_fail (dims[i] > 0, NULL); - num_elements *= dims[i]; - } - num_elements *= batch_size; + dynamic_tensor_size = dims[i] == 0; - if (gst_buffer_get_size (data) != size_for_elements (data_type, num_elements)) { + if (dynamic_tensor_size == FALSE) + num_elements *= dims[i]; + else + break; + } + + /* We can't do this validation if the tensor size is dynamic */ + if (dynamic_tensor_size == FALSE && + gst_buffer_get_size (data) != + size_for_elements (data_type, num_elements)) { g_critical ("Expected buffer of size %zu (%zu elements)," " but buffer has size %zu", size_for_elements (data_type, num_elements), num_elements, @@ -136,20 +140,14 @@ gst_tensor_new_simple (GQuark id, GstTensorDataType data_type, tensor = gst_tensor_alloc (num_dims); tensor->id = id; - tensor->layout = GST_TENSOR_LAYOUT_STRIDED; + tensor->layout = GST_TENSOR_LAYOUT_CONTIGUOUS; tensor->data_type = data_type; - tensor->batch_size = batch_size; tensor->data = data; tensor->dims_order = dims_order; tensor->num_dims = num_dims; for (i = 0; i < num_dims; i++) { tensor->dims[i].size = dims[i]; - if (dims_order == GST_TENSOR_DIM_ORDER_COL_MAJOR) - tensor->dims[i].order_index = i; - else if (dims_order == GST_TENSOR_DIM_ORDER_ROW_MAJOR) - tensor->dims[i].order_index = num_dims - i - 1; } - return tensor; } diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.h b/subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.h index ea686c2462..1ab15606f6 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.h +++ b/subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.h @@ -92,7 +92,7 @@ typedef enum _GstTensorDimOrder /** * GstTensorLayout: - * @GST_TENSOR_LAYOUT_STRIDED: indicate the tensor is stored in a dense format in memory + * @GST_TENSOR_LAYOUT_CONTIGUOUS: indicate the tensor is stored in a dense format in memory * * Indicate tensor storage in memory. * @@ -100,13 +100,13 @@ typedef enum _GstTensorDimOrder */ typedef enum _GstTensorLayout { - GST_TENSOR_LAYOUT_STRIDED + GST_TENSOR_LAYOUT_CONTIGUOUS } GstTensorLayout; /** * GstTensorDim: - * @size: Size of the dimension + * @size: Size of the dimension. Use 0 for dynamic dimension using. * @order_index: Dimension order in memory. @see_also #GST_TENSOR_DIM_ORDER_INDEXED * * Hold properties of the tensor's dimension @@ -124,7 +124,6 @@ typedef struct _GstTensorDim * @id: semantically identify the contents of the tensor * @layout: Indicate tensor layout * @data_type: #GstTensorDataType of tensor data - * @batch_size: Model batch size * @data: #GstBuffer holding tensor data * @dims_order: Indicate tensor elements layout in memory. * @num_dims: number of tensor dimensions @@ -139,7 +138,6 @@ typedef struct _GstTensor GQuark id; GstTensorLayout layout; GstTensorDataType data_type; - gsize batch_size; GstBuffer *data; GstTensorDimOrder dims_order; gsize num_dims; @@ -156,7 +154,6 @@ GstTensor * gst_tensor_alloc (gsize num_dims); GST_ANALYTICS_META_API GstTensor * gst_tensor_new_simple (GQuark id, GstTensorDataType data_type, - gsize batch_size, GstBuffer * data, GstTensorDimOrder dims_order, gsize num_dims,