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: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/8191>
This commit is contained in:
Daniel Morin 2024-12-20 14:51:45 -05:00 committed by GStreamer Marge Bot
parent 2f3deb4009
commit 0a343fa738
5 changed files with 26 additions and 39 deletions

View file

@ -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'

View file

@ -1244,10 +1244,6 @@ pixel to instance of an object is identified.</doc>
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.h">#GstTensorDataType of tensor data</doc>
<type name="TensorDataType" c:type="GstTensorDataType"/>
</field>
<field name="batch_size" writable="1">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.h">Model batch size</doc>
<type name="gsize" c:type="gsize"/>
</field>
<field name="data" writable="1">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.h">#GstBuffer holding tensor data</doc>
<type name="Gst.Buffer" c:type="GstBuffer*"/>
@ -1262,7 +1258,7 @@ pixel to instance of an object is identified.</doc>
</field>
<field name="dims" writable="1">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.h">number of tensor dimensions</doc>
<array length="6" zero-terminated="0">
<array length="5" zero-terminated="0">
<type name="TensorDim" c:type="GstTensorDim"/>
</array>
</field>
@ -1297,10 +1293,6 @@ with an interleaved layout</doc>
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.c">#GstTensorDataType of tensor data</doc>
<type name="TensorDataType" c:type="GstTensorDataType"/>
</parameter>
<parameter name="batch_size" transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.c">Model batch size</doc>
<type name="gsize" c:type="gsize"/>
</parameter>
<parameter name="data" transfer-ownership="full">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.c">#GstBuffer holding tensor data</doc>
<type name="Gst.Buffer" c:type="GstBuffer*"/>
@ -1314,8 +1306,9 @@ with an interleaved layout</doc>
<type name="gsize" c:type="gsize"/>
</parameter>
<parameter name="dims" transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.c">tensor dimensions</doc>
<array length="5" zero-terminated="0" c:type="gsize*">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.c">tensor dimensions. Value of 0 mean the
dimension is dynamic.</doc>
<array length="4" zero-terminated="0" c:type="gsize*">
<type name="gsize" c:type="gsize"/>
</array>
</parameter>
@ -1419,7 +1412,7 @@ with an interleaved layout</doc>
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.h">Hold properties of the tensor's dimension</doc>
<source-position filename="../subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.h"/>
<field name="size" writable="1">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.h">Size of the dimension</doc>
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.h">Size of the dimension. Use 0 for dynamic dimension using.</doc>
<type name="gsize" c:type="gsize"/>
</field>
<field name="order_index" writable="1">
@ -1447,7 +1440,7 @@ with an interleaved layout</doc>
<enumeration name="TensorLayout" version="1.26" c:type="GstTensorLayout">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.h">Indicate tensor storage in memory.</doc>
<source-position filename="../subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.h"/>
<member name="tensor_layout_strided" value="0" c:identifier="GST_TENSOR_LAYOUT_STRIDED">
<member name="tensor_layout_contiguous" value="0" c:identifier="GST_TENSOR_LAYOUT_CONTIGUOUS">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.h">indicate the tensor is stored in a dense format in memory</doc>
</member>
</enumeration>

View file

@ -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];

View file

@ -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;
}

View file

@ -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,