GStreamer plugin to use general neural network frameworks as filters. More...
Go to the source code of this file.
Classes | |
struct | _FilterTransformData |
Internal data structure for tensor_filter transform data. More... | |
Macros | |
#define | EVENT_NAME_UPDATE_MODEL "evt_update_model" |
#define | GST_CAT_DEFAULT gst_tensor_filter_debug |
#define | TF_MODELNAME(prop) ((prop)->model_files ? ((prop)->model_files[0]) : "[No Model File]") |
#define | CAPS_STRING GST_TENSOR_CAP_DEFAULT ";" GST_TENSORS_CAP_MAKE ("{ static, flexible }") |
Default caps string for both sink and source pad. More... | |
#define | gst_tensor_filter_parent_class parent_class |
#define | LATENCY_REPORT_HEADROOM 0.05 |
Headroom (extra duration) added to actual latency estimate reported to LATENCY query, to limit number of updates when tracking the maximum value - arbitrarily set to 5%. More... | |
#define | LATENCY_REPORT_THRESHOLD 0.25 |
Threshold deciding when tracking latency estimate that current value is sufficiently lower than reported value so that a notification update is necessary - arbitrarily set to 25%. More... | |
#define | THRESHOLD_DROP_OLD (2000) |
#define | THRESHOLD_CACHE_OLD (1000) |
Typedefs | |
typedef struct _FilterTransformData | FilterTransformData |
Internal data structure for tensor_filter transform data. More... | |
Functions | |
GST_DEBUG_CATEGORY_STATIC (gst_tensor_filter_debug) | |
G_DEFINE_TYPE (GstTensorFilter, gst_tensor_filter, GST_TYPE_BASE_TRANSFORM) | |
static void | gst_tensor_filter_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) |
Setter for tensor_filter properties. More... | |
static void | gst_tensor_filter_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) |
Getter for tensor_filter properties. More... | |
static void | gst_tensor_filter_finalize (GObject *object) |
Function to finalize instance. More... | |
static GstFlowReturn | gst_tensor_filter_transform (GstBaseTransform *trans, GstBuffer *inbuf, GstBuffer *outbuf) |
non-ip transform. required vmethod of GstBaseTransform. More... | |
static GstCaps * | gst_tensor_filter_transform_caps (GstBaseTransform *trans, GstPadDirection direction, GstCaps *caps, GstCaps *filter) |
configure tensor-srcpad cap from "proposed" cap. More... | |
static GstCaps * | gst_tensor_filter_fixate_caps (GstBaseTransform *trans, GstPadDirection direction, GstCaps *caps, GstCaps *othercaps) |
fixate caps. required vmethod of GstBaseTransform. More... | |
static gboolean | gst_tensor_filter_set_caps (GstBaseTransform *trans, GstCaps *incaps, GstCaps *outcaps) |
set caps. required vmethod of GstBaseTransform. More... | |
static gboolean | gst_tensor_filter_query (GstBaseTransform *trans, GstPadDirection direction, GstQuery *query) |
query handling, optional vmethod of GstBaseTransform. More... | |
static gboolean | gst_tensor_filter_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. optional vmethod of BaseTransform. More... | |
static gboolean | gst_tensor_filter_start (GstBaseTransform *trans) |
Called when the element starts processing. optional vmethod of BaseTransform. More... | |
static gboolean | gst_tensor_filter_stop (GstBaseTransform *trans) |
Called when the element stops processing. optional vmethod of BaseTransform. More... | |
static gboolean | gst_tensor_filter_sink_event (GstBaseTransform *trans, GstEvent *event) |
Event handler for sink pad of tensor filter. More... | |
static gboolean | gst_tensor_filter_src_event (GstBaseTransform *trans, GstEvent *event) |
Event handler for src pad of tensor filter. More... | |
static void | gst_tensor_filter_class_init (GstTensorFilterClass *klass) |
initialize the tensor_filter's class More... | |
static void | gst_tensor_filter_init (GstTensorFilter *self) |
initialize the new element instantiate pads and add them to element set pad callback functions initialize instance structure More... | |
static gsize | gst_tensor_filter_get_tensor_size (GstTensorFilter *self, guint index, gboolean is_input) |
Calculate tensor buffer size. More... | |
static void | gst_tensor_filter_destroy_notify (void *data) |
Free the data allocated for tensor transform. More... | |
static GstMemory * | gst_tensor_filter_get_wrapped_mem (GstTensorFilter *self, gpointer data, gsize size) |
Allocate new memory block from given data. More... | |
static void | prepare_statistics (GstTensorFilterPrivate *priv) |
Prepare statistics for performance profiling (e.g, latency, throughput) More... | |
static void | accumulate_latency (void *data, void *user_data) |
Helper function to accumulate latencies. More... | |
static void | record_statistics (GstTensorFilterPrivate *priv) |
Record statistics for performance profiling (e.g, latency, throughput) More... | |
static void | track_latency (GstTensorFilter *self) |
Track estimated latency and notify pipeline when it changes. Latency estimates may be a bit jittery. On the principle we want to inform pipeline with the latency from longest inference. However, first inference may take much longer, or model filter configuration may change. Therefore any change of more than 10% (arbitrary value) to a lower latency is also reported to pipeline. Notification is done sending LATENCY message to bus. Upon receipt, application will initiate a pipeline latency probe via LATENCY query. More... | |
static gboolean | gst_tensor_filter_check_throttling_delay (GstBaseTransform *trans, GstBuffer *inbuf) |
Check throttling delay and send qos overflow event to upstream elements. More... | |
static GstFlowReturn | _gst_tensor_filter_transform_validate (GstBaseTransform *trans, GstBuffer *inbuf, GstBuffer *outbuf) |
Check input parameters for gst_tensor_filter_transform ();. More... | |
static void | _gst_tensor_filter_release_mem_until_idx (FilterTransformData *trans_data, guint end_index) |
Internal function to release mem and unmap info with index. More... | |
static gsize | _gst_tensor_filter_convert_meta (FilterTransformData *trans_data, GstTensorsInfo *info, guint idx) |
Internal function to convert tensor meta and get header size of flexible tensor. More... | |
static FilterTransformData * | _gst_tensor_filter_transform_get_all_input_data (GstBaseTransform *trans, GstBuffer *buf) |
Internal function to get input tensors. More... | |
static GstTensorMemory * | _gst_tensor_filter_transform_get_invoke_tensors (GstBaseTransform *trans, FilterTransformData *trans_data) |
Internal function to get invoke tensors. More... | |
static FilterTransformData * | _gst_tensor_filter_transform_get_output_data (GstBaseTransform *trans) |
Internal function to get output tensors. More... | |
static GstFlowReturn | _gst_tensor_filter_transform_prepare_output_tensors (GstBaseTransform *trans, FilterTransformData *trans_data) |
Internal function to get output tensors. More... | |
static GstFlowReturn | _gst_tensor_filter_transform_check_invoke_result (GstBaseTransform *trans, FilterTransformData *in_trans_data, FilterTransformData *out_trans_data, gint invoke_res) |
Internal function to check the invoke result. More... | |
static void | _gst_tensor_filter_transform_update_outbuf (GstBaseTransform *trans, FilterTransformData *in_trans_data, FilterTransformData *out_trans_data, GstBuffer *outbuf) |
Internal function to make output buffer. More... | |
static gboolean | gst_tensor_filter_watchdog_trigger (gpointer ptr) |
Called when there is no input within suspend time specified by the user. More... | |
static gboolean | gst_tensor_filter_configure_tensor (GstTensorFilter *self, const GstCaps *incaps) |
Configure input and output tensor info from incaps. More... | |
Variables | |
static GstStaticPadTemplate | sink_factory |
The capabilities of the inputs. More... | |
static GstStaticPadTemplate | src_factory |
The capabilities of the outputs. More... | |
GStreamer plugin to use general neural network frameworks as filters.
GStreamer Tensor_Filter 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.
set priority among properties
logic for dynamic properties(like model change)
This is the main plugin for per-NN-framework plugins. Specific implementations for each NN framework must be written in each framework specific files; e.g., tensor_filter_tensorflow_lite.c
Definition in file tensor_filter.c.
#define CAPS_STRING GST_TENSOR_CAP_DEFAULT ";" GST_TENSORS_CAP_MAKE ("{ static, flexible }") |
Default caps string for both sink and source pad.
Definition at line 87 of file tensor_filter.c.
#define EVENT_NAME_UPDATE_MODEL "evt_update_model" |
SECTION:element-tensor_filter
A plugin that invokes neural network models and their framework or an independent shared object implementing tensor_filter_custom.h. The input and output are always in the format of other/tensor or other/tensors.
<refsect2> <title>Example launch line</title> |[ gst-launch -v -m fakesrc ! tensor_filter framework=tensorflow-lite, model=./inception_v3.pb, input=3:224:224, output=1000 ! fakesink silent=TRUE ]| </refsect2>
If input is other/tensor C array input[1][224][224][3] and output is other/tensor C array output[1][1][1][1000]
The current QoS policy: In a nnstreamer pipeline, the QoS is currently satisfied by adjusting a input or output framerate, initiated by 'tensor_rate' element. When 'tensor_filter' receives a throttling QoS event from the 'tensor_rate' element, it compares the average processing latency and throttling delay, and takes the maximum value as the threshold to drop incoming frames by checking a buffer timestamp. In this way, 'tensor filter' can avoid unnecessary calculation and adjust a framerate, effectively reducing resource utilizations. Even in the case of receiving QoS events from multiple downstream pipelines (e.g., tee), 'tensor_filter' takes the minimum value as the throttling delay for downstream pipeline with more tight QoS requirement. Lastly, 'tensor_filter' also sends QoS events to upstream elements (e.g., tensor_converter, tensor_src) to possibly reduce incoming framerates, which is a better solution than dropping framerates.
Definition at line 76 of file tensor_filter.c.
#define GST_CAT_DEFAULT gst_tensor_filter_debug |
Definition at line 79 of file tensor_filter.c.
#define gst_tensor_filter_parent_class parent_class |
Definition at line 105 of file tensor_filter.c.
#define LATENCY_REPORT_HEADROOM 0.05 |
Headroom (extra duration) added to actual latency estimate reported to LATENCY query, to limit number of updates when tracking the maximum value - arbitrarily set to 5%.
Definition at line 113 of file tensor_filter.c.
#define LATENCY_REPORT_THRESHOLD 0.25 |
Threshold deciding when tracking latency estimate that current value is sufficiently lower than reported value so that a notification update is necessary - arbitrarily set to 25%.
Definition at line 120 of file tensor_filter.c.
Definition at line 81 of file tensor_filter.c.
#define THRESHOLD_CACHE_OLD (1000) |
Definition at line 406 of file tensor_filter.c.
#define THRESHOLD_DROP_OLD (2000) |
Definition at line 405 of file tensor_filter.c.
typedef struct _FilterTransformData FilterTransformData |
Internal data structure for tensor_filter transform data.
|
static |
Internal function to convert tensor meta and get header size of flexible tensor.
Definition at line 684 of file tensor_filter.c.
|
static |
Internal function to release mem and unmap info with index.
Definition at line 667 of file tensor_filter.c.
|
static |
Internal function to check the invoke result.
Definition at line 936 of file tensor_filter.c.
|
static |
Internal function to get input tensors.
Definition at line 707 of file tensor_filter.c.
|
static |
Internal function to get invoke tensors.
Definition at line 754 of file tensor_filter.c.
|
static |
Internal function to get output tensors.
Definition at line 836 of file tensor_filter.c.
|
static |
Internal function to get output tensors.
Definition at line 870 of file tensor_filter.c.
|
static |
Internal function to make output buffer.
Definition at line 976 of file tensor_filter.c.
|
static |
Check input parameters for gst_tensor_filter_transform ();.
This is fatal; if framework is not configured until this stage, it means that an extension is missing or not configured. We need readable messages for non-developers
Definition at line 593 of file tensor_filter.c.
|
static |
Helper function to accumulate latencies.
Definition at line 397 of file tensor_filter.c.
G_DEFINE_TYPE | ( | GstTensorFilter | , |
gst_tensor_filter | , | ||
GST_TYPE_BASE_TRANSFORM | |||
) |
GST_DEBUG_CATEGORY_STATIC | ( | gst_tensor_filter_debug | ) |
|
static |
Check throttling delay and send qos overflow event to upstream elements.
Send qos overflow event to upstream elements. Upstream elements (e.g., tensor_src, tensor_converter) may handle this.
Definition at line 536 of file tensor_filter.c.
|
static |
initialize the tensor_filter's class
Definition at line 169 of file tensor_filter.c.
|
static |
Configure input and output tensor info from incaps.
self | "this" pointer |
incaps | received caps for sink pad |
GstTensorFilter has to parse the tensor dimension and type from NN model.
Check configuration from caps. If true, fully configured tensor info from caps.
if set-property called and already has info, verify it!
If incoming tensor is flexible, we cannot validate tensor info here. Need to compare buffer size in transform().
call setInputDimension if output tensor is not configured
if set-property called and already has info, verify it!
already configured, compare to old.
Definition at line 1207 of file tensor_filter.c.
|
static |
Free the data allocated for tensor transform.
default function for tensor filter framework if not provided by the framework. The data is in GPtrArray - first element is private data of framework and second element is the data to be freed.
Definition at line 357 of file tensor_filter.c.
|
static |
Function to finalize instance.
Definition at line 249 of file tensor_filter.c.
|
static |
fixate caps. required vmethod of GstBaseTransform.
Removes no-used-variable warning for priv in when DBG is set
To get the out-caps, GstTensorFilter has to parse tensor info from NN model.
Definition at line 1528 of file tensor_filter.c.
|
static |
Getter for tensor_filter properties.
Definition at line 330 of file tensor_filter.c.
|
static |
Calculate tensor buffer size.
self | "this" pointer |
index | index of tensors |
Definition at line 277 of file tensor_filter.c.
|
static |
Allocate new memory block from given data.
tensor-filter should send event to sub-plugin when memory is freed.
Definition at line 372 of file tensor_filter.c.
|
static |
initialize the new element instantiate pads and add them to element set pad callback functions initialize instance structure
Definition at line 234 of file tensor_filter.c.
|
static |
query handling, optional vmethod of GstBaseTransform.
Definition at line 1623 of file tensor_filter.c.
|
static |
set caps. required vmethod of GstBaseTransform.
compare output tensor
Definition at line 1563 of file tensor_filter.c.
|
static |
Setter for tensor_filter properties.
Definition at line 304 of file tensor_filter.c.
|
static |
Event handler for sink pad of tensor filter.
trans | "this" pointer |
event | a passed event object |
other events are handled in the default event handler
Definition at line 1723 of file tensor_filter.c.
|
static |
Event handler for src pad of tensor filter.
trans | "this" pointer |
event | a passed event object |
other events are handled in the default event handler
Definition at line 1764 of file tensor_filter.c.
|
static |
Called when the element starts processing. optional vmethod of BaseTransform.
trans | "this" pointer |
Definition at line 1802 of file tensor_filter.c.
|
static |
Called when the element stops processing. optional vmethod of BaseTransform.
trans | "this" pointer |
Definition at line 1836 of file tensor_filter.c.
|
static |
non-ip transform. required vmethod of GstBaseTransform.
Reset suspend timeout
Set suspend timeout
Definition at line 1097 of file tensor_filter.c.
|
static |
configure tensor-srcpad cap from "proposed" cap.
@trans ("this" pointer) @direction (why do we need this?) @caps sinkpad cap (if direction GST_PAD_SINK) @filter this element's cap (don't know specifically.)
Be careful not to fix/set caps at this stage. Negotiation not completed yet.
GstTensorFilter has to parse the tensor dimension and type from NN model. In this stage, in-caps may not be fixed yet. To get the tensor info and generate pad-caps, call getInputDimension and getOutputDimension. If these functions are not defined, we have to call setInputDimension, and then it will fully configure the tensor info.
Definition at line 1405 of file tensor_filter.c.
|
static |
Tell the framework the required size of buffer based on the info of the other side pad. optional vmethod of BaseTransform.
We cannot directly get the value from size value, we need to review the pad-caps. This is called when non-ip mode is used.
Internal Logic Error. Cannot proceed without configured pipeline
Consider multi-tensors. Set each memory block in transform()
Definition at line 1694 of file tensor_filter.c.
|
static |
Called when there is no input within suspend time specified by the user.
Definition at line 1083 of file tensor_filter.c.
|
static |
Prepare statistics for performance profiling (e.g, latency, throughput)
Definition at line 388 of file tensor_filter.c.
|
static |
Record statistics for performance profiling (e.g, latency, throughput)
statistics values are monotonously increasing. to avoid potential overflow, let's cache old values and subtract them from the statistics if some threshold is exceeded.
Definition at line 412 of file tensor_filter.c.
|
static |
Track estimated latency and notify pipeline when it changes. Latency estimates may be a bit jittery. On the principle we want to inform pipeline with the latency from longest inference. However, first inference may take much longer, or model filter configuration may change. Therefore any change of more than 10% (arbitrary value) to a lower latency is also reported to pipeline. Notification is done sending LATENCY message to bus. Upon receipt, application will initiate a pipeline latency probe via LATENCY query.
Definition at line 503 of file tensor_filter.c.
|
static |
The capabilities of the inputs.
Definition at line 92 of file tensor_filter.c.
|
static |
The capabilities of the outputs.
Definition at line 100 of file tensor_filter.c.