[nnc] Made importer error message prettier (#2761)
authorIvan Vagin/AI Tools Lab /SRR/Engineer/삼성전자 <ivan.vagin@samsung.com>
Fri, 11 Jan 2019 20:54:33 +0000 (23:54 +0300)
committerEfimov Alexander/AI Tools Lab/./Samsung Electronics <a.efimov@samsung.com>
Fri, 11 Jan 2019 20:54:33 +0000 (23:54 +0300)
Made importer error message more prettier
Message example:
```
NNC can't load model. Detected problems:
  * Cos: unknown layer
  * Only 'NCHW' axis order is supported
  * Sin: unknown layer
```

Signed-off-by: Ivan Vagin <ivan.vagin@samsung.com>
contrib/nnc/include/passes/common_frontend/op_creator_helper.h
contrib/nnc/passes/caffe2_frontend/caffe2_importer.cpp
contrib/nnc/passes/caffe2_frontend/caffe2_importer.h
contrib/nnc/passes/caffe_frontend/caffe_importer.cpp
contrib/nnc/passes/caffe_frontend/caffe_importer.h
contrib/nnc/passes/common_frontend/op_creator_helper.cpp
contrib/nnc/passes/tflite_frontend/tflite_importer.cpp
contrib/nnc/passes/tflite_frontend/tflite_importer.h
contrib/nnc/unittests/caffe2_frontend/unsupported_caffe2_model.cpp
contrib/nnc/unittests/caffe_frontend/unsupported_caffe_model.cpp
contrib/nnc/unittests/tflite_frontend/unsupported_tflite_model.cpp

index 2c36e09..b268d2a 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <cstdint>
 #include <memory>
+#include <set>
 
 #include "core/modelIR/Shape.h"
 #include "core/modelIR/TensorVariant.h"
@@ -38,6 +39,14 @@ namespace nnc {
  */
 mir::TensorVariant fixGroupedKernel(int groups, const mir::TensorVariant& folded_kernel);
 
+/** Throws PassException if problems set is not empty
+ *
+ * @param problemsSet - set of strings describing incorrect parts of the network
+ *                      and parts of the network unsupported by NNC
+ * @throws PassException with appropriate message
+ */
+void handleProblemSet(const std::set<std::string>& problemsSet);
+
 } // namespace nnc
 
 #endif // FRONTEND_COMMON_OP_CREATOR_HELPER_H_
index 2aaccdc..246bafd 100644 (file)
@@ -20,6 +20,7 @@
 #include <cassert>
 
 #include "caffe2_importer.h"
+#include "passes/common_frontend/op_creator_helper.h"
 #include "passes/common_frontend/shape_helper.h"
 #include "support/ProtobufHelper.h"
 
@@ -89,12 +90,7 @@ void Caffe2Importer::collectUnsupportedOps() {
   for (auto& op : _net->op())
     collectUnsupportedOp(op);
 
-  if (!_problemsOpSet.empty()) {
-    std::string msg("Detected problems:\n");
-    for (const auto& problemStr : _problemsOpSet)
-      msg.append(problemStr + "\n");
-    throw PassException(msg);
-  }
+  handleProblemSet(_problemsOpSet);
 }
 
 void Caffe2Importer::collectUnsupportedOp(const OperatorDef& op) {
index 8720442..ca9fad9 100644 (file)
@@ -62,6 +62,7 @@ private:
   std::vector<mir::Shape> _inputShapes;
 
   static const std::map<std::string, SupportedCaffe2OpType> _operatorTypes;
+  // set of strings describing incorrect parts of network and parts of network unsupported by NNC
   std::set<std::string> _problemsOpSet;
 
   // This map maps caffe2 operators names to MIR operators
index d285aba..24b7563 100644 (file)
@@ -27,6 +27,7 @@
 #include "core/modelIR/TensorUtil.h"
 #include "pass/PassException.h"
 
+#include "passes/common_frontend/op_creator_helper.h"
 #include "passes/common_frontend/shape_helper.h"
 #include "support/ProtobufHelper.h"
 
@@ -76,12 +77,7 @@ void CaffeImporter::collectUnsupportedLayers() {
   for (int i = 0; i < _net->layer_size(); ++i)
     collectUnsupportedOp(_net->layer(i));
 
-  if (!_problemsOpSet.empty()) {
-    std::string msg("Detected problems:\n");
-    for (const auto& problemStr : _problemsOpSet)
-      msg.append(problemStr + "\n");
-    throw PassException(msg);
-  }
+  handleProblemSet(_problemsOpSet);
 }
 
 void CaffeImporter::createMIRNodesFromLayer(const LayerParameter& layer) {
index 3375cc0..731ee3c 100644 (file)
@@ -50,6 +50,7 @@ private:
   std::map<std::string, mir::IODescriptor> _blobNameToIODescriptor;
 
   static const std::map<std::string, CaffeOpType> _operatorTypes;
+  // set of strings describing incorrect parts of network and parts of network unsupported by NNC
   std::set<std::string> _problemsOpSet;
 
   /**
index 7d20f64..a07a5d6 100644 (file)
  * limitations under the License.
  */
 
+#include "pass/PassException.h"
 #include "passes/common_frontend/op_creator_helper.h"
 
 #include "core/modelIR/Shape.h"
 #include "core/modelIR/ShapeRange.h"
 #include "core/modelIR/TensorVariant.h"
 
+#include <set>
+
 namespace nnc {
 
 using namespace mir;
@@ -70,4 +73,13 @@ fixGroupedKernel(int groups, const TensorVariant& folded_kernel) {
   return unfold_kernel;
 }
 
+void handleProblemSet(const std::set<std::string>& problemsSet) {
+  if (!problemsSet.empty()) {
+    std::string msg("NNC can't load model. Detected problems:");
+    for (const auto& problem_str : problemsSet)
+      msg.append("\n  * " + problem_str);
+    throw PassException(msg);
+  }
+}
+
 }  // namespace nnc
\ No newline at end of file
index f270e4e..f73e12b 100644 (file)
@@ -18,6 +18,7 @@
 #include "tflite_importer.h"
 #include "core/modelIR/operations/ElementwiseOp.h"
 #include "tflite_op_creator.h"
+#include "passes/common_frontend/op_creator_helper.h"
 
 using namespace ::tflite;
 
@@ -61,12 +62,7 @@ void TfliteImporter::collectUnsupportedOps() {
     for (auto op: *(sub_graph->operators()))
       processUnsupportedOp(op);
 
-  if (!_problemsOpSet.empty()) {
-    std::string msg("Detected problems:\n");
-    for (const auto& problem_str : _problemsOpSet)
-      msg.append(problem_str + "\n");
-    throw PassException(msg);
-  }
+  handleProblemSet(_problemsOpSet);
 }
 
 void TfliteImporter::processUnsupportedOp(const Operator* op) {
index 0c97785..fd10aae 100644 (file)
@@ -75,7 +75,7 @@ private:
   // This map maps indices of TFLite tensors to MIR operations/nodes
   // that correspond to operations having these tensors as output.
   std::map<int, mir::Operation*> _opsForTensorsTheyOutput;
-
+  // set of strings describing incorrect parts of network and parts of network unsupported by NNC
   std::set<std::string> _problemsOpSet;
 
   /**
index 6985f60..1dcb1eb 100644 (file)
@@ -4,8 +4,8 @@
 #include <string>
 #include <iostream>
 
-const char *ErrorMsg = "Detected problems:\n"
-                       "Sin: unknown layer\n";
+const char *ErrorMsg = "NNC can't load model. Detected problems:\n"
+                       "  * Sin: unknown layer";
 
 // When adding support for new layers, change the model, not the test
 TEST(CAFFE_IMPORT_UNSUPPORTED, ImportAModelWithUnsupportedLayers) {
index 0227b90..2feed77 100644 (file)
@@ -4,10 +4,11 @@
 #include <string>
 #include <iostream>
 
-const char *ErrorMsg = "Detected problems:\n"
-                       "DummyData: unsupported layer\n"
-                       "LSTM: parameter 'expose_hidden' has unsupported value: 1\n"
-                       "UnexcitingLayerType: unknown layer\n";
+
+const char *ErrorMsg = "NNC can't load model. Detected problems:\n"
+                       "  * DummyData: unsupported layer\n"
+                       "  * LSTM: parameter 'expose_hidden' has unsupported value: 1\n"
+                       "  * UnexcitingLayerType: unknown layer";
 
 // When adding support for new layers, change the model, not the test
 TEST(CAFFE_IMPORT_UNSUPPORTED, ImportAModelWithUnsupportedLayers) {
index 4105035..62bbc6f 100644 (file)
@@ -4,8 +4,8 @@
 #include <string>
 #include <iostream>
 
-const char *ErrorMsg = "Detected problems:\n"
-                       "SIN: unsupported operator\n";
+const char *ErrorMsg = "NNC can't load model. Detected problems:\n"
+                       "  * SIN: unsupported operator";
 
 // When adding support for new layers, change the model, not the test
 TEST(TFLITE_IMPORT_UNSUPPORTED, ImportModelWithUnsupportedLayers) {