[Filter/TF-Lite] remove unnecessary code
authorjy1210.jung <jy1210.jung@samsung.com>
Wed, 1 Aug 2018 12:28:20 +0000 (21:28 +0900)
committer문지중/동작제어Lab(SR)/Principal Engineer/삼성전자 <jijoong.moon@samsung.com>
Tue, 7 Aug 2018 00:17:20 +0000 (09:17 +0900)
1. use interpreter inputs() / outputs() to get input/output tensor index
list
2. add debug logs to print tensor dim and type

**Self evaluation:**
1. Build test: [ ]Passed [ ]Failed [*]Skipped
2. Run test: [ ]Passed [ ]Failed [*]Skipped

Signed-off-by: Jaeyun Jung <jy1210.jung@samsung.com>
gst/tensor_filter/tensor_filter_tensorflow_lite_core.cc
include/tensor_filter_tensorflow_lite_core.h

index ada159d..2bdb627 100644 (file)
@@ -48,8 +48,6 @@
 TFLiteCore::TFLiteCore (const char *_model_path)
 {
   model_path = _model_path;
-  input_idx_list_len = 0;
-  output_idx_list_len = 0;
 
   loadModel ();
 }
@@ -60,8 +58,6 @@ TFLiteCore::TFLiteCore (const char *_model_path)
  */
 TFLiteCore::~TFLiteCore ()
 {
-  delete[]input_idx_list;
-  delete[]output_idx_list;
 }
 
 /**
@@ -106,30 +102,6 @@ TFLiteCore::loadModel ()
       return -2;
     }
   }
-  // fill class parameters
-  tensor_size = interpreter->tensors_size ();
-  node_size = interpreter->nodes_size ();
-  input_size = interpreter->inputs ().size ();
-  output_size = interpreter->outputs ().size ();
-
-  // allocate the idx of input/output tensors
-  // it could be used for get name of the tensors by using 'interpreter->GetOutputName(0);'
-  input_idx_list = new int[input_size];
-  output_idx_list = new int[output_size];
-
-  int t_size = interpreter->tensors_size ();
-  for (int i = 0; i < t_size; i++) {
-    for (int j = 0; j < input_size; j++) {
-      if (strcmp (interpreter->tensor (i)->name,
-              interpreter->GetInputName (j)) == 0)
-        input_idx_list[input_idx_list_len++] = i;
-    }
-    for (int j = 0; j < output_size; j++) {
-      if (strcmp (interpreter->tensor (i)->name,
-              interpreter->GetOutputName (j)) == 0)
-        output_idx_list[output_idx_list_len++] = i;
-    }
-  }
 
 #if (DBG)
   gettimeofday (&stop_time, nullptr);
@@ -181,10 +153,22 @@ TFLiteCore::getTensorType (int tensor_idx, tensor_type * type)
 int
 TFLiteCore::getInputTensorDim (int idx, tensor_dim dim, tensor_type * type)
 {
+  auto input_idx_list = interpreter->inputs ();
+  int input_size = input_idx_list.size ();
+
   if (idx >= input_size) {
     return -1;
   }
+
   int ret = getTensorDim (input_idx_list[idx], dim, type);
+#if (DBG)
+  if (ret) {
+    _print_log ("Failed to getInputTensorDim");
+  } else {
+    _print_log ("InputTensorDim idx[%d] type[%d] dim[%d:%d:%d:%d]",
+        idx, *type, dim[0], dim[1], dim[2], dim[3]);
+  }
+#endif
   return ret;
 }
 
@@ -198,10 +182,22 @@ TFLiteCore::getInputTensorDim (int idx, tensor_dim dim, tensor_type * type)
 int
 TFLiteCore::getOutputTensorDim (int idx, tensor_dim dim, tensor_type * type)
 {
+  auto output_idx_list = interpreter->outputs ();
+  int output_size = output_idx_list.size ();
+
   if (idx >= output_size) {
     return -1;
   }
+
   int ret = getTensorDim (output_idx_list[idx], dim, type);
+#if (DBG)
+  if (ret) {
+    _print_log ("Failed to getOutputTensorDim");
+  } else {
+    _print_log ("OutputTensorDim idx[%d] type[%d] dim[%d:%d:%d:%d]",
+        idx, *type, dim[0], dim[1], dim[2], dim[3]);
+  }
+#endif
   return ret;
 }
 
@@ -215,7 +211,6 @@ TFLiteCore::getOutputTensorDim (int idx, tensor_dim dim, tensor_type * type)
 int
 TFLiteCore::getTensorDim (int tensor_idx, tensor_dim dim, tensor_type * type)
 {
-
   if (getTensorType (tensor_idx, type)) {
     return -2;
   }
@@ -242,7 +237,7 @@ TFLiteCore::getTensorDim (int tensor_idx, tensor_dim dim, tensor_type * type)
 int
 TFLiteCore::getInputTensorSize ()
 {
-  return input_size;
+  return interpreter->inputs ().size ();
 }
 
 /**
@@ -252,7 +247,7 @@ TFLiteCore::getInputTensorSize ()
 int
 TFLiteCore::getOutputTensorSize ()
 {
-  return output_size;
+  return interpreter->outputs ().size ();
 }
 
 /**
@@ -276,16 +271,21 @@ TFLiteCore::invoke (uint8_t * inptr, uint8_t ** outptr)
   tensor_dim inputTensorDim;
   int ret = getInputTensorDim (0, inputTensorDim, &type);
   if (ret) {
+    _print_log ("Failed to get input tensor dim");
     return -1;
   }
   for (int i = 0; i < sizeOfArray; i++) {
     output_number_of_pixels *= inputTensorDim[i];
   }
 
+  /**
+   * @todo how to handle input/output tensor type? (for example, float32)
+   * also, we have to check multi tensor output.
+   */
   int input = interpreter->inputs ()[0];
 
   if (interpreter->AllocateTensors () != kTfLiteOk) {
-    std::cout << "Failed to allocate tensors!" << std::endl;
+    _print_log ("Failed to allocate tensors");
     return -2;
   }
 
@@ -294,6 +294,7 @@ TFLiteCore::invoke (uint8_t * inptr, uint8_t ** outptr)
   }
 
   if (interpreter->Invoke () != kTfLiteOk) {
+    _print_log ("Failed to invoke");
     return -3;
   }
 
index 0ce5ec9..625b12a 100644 (file)
@@ -73,14 +73,6 @@ private:
    * member variables.
    */
   const char *model_path;
-  int tensor_size;
-  int node_size;
-  int input_size;
-  int output_size;
-  int *input_idx_list;
-  int *output_idx_list;
-  int input_idx_list_len;
-  int output_idx_list_len;
   std::unique_ptr < tflite::Interpreter > interpreter;
   std::unique_ptr < tflite::FlatBufferModel > model;
   int getTensorType(int tensor_idx, tensor_type *type);