GStreamer plugin to transform tensor dimension or type. More...
#include <string.h>
#include <math.h>
#include <nnstreamer_log.h>
#include <nnstreamer_util.h>
#include "gsttensor_transform.h"
Go to the source code of this file.
Macros | |
#define | DBG (!filter->silent) |
Macro for debug mode. More... | |
#define | GST_CAT_DEFAULT gst_tensor_transform_debug |
#define | CAPS_STRING GST_TENSOR_CAP_DEFAULT ";" GST_TENSORS_CAP_MAKE ("{ static, flexible }") |
#define | REGEX_DIMCHG_OPTION "^([0-9]|1[0-5]):([0-9]|1[0-5])$" |
#define | REGEX_TYPECAST_OPTION "(^[u]?int(8|16|32|64)$|^float(16|32|64)$)" |
#define | REGEX_TRANSPOSE_OPTION "^(?:([0-2]):(?!.*\\1)){3}3$" |
#define | REGEX_STAND_OPTION "^(default|dc-average)(:([u]?int(8|16|32|64)|float(16|32|64)))?(,per-channel:(true|false))?$" |
#define | REGEX_CLAMP_OPTION |
#define | REGEX_PADDING_OPTION "^((left|right|top|bottom|front|back):(\\d)(,)?)+(layout:(NCHW|NHWC))?$" |
#define | REGEX_ARITH_OPTION |
#define | REGEX_ARITH_OPTION_TYPECAST "(typecast:([u]?int(8|16|32|64)|float(16|32|64)))" |
#define | NNS_TENSOR_TRANSPOSE_RANK_LIMIT (4) |
The transpose rank is fixed to 4. This RANK does not affect other/tensors(s)'s NNS_TENSOR_RANK_LIMIT. More... | |
#define | NNS_TENSOR_PADDING_RANK_LIMIT (3) |
The padding rank is fixed to 3. This RANK does not affect other/tensors(s)'s NNS_TENSOR_RANK_LIMIT. More... | |
#define | DEFAULT_ACCELERATION FALSE |
Flag to set orc acceleration. More... | |
#define | gst_tensor_transform_parent_class parent_class |
#define | GST_TYPE_TENSOR_TRANSFORM_MODE (gst_tensor_transform_mode_get_type ()) |
#define | _conv_to_f16(intype, o, i, n) do { float16_not_supported (); } while (0) |
#define | _conv_from_f16(otype, o, i, n) do { float16_not_supported (); } while (0) |
#define | _op_float16(i, n, v, op) do { float16_not_supported (); } while (0) |
#define | handle_operator(d, v, oper, vtype) |
Macro for operator. More... | |
#define | transposeloop(cl, ck, cj, ci, sl, sk, sj, si, typesize) |
Enumerations | |
enum | { PROP_0, PROP_SILENT, PROP_MODE, PROP_OPTION, PROP_ACCELERATION, PROP_APPLY, PROP_TRANSPOSE_RANK_LIMIT } |
tensor_transform properties More... | |
Functions | |
GST_DEBUG_CATEGORY_STATIC (gst_tensor_transform_debug) | |
G_DEFINE_TYPE (GstTensorTransform, gst_tensor_transform, GST_TYPE_BASE_TRANSFORM) | |
static void | gst_tensor_transform_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) |
Set property (gst element vmethod) More... | |
static void | gst_tensor_transform_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) |
Get property (gst element vmethod) More... | |
static void | gst_tensor_transform_finalize (GObject *object) |
Function to finalize instance (gst element vmethod) More... | |
static GstFlowReturn | gst_tensor_transform_transform (GstBaseTransform *trans, GstBuffer *inbuf, GstBuffer *outbuf) |
non-ip transform. required vmethod for BaseTransform class. More... | |
static GstCaps * | gst_tensor_transform_transform_caps (GstBaseTransform *trans, GstPadDirection direction, GstCaps *caps, GstCaps *filtercap) |
configure srcpad cap from "proposed" cap. (required vmethod for BaseTransform) More... | |
static GstCaps * | gst_tensor_transform_fixate_caps (GstBaseTransform *trans, GstPadDirection direction, GstCaps *caps, GstCaps *othercaps) |
fixate caps. required vmethod of BaseTransform More... | |
static gboolean | gst_tensor_transform_set_caps (GstBaseTransform *trans, GstCaps *incaps, GstCaps *outcaps) |
set caps. required vmethod of BaseTransform More... | |
static gboolean | gst_tensor_transform_transform_size (GstBaseTransform *trans, GstPadDirection direction, GstCaps *caps, gsize size, GstCaps *othercaps, gsize *othersize) |
Tell the framework the required size of buffer based on the info of the other side pad. Note that this is always the same with the input. optional vmethod of BaseTransform. More... | |
static gboolean | gst_tensor_transform_convert_dimension (GstTensorTransform *filter, GstPadDirection direction, guint idx, const GstTensorInfo *in_info, GstTensorInfo *out_info) |
Dimension conversion calculation. More... | |
static GType | gst_tensor_transform_mode_get_type (void) |
A private function to register GEnumValue array for the 'mode' property to a GType and return it. More... | |
static void | gst_tensor_transform_class_init (GstTensorTransformClass *klass) |
initialize the tensor_transform's class More... | |
static void | gst_tensor_transform_init (GstTensorTransform *filter) |
initialize the new element (G_DEFINE_TYPE requires this) instantiate pads and add them to element set pad callback functions initialize instance structure More... | |
static tensor_transform_operator | gst_tensor_transform_get_operator (const gchar *str) |
Get the corresponding operator from the string value. More... | |
static tensor_transform_stand_mode | gst_tensor_transform_get_stand_mode (const gchar *str) |
Get the corresponding mode from the string value. More... | |
static void | float16_not_supported (void) |
Generate error if float16 is required. More... | |
while (0) | |
static gboolean | gst_tensor_transform_set_option_data (GstTensorTransform *filter) |
Setup internal data (data_* in GstTensorTransform) More... | |
static GstFlowReturn | gst_tensor_transform_dimchg (GstTensorTransform *filter, GstTensorInfo *in_info, GstTensorInfo *out_info, const uint8_t *inptr, uint8_t *outptr) |
subrouting for tensor-transform, "dimchg" case. More... | |
static GstFlowReturn | gst_tensor_transform_typecast (GstTensorTransform *filter, GstTensorInfo *in_info, GstTensorInfo *out_info, const uint8_t *inptr, uint8_t *outptr) |
subrouting for tensor-transform, "typecast" case. More... | |
static GstFlowReturn | gst_tensor_transform_arithmetic (GstTensorTransform *filter, GstTensorInfo *in_info, GstTensorInfo *out_info, const uint8_t *inptr, uint8_t *outptr) |
subrouting for tensor-transform, "arithmetic" case. More... | |
static GstFlowReturn | gst_tensor_transform_transpose (GstTensorTransform *filter, GstTensorInfo *in_info, GstTensorInfo *out_info, const uint8_t *inptr, uint8_t *outptr) |
subrouting for tensor-transform, "transpose" case. More... | |
static GstFlowReturn | gst_tensor_transform_stand (GstTensorTransform *filter, GstTensorInfo *in_info, GstTensorInfo *out_info, const uint8_t *inptr, uint8_t *outptr) |
subrouting for tensor-transform, "stand" case. : pixel = abs((pixel - average(tensor))/(std(tensor) + val)) More... | |
static GstFlowReturn | gst_tensor_transform_clamp (GstTensorTransform *filter, GstTensorInfo *in_info, GstTensorInfo *out_info, const uint8_t *inptr, uint8_t *outptr) |
subrouting for tensor-transform, "clamp" case. : pixel = if (pixel > max) ? max : if (pixel < min) ? min : pixel More... | |
static GstFlowReturn | gst_tensor_transform_padding (GstTensorTransform *filter, GstTensorInfo *in_info, GstTensorInfo *out_info, const uint8_t *inptr, uint8_t *outptr) |
subrouting for tensor-transform, "padding" case. More... | |
static gboolean | gst_tensor_transform_read_caps (GstTensorTransform *filter, const GstCaps *caps, GstTensorsConfig *config) |
Read cap, parse tensor configuration (dim/type) from the cap. More... | |
Variables | |
static const gchar * | gst_tensor_transform_stand_string [] |
static const gchar * | gst_tensor_transform_operator_string [] |
static GstStaticPadTemplate | sink_factory |
The capabilities of the inputs. More... | |
static GstStaticPadTemplate | src_factory |
The capabilities of the outputs. More... | |
break | |
vtype += (v)->data._##vtype; \ More... | |
case | GTT_OP_MUL |
default | __pad0__ |
default Unknown | operator%d", oper) |
return | FALSE |
GStreamer plugin to transform tensor dimension or type.
GStreamer Copyright (C) 2005 Thomas Vander Stichele thoma Copyright (C) 2005 Ronald S. Bultje s@ap estaa rt.o rgrbult Copyright (C) 2018 MyungJoo Ham je@r onald .bit freak .netmyung joo. ham@s amsu ng.co m
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; version 2.1 of the License.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details.
Definition in file gsttensor_transform.c.
#define _conv_from_f16 | ( | otype, | |
o, | |||
i, | |||
n | |||
) | do { float16_not_supported (); } while (0) |
Definition at line 465 of file gsttensor_transform.c.
#define _conv_to_f16 | ( | intype, | |
o, | |||
i, | |||
n | |||
) | do { float16_not_supported (); } while (0) |
Definition at line 464 of file gsttensor_transform.c.
#define _op_float16 | ( | i, | |
n, | |||
v, | |||
op | |||
) | do { float16_not_supported (); } while (0) |
Definition at line 466 of file gsttensor_transform.c.
#define CAPS_STRING GST_TENSOR_CAP_DEFAULT ";" GST_TENSORS_CAP_MAKE ("{ static, flexible }") |
Definition at line 69 of file gsttensor_transform.c.
#define DBG (!filter->silent) |
Macro for debug mode.
SECTION:element-tensor_transform
A filter that transforms tensors dimension or type. The input and output is always in the format of other/tensor or other/tensors.
<refsect2> <title>Example launch line</title> |[ gst-launch -v -m fakesrc ! tensor_converter ! tensor_transform mode=dimchg option=0:2 ! fakesink silent=TRUE ]| <title>How to use dimchg</title> |[ option=0:2 # Move 0th dim to 2nd dim. I.e., [a][H][W][C] ==> [a][C][H][W] ]| </refsect2>
Definition at line 64 of file gsttensor_transform.c.
#define DEFAULT_ACCELERATION FALSE |
Flag to set orc acceleration.
Definition at line 115 of file gsttensor_transform.c.
#define GST_CAT_DEFAULT gst_tensor_transform_debug |
Definition at line 68 of file gsttensor_transform.c.
#define gst_tensor_transform_parent_class parent_class |
Definition at line 148 of file gsttensor_transform.c.
#define GST_TYPE_TENSOR_TRANSFORM_MODE (gst_tensor_transform_mode_get_type ()) |
Definition at line 176 of file gsttensor_transform.c.
#define handle_operator | ( | d, | |
v, | |||
oper, | |||
vtype | |||
) |
Macro for operator.
Definition at line 573 of file gsttensor_transform.c.
#define NNS_TENSOR_PADDING_RANK_LIMIT (3) |
The padding rank is fixed to 3. This RANK does not affect other/tensors(s)'s NNS_TENSOR_RANK_LIMIT.
Definition at line 93 of file gsttensor_transform.c.
#define NNS_TENSOR_TRANSPOSE_RANK_LIMIT (4) |
The transpose rank is fixed to 4. This RANK does not affect other/tensors(s)'s NNS_TENSOR_RANK_LIMIT.
Definition at line 87 of file gsttensor_transform.c.
#define REGEX_ARITH_OPTION |
Definition at line 77 of file gsttensor_transform.c.
#define REGEX_ARITH_OPTION_TYPECAST "(typecast:([u]?int(8|16|32|64)|float(16|32|64)))" |
Definition at line 81 of file gsttensor_transform.c.
#define REGEX_CLAMP_OPTION |
Definition at line 74 of file gsttensor_transform.c.
#define REGEX_DIMCHG_OPTION "^([0-9]|1[0-5]):([0-9]|1[0-5])$" |
Definition at line 70 of file gsttensor_transform.c.
#define REGEX_PADDING_OPTION "^((left|right|top|bottom|front|back):(\\d)(,)?)+(layout:(NCHW|NHWC))?$" |
Definition at line 76 of file gsttensor_transform.c.
#define REGEX_STAND_OPTION "^(default|dc-average)(:([u]?int(8|16|32|64)|float(16|32|64)))?(,per-channel:(true|false))?$" |
Definition at line 73 of file gsttensor_transform.c.
#define REGEX_TRANSPOSE_OPTION "^(?:([0-2]):(?!.*\\1)){3}3$" |
Definition at line 72 of file gsttensor_transform.c.
#define REGEX_TYPECAST_OPTION "(^[u]?int(8|16|32|64)$|^float(16|32|64)$)" |
Definition at line 71 of file gsttensor_transform.c.
#define transposeloop | ( | cl, | |
ck, | |||
cj, | |||
ci, | |||
sl, | |||
sk, | |||
sj, | |||
si, | |||
typesize | |||
) |
Macro to run loop for various data types with transpose
Definition at line 1506 of file gsttensor_transform.c.
anonymous enum |
tensor_transform properties
Enumerator | |
---|---|
PROP_0 | |
PROP_SILENT | |
PROP_MODE | |
PROP_OPTION | |
PROP_ACCELERATION | |
PROP_APPLY | |
PROP_TRANSPOSE_RANK_LIMIT |
Definition at line 98 of file gsttensor_transform.c.
|
static |
Generate error if float16 is required.
Definition at line 348 of file gsttensor_transform.c.
G_DEFINE_TYPE | ( | GstTensorTransform | , |
gst_tensor_transform | , | ||
GST_TYPE_BASE_TRANSFORM | |||
) |
GST_DEBUG_CATEGORY_STATIC | ( | gst_tensor_transform_debug | ) |
|
static |
subrouting for tensor-transform, "arithmetic" case.
[in/out] | filter "this" pointer | |
[in] | in_info | input tensor info |
[in] | out_info | output tensor info |
[in] | inptr | input tensor |
[out] | outptr | output tensor |
In case of 3:4:4:1, ch_dim:0 -> #ch: 3, ch_size: 1, ch_offset: 3 ch_dim:1 -> #ch: 4, ch_size: 3, ch_offset: 12 ch_dim:2 -> #ch: 4, ch_size: 12, ch_offset: 48 ch_dim:3 -> #ch: 1, ch_size: 48, ch_offset: 48 * 4
Definition at line 1330 of file gsttensor_transform.c.
|
static |
subrouting for tensor-transform, "clamp" case. : pixel = if (pixel > max) ? max : if (pixel < min) ? min : pixel
[in/out] | filter "this" pointer | |
[in] | in_info | input tensor info |
[in] | out_info | output tensor info |
[in] | inptr | input tensor |
[out] | outptr | output tensor |
Definition at line 1725 of file gsttensor_transform.c.
|
static |
initialize the tensor_transform's class
Definition at line 224 of file gsttensor_transform.c.
|
static |
Dimension conversion calculation.
[in] | filter | "this" pointer |
[in] | direction | GST_PAD_SINK if input->output conv |
[in] | idx | index of the input tensors |
[in] | in_info | tensor info structure of source tensor (input if direction is SINK) |
[out] | out_info | tensor info structure of destination tensor (output if direction is SINK) |
For both directions, dimension does not change
src = SINKPAD / dest = SRCPAD
For both directions, dimension does not change
Definition at line 2005 of file gsttensor_transform.c.
|
static |
subrouting for tensor-transform, "dimchg" case.
[in/out] | filter "this" pointer | |
[in] | in_info | input tensor info |
[in] | out_info | output tensor info |
[in] | inptr | input tensor |
[out] | outptr | output tensor |
Useless memcpy. Do not call this or
Smaller-loop-ed a to larger-loop-ed b E.g., [N][H][W][c] (c:W:H:N) --> [N][c][H][W] (W:H:c:N)
Larger-loop-ed a to smaller-loop-ed b E.g., [N][c][H][W] (W:H:c:N) --> [N][H][W][c] (c:W:H:N)
Definition at line 1197 of file gsttensor_transform.c.
|
static |
Function to finalize instance (gst element vmethod)
Definition at line 1163 of file gsttensor_transform.c.
|
static |
fixate caps. required vmethod of BaseTransform
Definition at line 2222 of file gsttensor_transform.c.
|
static |
Get the corresponding operator from the string value.
[in] | str | The string value for the operator |
Definition at line 319 of file gsttensor_transform.c.
|
static |
Get property (gst element vmethod)
Definition at line 1107 of file gsttensor_transform.c.
|
static |
Get the corresponding mode from the string value.
[in] | str | The string value for the mode |
Definition at line 334 of file gsttensor_transform.c.
|
static |
initialize the new element (G_DEFINE_TYPE requires this) instantiate pads and add them to element set pad callback functions initialize instance structure
Definition at line 299 of file gsttensor_transform.c.
|
static |
A private function to register GEnumValue array for the 'mode' property to a GType and return it.
Definition at line 182 of file gsttensor_transform.c.
|
static |
subrouting for tensor-transform, "padding" case.
[in/out] | filter "this" pointer | |
[in] | in_info | input tensor info |
[in] | out_info | output tensor info |
[in] | inptr | input tensor |
[out] | outptr | output tensor |
Definition at line 1762 of file gsttensor_transform.c.
|
static |
Read cap, parse tensor configuration (dim/type) from the cap.
[in] | filter | "this" pointer |
[in] | caps | The input caps to be read |
[out] | config | configured tensor info |
Definition at line 1978 of file gsttensor_transform.c.
|
static |
set caps. required vmethod of BaseTransform
Definition at line 2249 of file gsttensor_transform.c.
|
static |
Setup internal data (data_* in GstTensorTransform)
[in/out] | filter "this" pointer. mode & option MUST BE set already. |
TRUE | if OK or operation-skipped, FALSE if fatal-error. |
Definition at line 663 of file gsttensor_transform.c.
|
static |
Set property (gst element vmethod)
Definition at line 1040 of file gsttensor_transform.c.
|
static |
subrouting for tensor-transform, "stand" case. : pixel = abs((pixel - average(tensor))/(std(tensor) + val))
[in/out] | filter "this" pointer | |
[in] | in_info | input tensor info |
[in] | out_info | output tensor info |
[in] | inptr | input tensor |
[out] | outptr | output tensor |
Definition at line 1605 of file gsttensor_transform.c.
|
static |
non-ip transform. required vmethod for BaseTransform class.
[in/out] | trans "super" pointer | |
[in] | inbuf | The input gst buffer |
[out] | outbuf | The output gst buffer |
Definition at line 1815 of file gsttensor_transform.c.
|
static |
configure srcpad cap from "proposed" cap. (required vmethod for BaseTransform)
trans | ("this" pointer) |
direction | (why do we need this?) |
caps | sinkpad cap |
filtercap | this element's cap (don't know specifically.) |
Definition at line 2139 of file gsttensor_transform.c.
|
static |
Tell the framework the required size of buffer based on the info of the other side pad. Note that this is always the same with the input. optional vmethod of BaseTransform.
Consider multi-tensors. Set each memory block in transform()
Definition at line 2329 of file gsttensor_transform.c.
|
static |
subrouting for tensor-transform, "transpose" case.
[in/out] | filter "this" pointer | |
[in] | in_info | input tensor info |
[in] | out_info | output tensor info |
[in] | inptr | input tensor |
[out] | outptr | output tensor |
Definition at line 1533 of file gsttensor_transform.c.
|
static |
subrouting for tensor-transform, "typecast" case.
[in/out] | filter "this" pointer | |
[in] | in_info | input tensor info |
[in] | out_info | output tensor info |
[in] | inptr | input tensor |
[out] | outptr | output tensor |
Definition at line 1292 of file gsttensor_transform.c.
while | ( | 0 | ) |
default __pad0__ |
Definition at line 589 of file gsttensor_transform.c.
d data _ break |
vtype += (v)->data._##vtype; \
vtype /= (v)->data._##vtype; \
Definition at line 577 of file gsttensor_transform.c.
return FALSE |
Definition at line 590 of file gsttensor_transform.c.
|
static |
Definition at line 124 of file gsttensor_transform.c.
|
static |
Definition at line 118 of file gsttensor_transform.c.
case GTT_OP_MUL |
Definition at line 584 of file gsttensor_transform.c.
default Unknown operator%d", oper) |
Definition at line 589 of file gsttensor_transform.c.
|
static |
The capabilities of the inputs.
Definition at line 135 of file gsttensor_transform.c.
|
static |
The capabilities of the outputs.
Definition at line 143 of file gsttensor_transform.c.