[Filter] add proper error messages
authorHyoung Joo Ahn <hello.ahn@samsung.com>
Tue, 26 Feb 2019 02:15:25 +0000 (11:15 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Tue, 5 Mar 2019 00:34:44 +0000 (09:34 +0900)
when the model file is not valid or not existed, system generates the proper error messages without any options.

Signed-off-by: Hyoung Joo Ahn <hello.ahn@samsung.com>
ext/nnstreamer/tensor_filter/tensor_filter_tensorflow_core.cc
ext/nnstreamer/tensor_filter/tensor_filter_tensorflow_lite.c
ext/nnstreamer/tensor_filter/tensor_filter_tensorflow_lite_core.cc

index 71ab597..1dd22e5 100644 (file)
@@ -88,9 +88,11 @@ TFCore::getModelPath ()
  * @brief      load the tf model
  * @note       the model will be loaded
  * @return 0 if OK. non-zero if error.
- *        -1 if the pb file is not loaded.
- *        -2 if the input properties are different with model.
- *        -3 if the Tensorflow session is not created.
+ *        -1 if the modelfile is not valid(or not exist).
+ *        -2 if the pb file is not loaded.
+ *        -3 if the input properties are different with model.
+ *        -4 if the Tensorflow session is not initialized.
+ *        -5 if the Tensorflow session is not created.
  */
 int
 TFCore::loadModel ()
@@ -102,29 +104,33 @@ TFCore::loadModel ()
   Status status;
   GraphDef graph_def;
 
+  if (!g_file_test (model_path, G_FILE_TEST_IS_REGULAR)) {
+    g_critical ("the file of model_path is not valid\n");
+    return -1;
+  }
   status = ReadBinaryProto (Env::Default (), model_path, &graph_def);
   if (!status.ok()) {
-    GST_ERROR ("Failed to read graph.\n%s", status.ToString().c_str());
-    return -1;
+    g_critical ("Failed to read graph.\n%s", status.ToString().c_str());
+    return -2;
   }
 
   /* validate input tensor */
   if (validateInputTensor (graph_def)) {
-    GST_ERROR ("Input Tensor Information is not valid");
-    return -2;
+    g_critical ("Input Tensor Information is not valid");
+    return -3;
   }
 
   /* get session */
   status = NewSession (SessionOptions (), &session);
   if (!status.ok()) {
-    GST_ERROR ("Failed to init new session.\n%s", status.ToString().c_str());
-    return -3;
+    g_critical ("Failed to init new session.\n%s", status.ToString().c_str());
+    return -4;
   }
 
   status = session->Create (graph_def);
   if (!status.ok()) {
-    GST_ERROR ("Failed to create session.\n%s", status.ToString().c_str());
-    return -3;
+    g_critical ("Failed to create session.\n%s", status.ToString().c_str());
+    return -5;
   }
 
   /* prepare output tensor */
index 466ac1f..234e9af 100644 (file)
@@ -100,7 +100,9 @@ tflite_loadModelFile (const GstTensorFilterProperties * prop,
 static int
 tflite_open (const GstTensorFilterProperties * prop, void **private_data)
 {
-  return tflite_loadModelFile (prop, private_data);
+  int ret = tflite_loadModelFile (prop, private_data);
+  g_assert (ret == 0);       /** This must be called only once */
+  return ret;
 }
 
 /**
index 5e2217e..cc32503 100644 (file)
@@ -106,11 +106,15 @@ TFLiteCore::loadModel ()
 #endif
 
   if (!interpreter) {
+    if (!g_file_test (model_path, G_FILE_TEST_IS_REGULAR)) {
+      g_critical ("the file of model_path is not valid\n");
+      return -1;
+    }
     model =
         std::unique_ptr <tflite::FlatBufferModel>
         (tflite::FlatBufferModel::BuildFromFile (model_path));
     if (!model) {
-      GST_ERROR ("Failed to mmap model\n");
+      g_critical ("Failed to mmap model\n");
       return -1;
     }
     /* If got any trouble at model, active below code. It'll be help to analyze. */
@@ -119,7 +123,7 @@ TFLiteCore::loadModel ()
     tflite::ops::builtin::BuiltinOpResolver resolver;
     tflite::InterpreterBuilder (*model, resolver) (&interpreter);
     if (!interpreter) {
-      GST_ERROR ("Failed to construct interpreter\n");
+      g_critical ("Failed to construct interpreter\n");
       return -2;
     }
 
@@ -139,7 +143,7 @@ TFLiteCore::loadModel ()
     }
 
     if (interpreter->AllocateTensors () != kTfLiteOk) {
-      GST_ERROR ("Failed to allocate tensors\n");
+      g_critical ("Failed to allocate tensors\n");
       return -2;
     }
   }