GStreamer plugin to train tensor data using NN Frameworks. More...
#include <stdlib.h>
#include <nnstreamer_subplugin.h>
#include <nnstreamer_util.h>
#include "gsttensor_trainer.h"
#include <unistd.h>
#include <math.h>
Go to the source code of this file.
Macros | |
#define | SINK_CAPS_STRING GST_TENSORS_CAP_MAKE ("{ static, flexible }") |
Default caps string for sink. More... | |
#define | SRC_CAPS_STRING GST_TENSORS_CAP_MAKE ("{ static}") |
Default caps string for src. More... | |
#define | GST_CAT_DEFAULT gst_tensor_trainer_debug |
#define | gst_tensor_trainer_parent_class parent_class |
#define | MODEL_STATS_SIZE 4 |
#define | DEFAULT_PROP_INPUT_LIST 1 |
Default framework property value. More... | |
#define | DEFAULT_PROP_LABEL_LIST 1 |
#define | DEFAULT_PROP_TRAIN_SAMPLES 0 |
#define | DEFAULT_PROP_VALID_SAMPLES 0 |
#define | DEFAULT_PROP_EPOCHS 1 |
#define | DEFAULT_STR_PROP_VALUE "" |
Default string property value. More... | |
Enumerations | |
enum | { TRAINING_LOSS, TRAINING_ACCURACY, VALIDATION_LOSS, VALIDATION_ACCURACY } |
Statistical from the model being trained An enum value indicates the value stored at the index of the output tensor. More... | |
enum | { PROP_0, PROP_FRAMEWORK, PROP_MODEL_CONFIG, PROP_MODEL_SAVE_PATH, PROP_MODEL_LOAD_PATH, PROP_NUM_INPUTS, PROP_NUM_LABELS, PROP_NUM_TRAINING_SAMPLES, PROP_NUM_VALIDATION_SAMPLES, PROP_EPOCHS } |
tensor_trainer properties More... | |
Functions | |
GST_DEBUG_CATEGORY_STATIC (gst_tensor_trainer_debug) | |
G_DEFINE_TYPE (GstTensorTrainer, gst_tensor_trainer, GST_TYPE_ELEMENT) | |
static void | gst_tensor_trainer_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) |
Setter for tensor_trainsink properties. More... | |
static void | gst_tensor_trainer_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) |
Getter tensor_trainsink properties. More... | |
static void | gst_tensor_trainer_finalize (GObject *object) |
Function to finalize instance. More... | |
static gboolean | gst_tensor_trainer_sink_event (GstPad *sinkpad, GstObject *parent, GstEvent *event) |
Event handler for sink pad of tensor_trainer. More... | |
static gboolean | gst_tensor_trainer_sink_query (GstPad *sinkpad, GstObject *parent, GstQuery *query) |
This function handles sink pad query. More... | |
static gboolean | gst_tensor_trainer_src_query (GstPad *srcpad, GstObject *parent, GstQuery *query) |
This function handles src pad query. More... | |
static GstFlowReturn | gst_tensor_trainer_chain (GstPad *sinkpad, GstObject *parent, GstBuffer *inbuf) |
Chain function, this function does the actual processing. More... | |
static GstCaps * | gst_tensor_trainer_query_caps (GstTensorTrainer *trainer, GstPad *pad, GstCaps *filter) |
Get pad caps for caps negotiation. More... | |
static GstStateChangeReturn | gst_tensor_trainer_change_state (GstElement *element, GstStateChange transition) |
Change state of tensor_trainsink. More... | |
static void | gst_tensor_trainer_set_prop_framework (GstTensorTrainer *trainer, const GValue *value) |
Handle "PROP_FRAMEWORK" for set-property. More... | |
static void | gst_tensor_trainer_set_prop_model_config_file_path (GstTensorTrainer *trainer, const GValue *value) |
Handle "PROP_MODEL_CONFIG" for set-property. More... | |
static void | gst_tensor_trainer_set_model_save_path (GstTensorTrainer *trainer, const GValue *value) |
Handle "PROP_MODEL_SAVE_PATH" for set-property. More... | |
static void | gst_tensor_trainer_set_model_load_path (GstTensorTrainer *trainer, const GValue *value) |
Handle "PROP_MODEL_LOAD_PATH" for set-property. More... | |
static gboolean | gst_tensor_trainer_find_framework (GstTensorTrainer *trainer, const char *name) |
Find Trainer sub-plugin with the name. More... | |
static gboolean | gst_tensor_trainer_create_framework (GstTensorTrainer *trainer) |
Create NN framework. More... | |
static gsize | gst_tensor_trainer_get_tensor_size (GstTensorTrainer *trainer, guint index, gboolean is_input) |
Calculate tensor buffer size. More... | |
static gboolean | gst_tensor_trainer_create_model (GstTensorTrainer *trainer) |
Create model. More... | |
static void | gst_tensor_trainer_create_event_notifier (GstTensorTrainer *trainer) |
Create a event notifier. More... | |
static void | gst_tensor_trainer_start_model_training (GstTensorTrainer *trainer) |
Start model training. More... | |
static void | gst_tensor_trainer_stop_model_training (GstTensorTrainer *trainer) |
Stop model training. More... | |
static void | gst_tensor_trainer_set_output_meta (GstTensorTrainer *trainer) |
initialize the output tensor dimension More... | |
static void | gst_tensor_trainer_class_init (GstTensorTrainerClass *klass) |
initialize the tensor_trainer's class More... | |
static void | gst_tensor_trainer_init (GstTensorTrainer *trainer) |
Initialize tensor_trainer. More... | |
static gboolean | gst_tensor_trainer_check_invalid_param (GstTensorTrainer *trainer) |
Check invalid param. More... | |
static gpointer | gst_tensor_trainer_dummy_data_generation_func (GstTensorTrainer *trainer) |
Dummy data generation thread. More... | |
static void | gst_tensor_trainer_wait_for_epoch_completion (GstTensorTrainer *trainer) |
Wait for epoch eompletion. More... | |
static gboolean | gst_tensor_trainer_epochs_is_complete (GstTensorTrainer *trainer) |
Check if current epochs is complete, tensor_trainer wait for one of epochs to complete before getting the results from the subplugin. More... | |
static gboolean | gst_tensor_trainer_check_buffer_drop_conditions (GstTensorTrainer *trainer) |
Check buffer drop conditions. If condition is met, drop the buffer. More... | |
static gboolean | gst_tensor_trainer_check_chain_conditions (GstTensorTrainer *trainer, guint num_tensors) |
Check chain conditions. If all conditions are met, proceed to next step. More... | |
static gsize | gst_tensor_trainer_convert_meta (GstTensorTrainer *trainer, GstTensorMetaInfo *meta, GstTensorInfo *info, void *data) |
Convert tensor meta and get the size of tensor header. More... | |
static gboolean | gst_tensor_trainer_push_input (GstTensorTrainer *trainer, GstBuffer *inbuf, gboolean in_flexible) |
Create input tensors from the buffer and push it into trainer fw. More... | |
static gboolean | gst_tensor_trainer_get_model_stats (GstTensorTrainer *trainer, double *model_stats) |
Get the model statistics from the sub-plugin. More... | |
static GstBuffer * | gst_tensor_trainer_create_output (GstTensorTrainer *trainer) |
Create output tensors. More... | |
static void | gst_tensor_trainer_wait_for_training_completion (GstTensorTrainer *trainer) |
Wait for training completion. More... | |
int | nnstreamer_trainer_probe (GstTensorTrainerFramework *ttsp) |
Trainer's sub-plugin should call this function to register itself. More... | |
int | nnstreamer_trainer_exit (GstTensorTrainerFramework *ttsp) |
Trainer's sub-plugin may call this to unregister itself. More... | |
void | nnstreamer_trainer_notify_event (GstTensorTrainerEventNotifier *notifier, GstTensorTrainerEventType type, void *data) |
Trainer's sub-plugin may call this to send event. More... | |
Variables | |
static GstStaticPadTemplate | sink_template |
The capabilities of the sink pad. More... | |
static GstStaticPadTemplate | src_template |
The capabilities of the src pad. More... | |
GStreamer plugin to train tensor data using NN Frameworks.
Copyright (C) 2022 Samsung Electronics Co., Ltd.
//! Example launch line |[ gst-launch-1.0 datareposrc location=mnist_trainingSet.dat json=mnist.json start-sample-index=3 stop-sample-index=202 epochs=5 ! \ tensor_trainer framework=nntrainer model-config=mnist.ini model-save-path=model.bin \ num-inputs=1 num-labels=1 num-training-samples=100 num-validation-samples=100 epochs=5 ! \ tensor_sink ]|
Total number of data to be received is 1000((num-training-samples + num-validation-samples) * epochs)
output tensors : dimensions=1:1:4, types=float64. values are training loss, training accuracy, validation loss and validation accuracy. -INFINITY value is stored if the value fetched from the sub-plugin is not greater than 0.
Definition in file gsttensor_trainer.c.
#define DEFAULT_PROP_EPOCHS 1 |
Definition at line 88 of file gsttensor_trainer.c.
#define DEFAULT_PROP_INPUT_LIST 1 |
Default framework property value.
Definition at line 84 of file gsttensor_trainer.c.
#define DEFAULT_PROP_LABEL_LIST 1 |
Definition at line 85 of file gsttensor_trainer.c.
#define DEFAULT_PROP_TRAIN_SAMPLES 0 |
Definition at line 86 of file gsttensor_trainer.c.
#define DEFAULT_PROP_VALID_SAMPLES 0 |
Definition at line 87 of file gsttensor_trainer.c.
#define DEFAULT_STR_PROP_VALUE "" |
Default string property value.
Definition at line 92 of file gsttensor_trainer.c.
#define GST_CAT_DEFAULT gst_tensor_trainer_debug |
Definition at line 64 of file gsttensor_trainer.c.
#define gst_tensor_trainer_parent_class parent_class |
Definition at line 65 of file gsttensor_trainer.c.
#define MODEL_STATS_SIZE 4 |
Definition at line 79 of file gsttensor_trainer.c.
#define SINK_CAPS_STRING GST_TENSORS_CAP_MAKE ("{ static, flexible }") |
Default caps string for sink.
Definition at line 40 of file gsttensor_trainer.c.
#define SRC_CAPS_STRING GST_TENSORS_CAP_MAKE ("{ static}") |
Default caps string for src.
Definition at line 45 of file gsttensor_trainer.c.
anonymous enum |
Statistical from the model being trained An enum value indicates the value stored at the index of the output tensor.
Enumerator | |
---|---|
TRAINING_LOSS | |
TRAINING_ACCURACY | |
VALIDATION_LOSS | |
VALIDATION_ACCURACY |
Definition at line 72 of file gsttensor_trainer.c.
anonymous enum |
tensor_trainer properties
Enumerator | |
---|---|
PROP_0 | |
PROP_FRAMEWORK | |
PROP_MODEL_CONFIG | |
PROP_MODEL_SAVE_PATH | |
PROP_MODEL_LOAD_PATH | |
PROP_NUM_INPUTS | |
PROP_NUM_LABELS | |
PROP_NUM_TRAINING_SAMPLES | |
PROP_NUM_VALIDATION_SAMPLES | |
PROP_EPOCHS |
Definition at line 97 of file gsttensor_trainer.c.
G_DEFINE_TYPE | ( | GstTensorTrainer | , |
gst_tensor_trainer | , | ||
GST_TYPE_ELEMENT | |||
) |
GST_DEBUG_CATEGORY_STATIC | ( | gst_tensor_trainer_debug | ) |
|
static |
Chain function, this function does the actual processing.
Update result if one of epochs is complete, push one outbuf is necessary to change pipeline state. Scheduling with subplugin does not work.
Definition at line 868 of file gsttensor_trainer.c.
|
static |
Change state of tensor_trainsink.
Definition at line 513 of file gsttensor_trainer.c.
|
static |
Check buffer drop conditions. If condition is met, drop the buffer.
app need to send gst_element_send_event(tensor_trainer, gst_event_new_eos()) after training_complete or set eos to datareposrc
Definition at line 629 of file gsttensor_trainer.c.
|
static |
Check chain conditions. If all conditions are met, proceed to next step.
Definition at line 645 of file gsttensor_trainer.c.
|
static |
Check invalid param.
Definition at line 440 of file gsttensor_trainer.c.
|
static |
initialize the tensor_trainer's class
Definition at line 155 of file gsttensor_trainer.c.
|
static |
Convert tensor meta and get the size of tensor header.
Definition at line 665 of file gsttensor_trainer.c.
|
static |
Create a event notifier.
Definition at line 1296 of file gsttensor_trainer.c.
|
static |
Create NN framework.
Definition at line 1221 of file gsttensor_trainer.c.
|
static |
Create model.
Definition at line 1273 of file gsttensor_trainer.c.
|
static |
Create output tensors.
Definition at line 805 of file gsttensor_trainer.c.
|
static |
Dummy data generation thread.
Definition at line 471 of file gsttensor_trainer.c.
|
static |
Check if current epochs is complete, tensor_trainer wait for one of epochs to complete before getting the results from the subplugin.
Definition at line 609 of file gsttensor_trainer.c.
|
static |
Function to finalize instance.
Definition at line 316 of file gsttensor_trainer.c.
|
static |
Find Trainer sub-plugin with the name.
Definition at line 1196 of file gsttensor_trainer.c.
|
static |
Get the model statistics from the sub-plugin.
Definition at line 769 of file gsttensor_trainer.c.
|
static |
Getter tensor_trainsink properties.
Definition at line 395 of file gsttensor_trainer.c.
|
static |
Calculate tensor buffer size.
Definition at line 1250 of file gsttensor_trainer.c.
|
static |
Initialize tensor_trainer.
setup sink pad
setup src pad
init properties
Definition at line 262 of file gsttensor_trainer.c.
|
static |
Create input tensors from the buffer and push it into trainer fw.
Definition at line 687 of file gsttensor_trainer.c.
|
static |
Get pad caps for caps negotiation.
Definition at line 919 of file gsttensor_trainer.c.
|
static |
Handle "PROP_MODEL_LOAD_PATH" for set-property.
Definition at line 1183 of file gsttensor_trainer.c.
|
static |
Handle "PROP_MODEL_SAVE_PATH" for set-property.
Definition at line 1170 of file gsttensor_trainer.c.
|
static |
initialize the output tensor dimension
loss, accuracy, val_loss, val_accuracy
Definition at line 1347 of file gsttensor_trainer.c.
|
static |
Handle "PROP_FRAMEWORK" for set-property.
Definition at line 1143 of file gsttensor_trainer.c.
|
static |
Handle "PROP_MODEL_CONFIG" for set-property.
Definition at line 1157 of file gsttensor_trainer.c.
|
static |
Setter for tensor_trainsink properties.
Definition at line 350 of file gsttensor_trainer.c.
|
static |
Event handler for sink pad of tensor_trainer.
Definition at line 977 of file gsttensor_trainer.c.
|
static |
This function handles sink pad query.
Definition at line 1046 of file gsttensor_trainer.c.
|
static |
This function handles src pad query.
Definition at line 1109 of file gsttensor_trainer.c.
|
static |
Start model training.
Definition at line 1308 of file gsttensor_trainer.c.
|
static |
Stop model training.
Definition at line 1328 of file gsttensor_trainer.c.
|
static |
Wait for epoch eompletion.
Definition at line 590 of file gsttensor_trainer.c.
|
static |
Wait for training completion.
Definition at line 955 of file gsttensor_trainer.c.
int nnstreamer_trainer_exit | ( | GstTensorTrainerFramework * | ttsp | ) |
Trainer's sub-plugin may call this to unregister itself.
[in] | ttsp | tensor_trainer sub-plugin to be unregistered. |
Definition at line 1398 of file gsttensor_trainer.c.
void nnstreamer_trainer_notify_event | ( | GstTensorTrainerEventNotifier * | notifier, |
GstTensorTrainerEventType | type, | ||
void * | data | ||
) |
Trainer's sub-plugin may call this to send event.
Trainer's sub-plugin call this to notify event.
[in] | notifier | event notifier, sub-plugin must send events with this. |
[in] | type | event type |
Definition at line 1425 of file gsttensor_trainer.c.
int nnstreamer_trainer_probe | ( | GstTensorTrainerFramework * | ttsp | ) |
Trainer's sub-plugin should call this function to register itself.
[in] | ttsp | tensor_trainer sub-plugin to be registered. |
Definition at line 1371 of file gsttensor_trainer.c.
|
static |
The capabilities of the sink pad.
Definition at line 50 of file gsttensor_trainer.c.
|
static |
The capabilities of the src pad.
Definition at line 58 of file gsttensor_trainer.c.