* @brief Load tensorflow lite modelfile
* @param filter : tensor_filter instance
* @param private_data : tensorflow lite plugin's private data
- * @return 0 if successfully loaded. 1 if skipped (already loaded). -1 if error
+ * @return 0 if successfully loaded. 1 if skipped (already loaded).
+ * -1 if the object construction is failed.
+ * -2 if the object initialization if failed
*/
static int
tflite_loadModelFile (const GstTensorFilter * filter, void **private_data)
*private_data = tf;
tf->tflite_private_data = tflite_core_new (filter->prop.model_file);
if (tf->tflite_private_data) {
+ if (tflite_core_init (tf->tflite_private_data))
+ return -2;
return 0;
} else {
return -1;
TFLiteCore::TFLiteCore (const char *_model_path)
{
model_path = _model_path;
- loadModel ();
- setInputTensorProp ();
- setOutputTensorProp ();
}
/**
}
/**
+ * @brief initialize the object with tflite model
+ * @return 0 if OK. non-zero if error.
+ * -1 if the model is not loaded.
+ * -2 if the initialization of input tensor is failed.
+ * -3 if the initialization of output tensor is failed.
+ */
+int
+TFLiteCore::init()
+{
+ if(loadModel ())
+ {
+ _print_log ("Failed to load model\n");
+ return -1;
+ }
+ if(setInputTensorProp ())
+ {
+ _print_log ("Failed to initialize input tensor\n");
+ return -2;
+ }
+ if(setOutputTensorProp ())
+ {
+ _print_log ("Failed to initialize output tensor\n");
+ return -3;
+ }
+ return 0;
+}
+
+/**
* @brief get millisecond for time profiling.
* @note it returns the millisecond.
* @param t : the time struct.
* @param _model_path : the logical path to '{model_name}.tffile' file
* @return TFLiteCore class
*/
-extern void *
+void *
tflite_core_new (const char *_model_path)
{
return new TFLiteCore (_model_path);
* @param tflite : the class object
* @return Nothing
*/
-extern void
+void
tflite_core_delete (void *tflite)
{
TFLiteCore *c = (TFLiteCore *) tflite;
}
/**
+ * @brief initialize the object with tflite model
+ * @return 0 if OK. non-zero if error.
+ */
+int
+tflite_core_init (void *tflite)
+{
+ TFLiteCore *c = (TFLiteCore *) tflite;
+ int ret = c->init ();
+ return ret;
+}
+
+/**
* @brief get the Dimension of Input Tensor of model
* @param tflite : the class object
* @param[out] info Structure for tensor info.
TFLiteCore (const char *_model_path);
~TFLiteCore ();
+ int init();
int loadModel ();
int setInputTensorProp ();
int setOutputTensorProp ();
extern void *tflite_core_new (const char *_model_path);
extern void tflite_core_delete (void *tflite);
+ extern int tflite_core_init (void *tflite);
extern const char *tflite_core_getModelPath (void *tflite);
extern int tflite_core_getInputDim (void *tflite, GstTensorsInfo * info);
extern int tflite_core_getOutputDim (void *tflite, GstTensorsInfo * info);