mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-22 09:41:07 +00:00
analytics: Adding abstraction on tensor dims
Tensor can be row or col major, but it's also possible that the order by we need to read the tensor with more than two dimension need to be described. The reserved field in GstTensorDim is there for this purpose. If we need this we can add GST_TENSOR_DIM_ORDER_INDEXED, and follow an index defining order for each dimension. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6000>
This commit is contained in:
parent
8169863f01
commit
6a5a63f051
3 changed files with 32 additions and 10 deletions
|
@ -353,7 +353,7 @@ GstOnnxClient::GstOnnxClient (GstElement *debug_parent):debug_parent(debug_paren
|
||||||
tensor->batch_size = 1;
|
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] = tensorShape[j];
|
tensor->dims[j].size = 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 (gsize) * num_dims))
|
(sizeof (GstTensor) + (sizeof (GstTensorDim) * 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);
|
||||||
|
|
|
@ -73,15 +73,21 @@ 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.
|
* Indicate to read tensor from memory in row-major or column-major order.
|
||||||
*
|
*
|
||||||
* Since: 1.26
|
* Since: 1.26
|
||||||
*/
|
*/
|
||||||
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -97,16 +103,32 @@ typedef enum _GstTensorLayout
|
||||||
GST_TENSOR_LAYOUT_STRIDED
|
GST_TENSOR_LAYOUT_STRIDED
|
||||||
} GstTensorLayout;
|
} GstTensorLayout;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GstTensorDim:
|
||||||
|
* @size: Size of the dimension
|
||||||
|
* @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
|
||||||
* @num_dims: number of tensor dimensions
|
|
||||||
* @dims: tensor dimensions
|
|
||||||
* @dims_order: Indicate tensor elements layout in memory.
|
|
||||||
* @layout: Indicate tensor layout
|
* @layout: Indicate tensor layout
|
||||||
* @type: #GstTensorDataType of tensor data
|
* @data_type: #GstTensorDataType of tensor data
|
||||||
* @batch_size: Model batch size
|
* @batch_size: Model batch size
|
||||||
* @data: #GstBuffer holding tensor data
|
* @data: #GstBuffer holding tensor data
|
||||||
|
* @dims_order: Indicate tensor elements layout in memory.
|
||||||
|
* @num_dims: number of tensor dimensions
|
||||||
|
* @dims: (array length=num_dims): number of tensor dimensions
|
||||||
*
|
*
|
||||||
* Hold tensor data
|
* Hold tensor data
|
||||||
*
|
*
|
||||||
|
@ -115,13 +137,13 @@ typedef enum _GstTensorLayout
|
||||||
typedef struct _GstTensor
|
typedef struct _GstTensor
|
||||||
{
|
{
|
||||||
GQuark id;
|
GQuark id;
|
||||||
GstTensorDimOrder dims_order;
|
|
||||||
GstTensorLayout layout;
|
GstTensorLayout layout;
|
||||||
GstTensorDataType data_type;
|
GstTensorDataType data_type;
|
||||||
gsize batch_size;
|
gsize batch_size;
|
||||||
GstBuffer *data;
|
GstBuffer *data;
|
||||||
|
GstTensorDimOrder dims_order;
|
||||||
gsize num_dims;
|
gsize num_dims;
|
||||||
gsize dims[];
|
GstTensorDim dims[];
|
||||||
} GstTensor;
|
} GstTensor;
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
Loading…
Reference in a new issue