From: Ivan Vagin/AI Tools Lab /SRR/Engineer/삼성전자 Date: Fri, 11 Jan 2019 20:54:33 +0000 (+0300) Subject: [nnc] Made importer error message prettier (#2761) X-Git-Tag: nncc_backup~973 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5a94aae82067f243bc322ece5fd9695fb4b03b90;p=platform%2Fcore%2Fml%2Fnnfw.git [nnc] Made importer error message prettier (#2761) 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 --- diff --git a/contrib/nnc/include/passes/common_frontend/op_creator_helper.h b/contrib/nnc/include/passes/common_frontend/op_creator_helper.h index 2c36e09..b268d2a 100644 --- a/contrib/nnc/include/passes/common_frontend/op_creator_helper.h +++ b/contrib/nnc/include/passes/common_frontend/op_creator_helper.h @@ -19,6 +19,7 @@ #include #include +#include #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& problemsSet); + } // namespace nnc #endif // FRONTEND_COMMON_OP_CREATOR_HELPER_H_ diff --git a/contrib/nnc/passes/caffe2_frontend/caffe2_importer.cpp b/contrib/nnc/passes/caffe2_frontend/caffe2_importer.cpp index 2aaccdc..246bafd 100644 --- a/contrib/nnc/passes/caffe2_frontend/caffe2_importer.cpp +++ b/contrib/nnc/passes/caffe2_frontend/caffe2_importer.cpp @@ -20,6 +20,7 @@ #include #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) { diff --git a/contrib/nnc/passes/caffe2_frontend/caffe2_importer.h b/contrib/nnc/passes/caffe2_frontend/caffe2_importer.h index 8720442..ca9fad9 100644 --- a/contrib/nnc/passes/caffe2_frontend/caffe2_importer.h +++ b/contrib/nnc/passes/caffe2_frontend/caffe2_importer.h @@ -62,6 +62,7 @@ private: std::vector _inputShapes; static const std::map _operatorTypes; + // set of strings describing incorrect parts of network and parts of network unsupported by NNC std::set _problemsOpSet; // This map maps caffe2 operators names to MIR operators diff --git a/contrib/nnc/passes/caffe_frontend/caffe_importer.cpp b/contrib/nnc/passes/caffe_frontend/caffe_importer.cpp index d285aba..24b7563 100644 --- a/contrib/nnc/passes/caffe_frontend/caffe_importer.cpp +++ b/contrib/nnc/passes/caffe_frontend/caffe_importer.cpp @@ -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) { diff --git a/contrib/nnc/passes/caffe_frontend/caffe_importer.h b/contrib/nnc/passes/caffe_frontend/caffe_importer.h index 3375cc0..731ee3c 100644 --- a/contrib/nnc/passes/caffe_frontend/caffe_importer.h +++ b/contrib/nnc/passes/caffe_frontend/caffe_importer.h @@ -50,6 +50,7 @@ private: std::map _blobNameToIODescriptor; static const std::map _operatorTypes; + // set of strings describing incorrect parts of network and parts of network unsupported by NNC std::set _problemsOpSet; /** diff --git a/contrib/nnc/passes/common_frontend/op_creator_helper.cpp b/contrib/nnc/passes/common_frontend/op_creator_helper.cpp index 7d20f64..a07a5d6 100644 --- a/contrib/nnc/passes/common_frontend/op_creator_helper.cpp +++ b/contrib/nnc/passes/common_frontend/op_creator_helper.cpp @@ -14,12 +14,15 @@ * 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 + namespace nnc { using namespace mir; @@ -70,4 +73,13 @@ fixGroupedKernel(int groups, const TensorVariant& folded_kernel) { return unfold_kernel; } +void handleProblemSet(const std::set& 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 diff --git a/contrib/nnc/passes/tflite_frontend/tflite_importer.cpp b/contrib/nnc/passes/tflite_frontend/tflite_importer.cpp index f270e4e..f73e12b 100644 --- a/contrib/nnc/passes/tflite_frontend/tflite_importer.cpp +++ b/contrib/nnc/passes/tflite_frontend/tflite_importer.cpp @@ -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) { diff --git a/contrib/nnc/passes/tflite_frontend/tflite_importer.h b/contrib/nnc/passes/tflite_frontend/tflite_importer.h index 0c97785..fd10aae 100644 --- a/contrib/nnc/passes/tflite_frontend/tflite_importer.h +++ b/contrib/nnc/passes/tflite_frontend/tflite_importer.h @@ -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 _opsForTensorsTheyOutput; - + // set of strings describing incorrect parts of network and parts of network unsupported by NNC std::set _problemsOpSet; /** diff --git a/contrib/nnc/unittests/caffe2_frontend/unsupported_caffe2_model.cpp b/contrib/nnc/unittests/caffe2_frontend/unsupported_caffe2_model.cpp index 6985f60..1dcb1eb 100644 --- a/contrib/nnc/unittests/caffe2_frontend/unsupported_caffe2_model.cpp +++ b/contrib/nnc/unittests/caffe2_frontend/unsupported_caffe2_model.cpp @@ -4,8 +4,8 @@ #include #include -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) { diff --git a/contrib/nnc/unittests/caffe_frontend/unsupported_caffe_model.cpp b/contrib/nnc/unittests/caffe_frontend/unsupported_caffe_model.cpp index 0227b90..2feed77 100644 --- a/contrib/nnc/unittests/caffe_frontend/unsupported_caffe_model.cpp +++ b/contrib/nnc/unittests/caffe_frontend/unsupported_caffe_model.cpp @@ -4,10 +4,11 @@ #include #include -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) { diff --git a/contrib/nnc/unittests/tflite_frontend/unsupported_tflite_model.cpp b/contrib/nnc/unittests/tflite_frontend/unsupported_tflite_model.cpp index 4105035..62bbc6f 100644 --- a/contrib/nnc/unittests/tflite_frontend/unsupported_tflite_model.cpp +++ b/contrib/nnc/unittests/tflite_frontend/unsupported_tflite_model.cpp @@ -4,8 +4,8 @@ #include #include -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) {