analytics: Tensor dimensions are always row-major or col-major
Simplify by removing the extra fields, as this is what all frameworks give us. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/8250>
This commit is contained in:
parent
bb6bf7d23b
commit
33259e7ea4
@ -13,6 +13,6 @@ variables:
|
|||||||
|
|
||||||
LINT_TAG: '2024-02-20.0'
|
LINT_TAG: '2024-02-20.0'
|
||||||
|
|
||||||
ABI_CHECK_TAG: '2024-12-20.2'
|
ABI_CHECK_TAG: '2025-01-08.1'
|
||||||
|
|
||||||
WINDOWS_TAG: '2024-11-29.0'
|
WINDOWS_TAG: '2024-11-29.0'
|
||||||
|
@ -1259,7 +1259,7 @@ pixel to instance of an object is identified.</doc>
|
|||||||
<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="5" zero-terminated="0">
|
<array length="5" zero-terminated="0">
|
||||||
<type name="TensorDim" c:type="GstTensorDim"/>
|
<type name="gsize" c:type="gsize"/>
|
||||||
</array>
|
</array>
|
||||||
</field>
|
</field>
|
||||||
<constructor name="alloc" c:identifier="gst_tensor_alloc" version="1.26">
|
<constructor name="alloc" c:identifier="gst_tensor_alloc" version="1.26">
|
||||||
@ -1346,8 +1346,8 @@ dimension is dynamic.</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"/>
|
||||||
<return-value transfer-ownership="none">
|
<return-value transfer-ownership="none">
|
||||||
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.c">The dims array form the tensor</doc>
|
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.c">The dims array form the tensor</doc>
|
||||||
<array length="0" zero-terminated="0" c:type="GstTensorDim*">
|
<array length="0" zero-terminated="0" c:type="gsize*">
|
||||||
<type name="TensorDim" c:type="GstTensorDim"/>
|
<type name="gsize" c:type="gsize"/>
|
||||||
</array>
|
</array>
|
||||||
</return-value>
|
</return-value>
|
||||||
<parameters>
|
<parameters>
|
||||||
@ -1408,18 +1408,6 @@ dimension is dynamic.</doc>
|
|||||||
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.h">"brain" 16 bit floating point tensor data</doc>
|
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.h">"brain" 16 bit floating point tensor data</doc>
|
||||||
</member>
|
</member>
|
||||||
</enumeration>
|
</enumeration>
|
||||||
<record name="TensorDim" c:type="GstTensorDim" version="1.26">
|
|
||||||
<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. Use 0 for dynamic dimension using.</doc>
|
|
||||||
<type name="gsize" c:type="gsize"/>
|
|
||||||
</field>
|
|
||||||
<field name="order_index" writable="1">
|
|
||||||
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.h">Dimension order in memory. @see_also #GST_TENSOR_DIM_ORDER_INDEXED</doc>
|
|
||||||
<type name="gsize" c:type="gsize"/>
|
|
||||||
</field>
|
|
||||||
</record>
|
|
||||||
<enumeration name="TensorDimOrder" version="1.26" c:type="GstTensorDimOrder">
|
<enumeration name="TensorDimOrder" version="1.26" c:type="GstTensorDimOrder">
|
||||||
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.h">Indicate to read tensor from memory in row-major or column-major order.</doc>
|
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.h">Indicate to read tensor from memory in row-major or column-major order.</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"/>
|
||||||
@ -1429,13 +1417,6 @@ dimension is dynamic.</doc>
|
|||||||
<member name="col_major" value="1" c:identifier="GST_TENSOR_DIM_ORDER_COL_MAJOR">
|
<member name="col_major" value="1" c:identifier="GST_TENSOR_DIM_ORDER_COL_MAJOR">
|
||||||
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.h">elements along a column are consecutive in memory</doc>
|
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.h">elements along a column are consecutive in memory</doc>
|
||||||
</member>
|
</member>
|
||||||
<member name="indexed" value="2" c:identifier="GST_TENSOR_DIM_ORDER_INDEXED">
|
|
||||||
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.h">elements storage follow the order defined by
|
|
||||||
#GstTensorDim.order_index This mean that when iterating the tensor
|
|
||||||
the dimension with index 0 is the most nested in the loops and consecutive
|
|
||||||
in memory, followed by other dimensions in the order defined by
|
|
||||||
#GstTensorDim.order_index.</doc>
|
|
||||||
</member>
|
|
||||||
</enumeration>
|
</enumeration>
|
||||||
<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>
|
||||||
|
@ -351,7 +351,7 @@ GstOnnxClient::GstOnnxClient (GstElement *debug_parent):debug_parent(debug_paren
|
|||||||
tensor->num_dims = tensorShape.size ();
|
tensor->num_dims = tensorShape.size ();
|
||||||
|
|
||||||
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] = tensorShape[j];
|
||||||
|
|
||||||
size_t numElements =
|
size_t numElements =
|
||||||
outputTensor.GetTensorTypeAndShapeInfo ().GetElementCount ();
|
outputTensor.GetTensorTypeAndShapeInfo ().GetElementCount ();
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
#include "gsttensor.h"
|
#include "gsttensor.h"
|
||||||
|
|
||||||
#define GST_TENSOR_SIZE(num_dims) \
|
#define GST_TENSOR_SIZE(num_dims) \
|
||||||
(sizeof (GstTensor) + (sizeof (GstTensorDim) * num_dims))
|
(sizeof (GstTensor) + (sizeof (gsize) * num_dims))
|
||||||
|
|
||||||
G_DEFINE_BOXED_TYPE (GstTensor, gst_tensor,
|
G_DEFINE_BOXED_TYPE (GstTensor, gst_tensor,
|
||||||
(GBoxedCopyFunc) gst_tensor_copy, (GBoxedFreeFunc) gst_tensor_free);
|
(GBoxedCopyFunc) gst_tensor_copy, (GBoxedFreeFunc) gst_tensor_free);
|
||||||
@ -145,9 +145,8 @@ gst_tensor_new_simple (GQuark id, GstTensorDataType data_type, GstBuffer * data,
|
|||||||
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++) {
|
memcpy (tensor->dims, dims, sizeof (gsize) * num_dims);
|
||||||
tensor->dims[i].size = dims[i];
|
|
||||||
}
|
|
||||||
return tensor;
|
return tensor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,7 +202,7 @@ gst_tensor_copy (const GstTensor * tensor)
|
|||||||
* Since: 1.26
|
* Since: 1.26
|
||||||
*/
|
*/
|
||||||
|
|
||||||
GstTensorDim *
|
gsize *
|
||||||
gst_tensor_get_dims (GstTensor * tensor, gsize * num_dims)
|
gst_tensor_get_dims (GstTensor * tensor, gsize * num_dims)
|
||||||
{
|
{
|
||||||
if (num_dims)
|
if (num_dims)
|
||||||
|
@ -73,11 +73,6 @@ typedef enum _GstTensorDataType
|
|||||||
* GstTensorDimOrder:
|
* GstTensorDimOrder:
|
||||||
* @GST_TENSOR_DIM_ORDER_ROW_MAJOR: elements along a row are consecutive in memory
|
* @GST_TENSOR_DIM_ORDER_ROW_MAJOR: elements along a row are consecutive in memory
|
||||||
* @GST_TENSOR_DIM_ORDER_COL_MAJOR: elements along a column are consecutive in memory
|
* @GST_TENSOR_DIM_ORDER_COL_MAJOR: elements along a column are consecutive in memory
|
||||||
* @GST_TENSOR_DIM_ORDER_INDEXED: elements storage follow the order defined by
|
|
||||||
* #GstTensorDim.order_index This mean that when iterating the tensor
|
|
||||||
* the dimension with index 0 is the most nested in the loops and consecutive
|
|
||||||
* in memory, followed by other dimensions in the order defined by
|
|
||||||
* #GstTensorDim.order_index.
|
|
||||||
*
|
*
|
||||||
* Indicate to read tensor from memory in row-major or column-major order.
|
* Indicate to read tensor from memory in row-major or column-major order.
|
||||||
*
|
*
|
||||||
@ -86,8 +81,7 @@ typedef enum _GstTensorDataType
|
|||||||
typedef enum _GstTensorDimOrder
|
typedef enum _GstTensorDimOrder
|
||||||
{
|
{
|
||||||
GST_TENSOR_DIM_ORDER_ROW_MAJOR,
|
GST_TENSOR_DIM_ORDER_ROW_MAJOR,
|
||||||
GST_TENSOR_DIM_ORDER_COL_MAJOR,
|
GST_TENSOR_DIM_ORDER_COL_MAJOR
|
||||||
GST_TENSOR_DIM_ORDER_INDEXED
|
|
||||||
} GstTensorDimOrder;
|
} GstTensorDimOrder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -103,22 +97,6 @@ typedef enum _GstTensorLayout
|
|||||||
GST_TENSOR_LAYOUT_CONTIGUOUS
|
GST_TENSOR_LAYOUT_CONTIGUOUS
|
||||||
} GstTensorLayout;
|
} GstTensorLayout;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* GstTensorDim:
|
|
||||||
* @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
|
|
||||||
*
|
|
||||||
* Since: 1.26
|
|
||||||
*/
|
|
||||||
typedef struct _GstTensorDim
|
|
||||||
{
|
|
||||||
gsize size;
|
|
||||||
gsize order_index;
|
|
||||||
} GstTensorDim;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GstTensor:
|
* GstTensor:
|
||||||
* @id: semantically identify the contents of the tensor
|
* @id: semantically identify the contents of the tensor
|
||||||
@ -141,7 +119,7 @@ typedef struct _GstTensor
|
|||||||
GstBuffer *data;
|
GstBuffer *data;
|
||||||
GstTensorDimOrder dims_order;
|
GstTensorDimOrder dims_order;
|
||||||
gsize num_dims;
|
gsize num_dims;
|
||||||
GstTensorDim dims[];
|
gsize dims[];
|
||||||
} GstTensor;
|
} GstTensor;
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
@ -166,7 +144,7 @@ GST_ANALYTICS_META_API
|
|||||||
GstTensor * gst_tensor_copy (const GstTensor * tensor);
|
GstTensor * gst_tensor_copy (const GstTensor * tensor);
|
||||||
|
|
||||||
GST_ANALYTICS_META_API
|
GST_ANALYTICS_META_API
|
||||||
GstTensorDim * gst_tensor_get_dims (GstTensor * tensor, gsize * num_dims);
|
gsize * gst_tensor_get_dims (GstTensor * tensor, gsize * num_dims);
|
||||||
|
|
||||||
GST_ANALYTICS_META_API
|
GST_ANALYTICS_META_API
|
||||||
GType gst_tensor_get_type (void);
|
GType gst_tensor_get_type (void);
|
||||||
|
@ -218,10 +218,10 @@ class TestAnalyticsTensorMeta(TestCase):
|
|||||||
self.assertEqual(tensor.num_dims, 4)
|
self.assertEqual(tensor.num_dims, 4)
|
||||||
dims = tensor.get_dims()
|
dims = tensor.get_dims()
|
||||||
self.assertEqual(len(dims), 4)
|
self.assertEqual(len(dims), 4)
|
||||||
self.assertEqual(dims[0].size, 1)
|
self.assertEqual(dims[0], 1)
|
||||||
self.assertEqual(dims[1].size, 2)
|
self.assertEqual(dims[1], 2)
|
||||||
self.assertEqual(dims[2].size, 3)
|
self.assertEqual(dims[2], 3)
|
||||||
self.assertEqual(dims[3].size, 4)
|
self.assertEqual(dims[3], 4)
|
||||||
self.assertEqual(tensor.data, data)
|
self.assertEqual(tensor.data, data)
|
||||||
self.assertEqual(tensor.data_type, GstAnalytics.TensorDataType.UINT8)
|
self.assertEqual(tensor.data_type, GstAnalytics.TensorDataType.UINT8)
|
||||||
self.assertEqual(tensor.dims_order, GstAnalytics.TensorDimOrder.ROW_MAJOR)
|
self.assertEqual(tensor.dims_order, GstAnalytics.TensorDimOrder.ROW_MAJOR)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user