[caffe2] Do first run with try/catch
authorParichay Kapoor <pk.kapoor@samsung.com>
Thu, 7 Nov 2019 02:25:25 +0000 (11:25 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Mon, 11 Nov 2019 01:28:45 +0000 (10:28 +0900)
First run after configuring the tensor filter with caffe2 framework is now run with a try/catch

Check #180 for more details

Signed-off-by: Parichay Kapoor <pk.kapoor@samsung.com>
ext/nnstreamer/tensor_filter/tensor_filter_caffe2_core.cc
ext/nnstreamer/tensor_filter/tensor_filter_caffe2_core.h

index 777f164..15d869a 100644 (file)
@@ -47,6 +47,7 @@ Caffe2Core::Caffe2Core (const char * _model_path, const char *_model_path_sub)
   g_assert (_model_path != NULL && _model_path_sub != NULL);
   pred_model_path = g_strdup (_model_path);
   init_model_path = g_strdup (_model_path_sub);
+  first_run = true;
 
   gst_tensors_info_init (&inputTensorMeta);
   gst_tensors_info_init (&outputTensorMeta);
@@ -86,6 +87,8 @@ Caffe2Core::init (const GstTensorFilterProperties * prop)
     g_critical ("Failed to initialize input tensor\n");
     return -2;
   }
+
+  first_run = true;
   return 0;
 }
 
@@ -300,7 +303,27 @@ Caffe2Core::run (const GstTensorMemory * input, GstTensorMemory * output)
     }
   }
 
-  workSpace.RunNet (predictNet.name ());
+  /**
+   * As the input information has not been verified, the first run for the model
+   * is encapsulated in a try-catch block
+   */
+  if (first_run) {
+    try {
+      workSpace.RunNet (predictNet.name ());
+      first_run = false;
+    } catch(const std::runtime_error& re) {
+      g_critical ("Runtime error while running the model: %s", re.what());
+      return -4;
+    } catch(const std::exception& ex)  {
+      g_critical ("Exception while running the model : %s", ex.what());
+      return -4;
+    } catch (...) {
+      g_critical ("Unknown exception while running the model");
+      return -4;
+    }
+  } else {
+    workSpace.RunNet (predictNet.name ());
+  }
 
   for (i = 0; i < outputTensorMeta.num_tensors; i++) {
     const auto& out = workSpace.GetBlob (outputTensorMeta.info[i].name)
index 0de6577..2153ad4 100644 (file)
@@ -55,6 +55,7 @@ private:
 
   char *init_model_path;
   char *pred_model_path;
+  bool first_run;
 
   GstTensorsInfo inputTensorMeta;  /**< The tensor info of input tensors */
   GstTensorsInfo outputTensorMeta;  /**< The tensor info of output tensors */