mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-04 22:48:54 +00:00
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:
parent
2f3deb4009
commit
0a343fa738
5 changed files with 26 additions and 39 deletions
|
@ -13,6 +13,6 @@ variables:
|
||||||
|
|
||||||
LINT_TAG: '2024-02-20.0'
|
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'
|
WINDOWS_TAG: '2024-11-29.0'
|
||||||
|
|
|
@ -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>
|
<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"/>
|
<type name="TensorDataType" c:type="GstTensorDataType"/>
|
||||||
</field>
|
</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">
|
<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>
|
<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*"/>
|
<type name="Gst.Buffer" c:type="GstBuffer*"/>
|
||||||
|
@ -1262,7 +1258,7 @@ pixel to instance of an object is identified.</doc>
|
||||||
</field>
|
</field>
|
||||||
<field name="dims" writable="1">
|
<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>
|
<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"/>
|
<type name="TensorDim" c:type="GstTensorDim"/>
|
||||||
</array>
|
</array>
|
||||||
</field>
|
</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>
|
<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"/>
|
<type name="TensorDataType" c:type="GstTensorDataType"/>
|
||||||
</parameter>
|
</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">
|
<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>
|
<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*"/>
|
<type name="Gst.Buffer" c:type="GstBuffer*"/>
|
||||||
|
@ -1314,8 +1306,9 @@ with an interleaved layout</doc>
|
||||||
<type name="gsize" c:type="gsize"/>
|
<type name="gsize" c:type="gsize"/>
|
||||||
</parameter>
|
</parameter>
|
||||||
<parameter name="dims" transfer-ownership="none">
|
<parameter name="dims" transfer-ownership="none">
|
||||||
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.c">tensor dimensions</doc>
|
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.c">tensor dimensions. Value of 0 mean the
|
||||||
<array length="5" zero-terminated="0" c:type="gsize*">
|
dimension is dynamic.</doc>
|
||||||
|
<array length="4" zero-terminated="0" c:type="gsize*">
|
||||||
<type name="gsize" c:type="gsize"/>
|
<type name="gsize" c:type="gsize"/>
|
||||||
</array>
|
</array>
|
||||||
</parameter>
|
</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>
|
<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"/>
|
<source-position filename="../subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.h"/>
|
||||||
<field name="size" writable="1">
|
<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"/>
|
<type name="gsize" c:type="gsize"/>
|
||||||
</field>
|
</field>
|
||||||
<field name="order_index" writable="1">
|
<field name="order_index" writable="1">
|
||||||
|
@ -1447,7 +1440,7 @@ with an interleaved layout</doc>
|
||||||
<enumeration name="TensorLayout" version="1.26" c:type="GstTensorLayout">
|
<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>
|
<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"/>
|
<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>
|
<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>
|
</member>
|
||||||
</enumeration>
|
</enumeration>
|
||||||
|
|
|
@ -349,7 +349,6 @@ GstOnnxClient::GstOnnxClient (GstElement *debug_parent):debug_parent(debug_paren
|
||||||
else
|
else
|
||||||
tensor->id = 0;
|
tensor->id = 0;
|
||||||
tensor->num_dims = tensorShape.size ();
|
tensor->num_dims = tensorShape.size ();
|
||||||
tensor->batch_size = 1;
|
|
||||||
|
|
||||||
for (size_t j = 0; j < tensorShape.size (); ++j)
|
for (size_t j = 0; j < tensorShape.size (); ++j)
|
||||||
tensor->dims[j].size = tensorShape[j];
|
tensor->dims[j].size = tensorShape[j];
|
||||||
|
|
|
@ -88,11 +88,11 @@ size_for_elements (GstTensorDataType data_type, gsize elements)
|
||||||
* gst_tensor_new_simple:
|
* gst_tensor_new_simple:
|
||||||
* @id: semantically identify the contents of the tensor
|
* @id: semantically identify the contents of the tensor
|
||||||
* @data_type: #GstTensorDataType of tensor data
|
* @data_type: #GstTensorDataType of tensor data
|
||||||
* @batch_size: Model batch size
|
|
||||||
* @data: (transfer full): #GstBuffer holding tensor data
|
* @data: (transfer full): #GstBuffer holding tensor data
|
||||||
* @dims_order: Indicate tensor dimension indexing order
|
* @dims_order: Indicate tensor dimension indexing order
|
||||||
* @num_dims: number of tensor dimensions
|
* @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
|
* Allocates a new #GstTensor of @dims_order ROW_MAJOR or COLUMN_MAJOR and
|
||||||
* with an interleaved layout
|
* with an interleaved layout
|
||||||
|
@ -102,31 +102,35 @@ size_for_elements (GstTensorDataType data_type, gsize elements)
|
||||||
* Since: 1.26
|
* Since: 1.26
|
||||||
*/
|
*/
|
||||||
GstTensor *
|
GstTensor *
|
||||||
gst_tensor_new_simple (GQuark id, GstTensorDataType data_type,
|
gst_tensor_new_simple (GQuark id, GstTensorDataType data_type, GstBuffer * data,
|
||||||
gsize batch_size, GstBuffer * data,
|
|
||||||
GstTensorDimOrder dims_order, gsize num_dims, gsize * dims)
|
GstTensorDimOrder dims_order, gsize num_dims, gsize * dims)
|
||||||
{
|
{
|
||||||
GstTensor *tensor;
|
GstTensor *tensor;
|
||||||
gsize num_elements = 1;
|
gsize num_elements = 1;
|
||||||
gsize i;
|
gsize i;
|
||||||
|
gboolean dynamic_tensor_size = FALSE;
|
||||||
|
|
||||||
/* Update this if adding more to GstTensorDataType */
|
/* 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 (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 (GST_IS_BUFFER (data), NULL);
|
||||||
g_return_val_if_fail (dims_order == GST_TENSOR_DIM_ORDER_ROW_MAJOR ||
|
g_return_val_if_fail (dims_order == GST_TENSOR_DIM_ORDER_ROW_MAJOR ||
|
||||||
dims_order == GST_TENSOR_DIM_ORDER_COL_MAJOR, NULL);
|
dims_order == GST_TENSOR_DIM_ORDER_COL_MAJOR, NULL);
|
||||||
g_return_val_if_fail (num_dims > 0, NULL);
|
g_return_val_if_fail (num_dims > 0, NULL);
|
||||||
|
|
||||||
|
|
||||||
for (i = 0; i < num_dims; i++) {
|
for (i = 0; i < num_dims; i++) {
|
||||||
g_return_val_if_fail (dims[i] > 0, NULL);
|
dynamic_tensor_size = dims[i] == 0;
|
||||||
num_elements *= dims[i];
|
|
||||||
}
|
|
||||||
num_elements *= batch_size;
|
|
||||||
|
|
||||||
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),"
|
g_critical ("Expected buffer of size %zu (%zu elements),"
|
||||||
" but buffer has size %zu",
|
" but buffer has size %zu",
|
||||||
size_for_elements (data_type, num_elements), num_elements,
|
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 = gst_tensor_alloc (num_dims);
|
||||||
tensor->id = id;
|
tensor->id = id;
|
||||||
tensor->layout = GST_TENSOR_LAYOUT_STRIDED;
|
tensor->layout = GST_TENSOR_LAYOUT_CONTIGUOUS;
|
||||||
tensor->data_type = data_type;
|
tensor->data_type = data_type;
|
||||||
tensor->batch_size = batch_size;
|
|
||||||
tensor->data = data;
|
tensor->data = data;
|
||||||
tensor->dims_order = dims_order;
|
tensor->dims_order = dims_order;
|
||||||
tensor->num_dims = num_dims;
|
tensor->num_dims = num_dims;
|
||||||
for (i = 0; i < num_dims; i++) {
|
for (i = 0; i < num_dims; i++) {
|
||||||
tensor->dims[i].size = 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;
|
return tensor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,7 @@ typedef enum _GstTensorDimOrder
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GstTensorLayout:
|
* 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.
|
* Indicate tensor storage in memory.
|
||||||
*
|
*
|
||||||
|
@ -100,13 +100,13 @@ typedef enum _GstTensorDimOrder
|
||||||
*/
|
*/
|
||||||
typedef enum _GstTensorLayout
|
typedef enum _GstTensorLayout
|
||||||
{
|
{
|
||||||
GST_TENSOR_LAYOUT_STRIDED
|
GST_TENSOR_LAYOUT_CONTIGUOUS
|
||||||
} GstTensorLayout;
|
} GstTensorLayout;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GstTensorDim:
|
* 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
|
* @order_index: Dimension order in memory. @see_also #GST_TENSOR_DIM_ORDER_INDEXED
|
||||||
*
|
*
|
||||||
* Hold properties of the tensor's dimension
|
* Hold properties of the tensor's dimension
|
||||||
|
@ -124,7 +124,6 @@ typedef struct _GstTensorDim
|
||||||
* @id: semantically identify the contents of the tensor
|
* @id: semantically identify the contents of the tensor
|
||||||
* @layout: Indicate tensor layout
|
* @layout: Indicate tensor layout
|
||||||
* @data_type: #GstTensorDataType of tensor data
|
* @data_type: #GstTensorDataType of tensor data
|
||||||
* @batch_size: Model batch size
|
|
||||||
* @data: #GstBuffer holding tensor data
|
* @data: #GstBuffer holding tensor data
|
||||||
* @dims_order: Indicate tensor elements layout in memory.
|
* @dims_order: Indicate tensor elements layout in memory.
|
||||||
* @num_dims: number of tensor dimensions
|
* @num_dims: number of tensor dimensions
|
||||||
|
@ -139,7 +138,6 @@ typedef struct _GstTensor
|
||||||
GQuark id;
|
GQuark id;
|
||||||
GstTensorLayout layout;
|
GstTensorLayout layout;
|
||||||
GstTensorDataType data_type;
|
GstTensorDataType data_type;
|
||||||
gsize batch_size;
|
|
||||||
GstBuffer *data;
|
GstBuffer *data;
|
||||||
GstTensorDimOrder dims_order;
|
GstTensorDimOrder dims_order;
|
||||||
gsize num_dims;
|
gsize num_dims;
|
||||||
|
@ -156,7 +154,6 @@ GstTensor * gst_tensor_alloc (gsize num_dims);
|
||||||
GST_ANALYTICS_META_API
|
GST_ANALYTICS_META_API
|
||||||
GstTensor * gst_tensor_new_simple (GQuark id,
|
GstTensor * gst_tensor_new_simple (GQuark id,
|
||||||
GstTensorDataType data_type,
|
GstTensorDataType data_type,
|
||||||
gsize batch_size,
|
|
||||||
GstBuffer * data,
|
GstBuffer * data,
|
||||||
GstTensorDimOrder dims_order,
|
GstTensorDimOrder dims_order,
|
||||||
gsize num_dims,
|
gsize num_dims,
|
||||||
|
|
Loading…
Reference in a new issue