[enco] Bugfix to throw error when file do not exist (#2104)
author남궁석/On-Device Lab./Engineer/삼성전자 <sk.namkoong@samsung.com>
Tue, 18 Dec 2018 01:35:46 +0000 (10:35 +0900)
committer박종현/On-Device Lab./Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Tue, 18 Dec 2018 01:35:46 +0000 (10:35 +0900)
Until now, there was no error even when prototxt or caffemodel do not exist
This commit will fix the bug

Signed-off-by: Seok NamKoong <sk.namkoong@samsung.com>
contrib/enco/frontend/caffe/src/Entry.cpp

index 35b216e..2bdb73e 100644 (file)
@@ -33,13 +33,29 @@ extern "C" std::unique_ptr<enco::Frontend> make_frontend(const cmdline::View &cm
   // Fill prototxt
   {
     std::ifstream ifs{cmdline.at(0)};
-    from_txt(ifs, *frontend->prototxt());
+    if (!ifs.is_open())
+    {
+      throw std::runtime_error("Prototxt file open fail");
+    }
+
+    if (!from_txt(ifs, *frontend->prototxt()))
+    {
+      throw std::runtime_error("Filling prototxt fail");
+    }
   }
 
   // Fill caffemodel
   {
     std::ifstream ifs{cmdline.at(1), std::ios::binary};
-    from_bin(ifs, *frontend->caffemodel());
+    if (!ifs.is_open())
+    {
+      throw std::runtime_error("Caffemodel file open fail");
+    }
+
+    if (!from_bin(ifs, *frontend->caffemodel()))
+    {
+      throw std::runtime_error("Filling caffemodel fail");
+    }
   }
 
   return std::move(frontend);