From ca866f7933e4cebd746fe71fcf3921980b6167c1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ivan=20Vagin/AI=20Tools=20Lab=20/SRR/Engineer/=EC=82=BC?= =?utf8?q?=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Mon, 15 Oct 2018 22:01:38 +0300 Subject: [PATCH] Fixed caffe PassException what method, minor fixes (#1867) * Fixed caffe PassException method * Fixed sasha.caffemodel * Made caffe op-checker methods non static Signed-off-by: Ivan Vagin --- contrib/nnc/examples/caffe_frontend/model_dump.cpp | 2 +- .../nnc/passes/caffe_frontend/caffe_importer.cpp | 21 ++++------ contrib/nnc/passes/caffe_frontend/caffe_importer.h | 44 +++++++++++++++++++-- .../nnc/passes/caffe_frontend/caffe_op_creator.h | 14 +++---- .../test_data/unsupported.caffemodel | Bin 803218 -> 803260 bytes .../caffe_frontend/unsupportedCaffeModel.cpp | 4 +- 6 files changed, 59 insertions(+), 26 deletions(-) diff --git a/contrib/nnc/examples/caffe_frontend/model_dump.cpp b/contrib/nnc/examples/caffe_frontend/model_dump.cpp index 7e587a5..e0d5846 100644 --- a/contrib/nnc/examples/caffe_frontend/model_dump.cpp +++ b/contrib/nnc/examples/caffe_frontend/model_dump.cpp @@ -44,7 +44,7 @@ int main(int argc, const char **argv) { dotDumper.writeDot(std::cout); } catch (PassException &e) { - std::cout << "Error: " << e.reason() << std::endl; + std::cout << "Error: " << e.what() << std::endl; return -1; } diff --git a/contrib/nnc/passes/caffe_frontend/caffe_importer.cpp b/contrib/nnc/passes/caffe_frontend/caffe_importer.cpp index eaa10e4..b9f2c9e 100644 --- a/contrib/nnc/passes/caffe_frontend/caffe_importer.cpp +++ b/contrib/nnc/passes/caffe_frontend/caffe_importer.cpp @@ -71,7 +71,7 @@ void CaffeImporter::collectUnsupportedLayers() { } void CaffeImporter::createMIRNodesFromLayer(const LayerParameter& lp) { - auto inputs = createOpInputs(lp); + auto inputs = getInputMIROps(lp); auto params = createOpParams(lp); std::vector outputs; @@ -147,23 +147,23 @@ void CaffeImporter::collectUnsupportedOp(const LayerParameter& lp) { // No checks break; case CaffeOpType::convolution: - OpCreator::checkConv2D(lp.convolution_param(), _problemsOpSet); + _opCreator.checkConv2D(lp.convolution_param(), _problemsOpSet); break; case CaffeOpType::innerProduct: - OpCreator::checkFullyConnected(lp.inner_product_param(), _problemsOpSet); + _opCreator.checkFullyConnected(lp.inner_product_param(), _problemsOpSet); break; case CaffeOpType::pooling: - OpCreator::checkPool(lp.pooling_param(), _problemsOpSet); + _opCreator.checkPool(lp.pooling_param(), _problemsOpSet); break; case CaffeOpType::reshape: - OpCreator::checkReshape(lp.reshape_param(), _problemsOpSet); + _opCreator.checkReshape(lp.reshape_param(), _problemsOpSet); break; case CaffeOpType::ReLU: - OpCreator::checkRelu(lp.relu_param(), _problemsOpSet); + _opCreator.checkRelu(lp.relu_param(), _problemsOpSet); break; case CaffeOpType::batchNorm: params = createOpParams(lp); - OpCreator::checkBatchNorm(lp.batch_norm_param(), params, _problemsOpSet); + _opCreator.checkBatchNorm(lp.batch_norm_param(), params, _problemsOpSet); break; default: _problemsOpSet.insert(lp.type() + ": unsupported layer"); @@ -249,8 +249,7 @@ std::shared_ptr CaffeImporter::createTensor(const BlobProto &bp) { return tensor; } -std::vector CaffeImporter::createOpInputs(const LayerParameter &lp) -{ +std::vector CaffeImporter::getInputMIROps(const LayerParameter &lp) { std::vector inputs; for (const auto &inputBlobName : lp.bottom()) @@ -259,9 +258,6 @@ std::vector CaffeImporter::createOpInputs(const LayerParameter &lp) return inputs; } -/** - * @brief Prepares Caffe layer parameters for Model IR operation creator. - */ std::vector> CaffeImporter::createOpParams(const LayerParameter &lp) { std::vector> params; @@ -286,7 +282,6 @@ std::vector> CaffeImporter::createOpParams(const Layer } void CaffeImporter::setGraphOutputs() { - // Marking nodes as output nodes. for (auto &outputIdx : _graphOutputs) _graph->markOutput(outputIdx); } diff --git a/contrib/nnc/passes/caffe_frontend/caffe_importer.h b/contrib/nnc/passes/caffe_frontend/caffe_importer.h index cbec284..0fba57b 100644 --- a/contrib/nnc/passes/caffe_frontend/caffe_importer.h +++ b/contrib/nnc/passes/caffe_frontend/caffe_importer.h @@ -36,9 +36,18 @@ class CaffeImporter : public NNImporter { public: explicit CaffeImporter(std::string filename) : _modelFilename(std::move(filename)), _graph(new mir::Graph()), - _opCreator(_graph) {}; + _opCreator(_graph) {} + /** + * @brief Import model from file, must be called before 'createIR' method + * @throw PassException in case, if model couldn't be parsed or NNC doesn't support it + */ void import() override; + + /** + * @brief Create MIR graph from caffe model, must be called after 'import' method + * @return MIR graph, corresponding to processed caffe model + */ Graph *createIR() override; private: @@ -48,20 +57,49 @@ private: OpCreator _opCreator; std::vector _inputShapes; + + // This map maps caffe tensor names to MIR operations/nodes + // that correspond to operations having these tensors as output. std::map _opsForBlobsTheyOutput; std::vector _graphOutputs; static const std::map _operatorTypes; - std::set _problemsOpSet{}; + std::set _problemsOpSet; + /** + * @brief Mark output MIR nodes + */ void setGraphOutputs(); + /** + * @brief Set MIR node names + */ void setIrNodeNames(); + /** + * @brief Pass through caffe graph and collect unsupported by NNC layers + * @throw PassException with message, containing detected problems + */ void collectUnsupportedLayers(); + + /** + * @brief Creating MIR node from single caffe layer + */ void createMIRNodesFromLayer(const LayerParameter& lp); + /** + * @brief Collecting unsupported parts of caffe layer + */ void collectUnsupportedOp(const LayerParameter& lp); + /** + * @brief Creates MIR tensor from caffe blob + */ std::shared_ptr createTensor(const ::caffe::BlobProto&); - std::vector createOpInputs(const ::caffe::LayerParameter&); + /** + * @brief Returns MIR ops, under given caffe layer + */ + std::vector getInputMIROps(const ::caffe::LayerParameter&); + /** + * @brief Prepares Caffe layer parameters for Model IR operation creator. + */ std::vector> createOpParams(const ::caffe::LayerParameter&); void createGraphInputs(const std::vector &names, diff --git a/contrib/nnc/passes/caffe_frontend/caffe_op_creator.h b/contrib/nnc/passes/caffe_frontend/caffe_op_creator.h index e7b8bfe..28f92c0 100644 --- a/contrib/nnc/passes/caffe_frontend/caffe_op_creator.h +++ b/contrib/nnc/passes/caffe_frontend/caffe_op_creator.h @@ -57,13 +57,13 @@ public: std::vector createBatchNorm(InputOps inputs, InputParams params, const BatchNormParameter& opts); std::vector createDropout(InputOps inputs, InputParams params, const DropoutParameter& opts); - static void checkConv2D(const caffe::ConvolutionParameter& opts, std::set &unsupportedOpSet); - static void checkFullyConnected(const caffe::InnerProductParameter &opts, std::set &problemsOpSet); - static void checkPool(const caffe::PoolingParameter &opts, std::set &problemsOpSet); - static void checkReshape(const caffe::ReshapeParameter &opts, std::set &problemsOpSet); - static void checkRelu(const caffe::ReLUParameter &opts, std::set &problemsOpSet); - static void checkBatchNorm(const caffe::BatchNormParameter &opts, InputParams params, - std::set &problemsOpSet); + void checkConv2D(const caffe::ConvolutionParameter& opts, std::set &unsupportedOpSet); + void checkFullyConnected(const caffe::InnerProductParameter &opts, std::set &problemsOpSet); + void checkPool(const caffe::PoolingParameter &opts, std::set &problemsOpSet); + void checkReshape(const caffe::ReshapeParameter &opts, std::set &problemsOpSet); + void checkRelu(const caffe::ReLUParameter &opts, std::set &problemsOpSet); + void checkBatchNorm(const caffe::BatchNormParameter &opts, InputParams params, + std::set &problemsOpSet); private: Graph* graph = nullptr; diff --git a/contrib/nnc/unittests/caffe_frontend/test_data/unsupported.caffemodel b/contrib/nnc/unittests/caffe_frontend/test_data/unsupported.caffemodel index eab73971d780b95f2acea8cc874b71ba7f6c390d..77278fe50ba97262d98bb877fba0184231a1e4fb 100644 GIT binary patch delta 142 zcmbQ#Y`CY{aDry65tndiUTQ^hW=UpVx=&(dYEejKL8=foK_!-y#FE4S#zkz-T&y6b zp%AA_X>M+%3y`gZO-Ex)YYby+3{z_ib88GsYYb~^3|ngqdut3wYYb;=3|DIm_tqF5 GGe-aeMKFQ@ delta 100 zcmdnfY&faeaDt|>7#C}BVsS>I5QI`