From 2da6546841a25318be17362c7125194e7525c932 Mon Sep 17 00:00:00 2001 From: Bartosz Lesniewski Date: Fri, 4 Dec 2020 17:49:36 +0100 Subject: [PATCH] Remove ops from Layer Creator/ Node Converter - part 2 (#3226) * remove power op from layer creator * remove prelu op from layer creator * remove tile op from layer creator * remove relu op from layer creator * remove selu op from layer creator * remove softmax op from layer creator * remove tanh op from layer creator * remove split op from layer creator * remove reshape op from layer creator * remove reverse sequence op from layer creator * remove proposal op from layer creator * remove priorbox op from layer creator * remove roipooling op from layer creator * remove priorboxclustered op from layer creator * style fix * utility function to parse bool-containing strings * align priorbox scale_all_sizes parameter to specification * change location of getBoolStrParamAsIntStr function * align prelu creator to new constant op changes * adjust priorbox tests to align with scale_all_sizes default value * adjust priorbox python tests to align with scale_all_sizes default value * align priorboxclustered attributes initlialization to specification * fix checking wrong container's end iterator for opset name search * improve comment on roipooling parameters * Apply review suggestion 1 Co-authored-by: Ilya Churaev * Apply review suggestion 2 Co-authored-by: Ilya Churaev * align priorbox step initial value to specification * align roipooling method attribute to specification * remove roipooling specific creator * align with review comments Co-authored-by: Ilya Churaev --- .../src/legacy_api/include/legacy/ie_layers.h | 9 + .../ngraph_ops/prior_box_clustered_ie.hpp | 2 +- .../legacy/ngraph_ops/prior_box_ie.hpp | 1 + .../include/legacy/ngraph_ops/proposal_ie.hpp | 2 +- .../include/legacy/ngraph_ops/selu_ie.hpp | 2 +- .../include/legacy/ngraph_ops/tile_ie.hpp | 2 +- .../src/convert_function_to_cnn_network.cpp | 242 +++++++++++--- .../src/ie_cnn_layer_builder_ngraph.cpp | 306 ------------------ .../src/legacy_api/src/ie_layers.cpp | 10 + .../src/ngraph_ops/prior_box_clustered_ie.cpp | 24 ++ .../src/ngraph_ops/prior_box_ie.cpp | 16 + .../legacy_api/src/ngraph_ops/proposal_ie.cpp | 18 ++ .../src/legacy_api/src/ngraph_ops/selu_ie.cpp | 6 + .../src/legacy_api/src/ngraph_ops/tile_ie.cpp | 6 + .../src/readers/ir_reader/ie_ir_parser.cpp | 204 +----------- .../functional_test_utils/network_utils.cpp | 3 + ngraph/core/include/ngraph/op/prior_box.hpp | 4 +- .../include/ngraph/op/prior_box_clustered.hpp | 6 +- ngraph/core/include/ngraph/op/relu.hpp | 1 + .../include/ngraph/op/reverse_sequence.hpp | 2 +- ngraph/core/include/ngraph/op/roi_pooling.hpp | 4 +- ngraph/core/include/ngraph/opsets/opset.hpp | 2 +- ngraph/core/src/op/prior_box_clustered.cpp | 28 +- ngraph/core/src/op/relu.cpp | 5 + ngraph/core/src/op/roi_pooling.cpp | 2 + .../tests/test_ngraph/test_create_op.py | 5 +- ngraph/test/type_prop_layers.cpp | 3 +- 27 files changed, 353 insertions(+), 562 deletions(-) diff --git a/inference-engine/src/legacy_api/include/legacy/ie_layers.h b/inference-engine/src/legacy_api/include/legacy/ie_layers.h index b298ac969fa..97667158142 100644 --- a/inference-engine/src/legacy_api/include/legacy/ie_layers.h +++ b/inference-engine/src/legacy_api/include/legacy/ie_layers.h @@ -361,6 +361,15 @@ public: */ std::string GetParamAsString(const char* param) const; + /** + * @brief Returns a string containing an integer if parameters value was + * "true" or "false" + * + * @param param Name of the layer parameter + * @return A string containing an integer or the parameter as string + */ + std::string getBoolStrParamAsIntStr(const char *param) const; + /** * @brief Gets the parameter as a std::vector * @param param The parameter name diff --git a/inference-engine/src/legacy_api/include/legacy/ngraph_ops/prior_box_clustered_ie.hpp b/inference-engine/src/legacy_api/include/legacy/ngraph_ops/prior_box_clustered_ie.hpp index 9f1193ca6bf..ff785c89308 100644 --- a/inference-engine/src/legacy_api/include/legacy/ngraph_ops/prior_box_clustered_ie.hpp +++ b/inference-engine/src/legacy_api/include/legacy/ngraph_ops/prior_box_clustered_ie.hpp @@ -31,7 +31,7 @@ public: void validate_and_infer_types() override; std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - + bool visit_attributes(AttributeVisitor& visitor) override; const PriorBoxClusteredAttrs& get_attrs() const { return m_attrs; } private: diff --git a/inference-engine/src/legacy_api/include/legacy/ngraph_ops/prior_box_ie.hpp b/inference-engine/src/legacy_api/include/legacy/ngraph_ops/prior_box_ie.hpp index 334a86b02ff..824b5d4bd27 100644 --- a/inference-engine/src/legacy_api/include/legacy/ngraph_ops/prior_box_ie.hpp +++ b/inference-engine/src/legacy_api/include/legacy/ngraph_ops/prior_box_ie.hpp @@ -32,6 +32,7 @@ public: std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; const PriorBoxAttrs& get_attrs() const { return m_attrs; } + bool visit_attributes(AttributeVisitor& visitor) override; private: PriorBoxAttrs m_attrs; diff --git a/inference-engine/src/legacy_api/include/legacy/ngraph_ops/proposal_ie.hpp b/inference-engine/src/legacy_api/include/legacy/ngraph_ops/proposal_ie.hpp index d5a15561ef4..d1fcc6a95ed 100644 --- a/inference-engine/src/legacy_api/include/legacy/ngraph_ops/proposal_ie.hpp +++ b/inference-engine/src/legacy_api/include/legacy/ngraph_ops/proposal_ie.hpp @@ -34,7 +34,7 @@ public: std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - + bool visit_attributes(AttributeVisitor& visitor) override; const ProposalAttrs& get_attrs() const { return m_attrs; } private: diff --git a/inference-engine/src/legacy_api/include/legacy/ngraph_ops/selu_ie.hpp b/inference-engine/src/legacy_api/include/legacy/ngraph_ops/selu_ie.hpp index b776a9da333..80fef80c9c6 100644 --- a/inference-engine/src/legacy_api/include/legacy/ngraph_ops/selu_ie.hpp +++ b/inference-engine/src/legacy_api/include/legacy/ngraph_ops/selu_ie.hpp @@ -25,7 +25,7 @@ public: void validate_and_infer_types() override; std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - + bool visit_attributes(AttributeVisitor& visitor) override; float gamma, alpha; }; diff --git a/inference-engine/src/legacy_api/include/legacy/ngraph_ops/tile_ie.hpp b/inference-engine/src/legacy_api/include/legacy/ngraph_ops/tile_ie.hpp index 63102253d8e..ac08cf35735 100644 --- a/inference-engine/src/legacy_api/include/legacy/ngraph_ops/tile_ie.hpp +++ b/inference-engine/src/legacy_api/include/legacy/ngraph_ops/tile_ie.hpp @@ -23,7 +23,7 @@ public: const int64_t tiles); void validate_and_infer_types() override; - + bool visit_attributes(AttributeVisitor& visitor) override; std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; int64_t axis, tiles; diff --git a/inference-engine/src/legacy_api/src/convert_function_to_cnn_network.cpp b/inference-engine/src/legacy_api/src/convert_function_to_cnn_network.cpp index b163cbeeaac..c728b732c4b 100644 --- a/inference-engine/src/legacy_api/src/convert_function_to_cnn_network.cpp +++ b/inference-engine/src/legacy_api/src/convert_function_to_cnn_network.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include "ngraph_ops/convolution_ie.hpp" @@ -105,7 +106,10 @@ public: } void on_adapter(const std::string& name, ::ngraph::ValueAccessor& adapter) override { - params[name] = std::to_string(adapter.get()); + std::ostringstream stream; + stream.precision(8); + stream << std::fixed << adapter.get(); + params[name] = stream.str(); } void on_adapter(const std::string& name, ::ngraph::ValueAccessor& adapter) override { @@ -458,32 +462,25 @@ InferenceEngine::details::CNNLayerCreator::CNNLayerCreator(const std::shared_ptr details::convertPrecision(node->get_output_element_type(0))}; auto res = std::make_shared(attrs); res->params = params; - auto parseBoolStrToIntStr = [](const std::string ¶m) -> const std::string { - if (param == "true") { - return "1"; - } - else if (param == "false") { - return "0"; - } - return param; - }; + if (res->params["code_type"] == "caffe.priorboxparameter.center_size"){ res->params["code_type"] = "caffe.PriorBoxParameter.CENTER_SIZE"; } else{ res->params["code_type"] = "caffe.PriorBoxParameter.CORNER"; } - res->params["variance_encoded_in_target"] = parseBoolStrToIntStr(res->params["variance_encoded_in_target"]); - res->params["share_location"] = parseBoolStrToIntStr(res->params["share_location"]); - res->params["clip_after_nms"] = parseBoolStrToIntStr(res->params["clip_after_nms"]); - res->params["clip_before_nms"] = parseBoolStrToIntStr(res->params["clip_before_nms"]); - res->params["decrease_label_id"] = parseBoolStrToIntStr(res->params["decrease_label_id"]); - res->params["normalized"] = parseBoolStrToIntStr(res->params["normalized"]); + res->params["variance_encoded_in_target"] = res->getBoolStrParamAsIntStr("variance_encoded_in_target"); + res->params["share_location"] = res->getBoolStrParamAsIntStr("share_location"); + res->params["clip_after_nms"] = res->getBoolStrParamAsIntStr("clip_after_nms"); + res->params["clip_before_nms"] = res->getBoolStrParamAsIntStr("clip_before_nms"); + res->params["decrease_label_id"] = res->getBoolStrParamAsIntStr("decrease_label_id"); + res->params["normalized"] = res->getBoolStrParamAsIntStr("normalized"); return res; }); - addSpecificCreator({"LogicalNot"}, [](const std::shared_ptr<::ngraph::Node>& node, - const std::map params) -> CNNLayerPtr { + addSpecificCreator({"LogicalNot"}, + [](const std::shared_ptr<::ngraph::Node>& node, + const std::map params) -> CNNLayerPtr { LayerParams attrs = {node->get_friendly_name(), "Activation", details::convertPrecision(node->get_output_element_type(0))}; auto res = std::make_shared(attrs); @@ -491,8 +488,9 @@ InferenceEngine::details::CNNLayerCreator::CNNLayerCreator(const std::shared_ptr return res; }); - addSpecificCreator({"LSTMCellIE"}, [](const std::shared_ptr<::ngraph::Node>& node, - const std::map params) -> CNNLayerPtr { + addSpecificCreator({"LSTMCellIE"}, + [](const std::shared_ptr<::ngraph::Node>& node, + const std::map params) -> CNNLayerPtr { LayerParams attrs = {node->get_friendly_name(), "LSTMCell", details::convertPrecision(node->get_output_element_type(0))}; auto res = std::make_shared(attrs); @@ -506,8 +504,9 @@ InferenceEngine::details::CNNLayerCreator::CNNLayerCreator(const std::shared_ptr return res; }); - addSpecificCreator({"RNNCellIE"}, [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { + addSpecificCreator({"RNNCellIE"}, + [](const std::shared_ptr<::ngraph::Node>& node, + const std::map& params) -> CNNLayerPtr { LayerParams attrs = {node->get_friendly_name(), "RNNCell", details::convertPrecision(node->get_output_element_type(0))}; auto res = std::make_shared(attrs); @@ -522,8 +521,9 @@ InferenceEngine::details::CNNLayerCreator::CNNLayerCreator(const std::shared_ptr return res; }); - addSpecificCreator({"GRUCellIE"}, [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { + addSpecificCreator({"GRUCellIE"}, + [](const std::shared_ptr<::ngraph::Node>& node, + const std::map& params) -> CNNLayerPtr { LayerParams attrs = {node->get_friendly_name(), "GRUCell", details::convertPrecision(node->get_output_element_type(0))}; auto res = std::make_shared(attrs); @@ -538,6 +538,186 @@ InferenceEngine::details::CNNLayerCreator::CNNLayerCreator(const std::shared_ptr return res; }); + addSpecificCreator({"PRelu"}, + [](const std::shared_ptr<::ngraph::Node>& node, + const std::map& params) -> CNNLayerPtr { + LayerParams attrs = {node->get_friendly_name(), "PReLU", + details::convertPrecision(node->get_output_element_type(0))}; + auto res = std::make_shared(attrs); + res->params = params; + + const auto weightsNode = node->input_value(1).get_node_shared_ptr(); + InferenceEngine::details::addBlob(weightsNode, res, InferenceEngine::details::weights); + + return res; + }); + + addSpecificCreator({"TileIE"}, + [](const std::shared_ptr<::ngraph::Node>& node, + const std::map& params) -> CNNLayerPtr { + LayerParams attrs = {node->get_friendly_name(), "Tile", + details::convertPrecision(node->get_output_element_type(0))}; + auto res = std::make_shared(attrs); + res->params = params; + return res; + }); + + addSpecificCreator({"PriorBoxIE"}, + [](const std::shared_ptr<::ngraph::Node>& node, + const std::map& params) -> CNNLayerPtr { + LayerParams attrs = {node->get_friendly_name(), "PriorBox", + details::convertPrecision(node->get_output_element_type(0))}; + + auto res = std::make_shared(attrs); + res->params = params; + res->params["clip"] = res->getBoolStrParamAsIntStr("clip"); + res->params["flip"] = res->getBoolStrParamAsIntStr("flip"); + res->params["scale_all_sizes"] = res->getBoolStrParamAsIntStr("scale_all_sizes"); + + auto scale_all_sizes = std::stoi(res->params["scale_all_sizes"]); + if (!scale_all_sizes) { + auto data_pshape = node->get_input_partial_shape(0); + if (data_pshape.is_dynamic()) THROW_IE_EXCEPTION << "Dynamic 0-port input of PriorBox is not supported"; + auto data_shape = data_pshape.to_shape(); + if (data_shape.size() != 4) THROW_IE_EXCEPTION << "PriorBox has " << data_shape.size() << " items in 0-port input, 4 expected"; + auto img_pshape = node->get_input_partial_shape(1); + if (img_pshape.is_dynamic()) THROW_IE_EXCEPTION << "Dynamic 1-port input of PriorBox is not supported"; + auto img_shape = img_pshape.to_shape(); + if (img_shape.size() != 4) THROW_IE_EXCEPTION << "PriorBox has " << data_shape.size() << " items in 1-port input, 4 expected"; + + // mxnet-like PriorBox + auto img_H = img_shape[2]; + auto data_H = data_shape[2]; + + auto step = std::stof(res->params["step"]); + if (step == -1) + step = img_H / static_cast(data_H); + else + step *= img_H; + res->params["step"] = Builder::asString(step); + + auto min_size = details::split(res->params["min_size"], ","); + for (auto &size : min_size) { + size = Builder::asString(std::stof(size) * img_H); + } + res->params["min_size"] = details::joinVec(min_size); + } + return res; + }); + + addSpecificCreator({"PriorBoxClusteredIE"}, + [](const std::shared_ptr<::ngraph::Node>& node, + const std::map& params) -> CNNLayerPtr { + LayerParams attrs = {node->get_friendly_name(), "PriorBoxClustered", + details::convertPrecision(node->get_output_element_type(0))}; + auto res = std::make_shared(attrs); + res->params = params; + res->params["clip"] = + res->getBoolStrParamAsIntStr("clip"); + + auto step_h = std::stof(res->params["step_h"]); + auto step_w = std::stof(res->params["step_w"]); + if (std::abs(step_h - step_w) < 1e-5) { + res->params["step"] = res->params["step_w"]; + } + return res; + }); + + addSpecificCreator({"ProposalIE"}, + [](const std::shared_ptr<::ngraph::Node>& node, + const std::map& params) -> CNNLayerPtr { + LayerParams attrs = {node->get_friendly_name(), "Proposal", + details::convertPrecision(node->get_output_element_type(0))}; + auto res = std::make_shared(attrs); + res->params = params; + res->params["clip_before_nms"] = + res->getBoolStrParamAsIntStr("clip_before_nms"); + res->params["clip_after_nms"] = + res->getBoolStrParamAsIntStr("clip_after_nms"); + res->params["normalize"] = res->getBoolStrParamAsIntStr("normalize"); + return res; + }); + + addSpecificCreator({"Relu"}, + [](const std::shared_ptr<::ngraph::Node>& node, + const std::map& params) -> CNNLayerPtr { + LayerParams attrs = {node->get_friendly_name(), "ReLU", + details::convertPrecision(node->get_output_element_type(0))}; + auto res = std::make_shared(attrs); + res->params = params; + return res; + }); + + addSpecificCreator({"Reshape"}, + [](const std::shared_ptr<::ngraph::Node>& node, + const std::map& params) -> CNNLayerPtr { + LayerParams attrs = {node->get_friendly_name(), "Reshape", + details::convertPrecision(node->get_output_element_type(0))}; + auto res = std::make_shared(attrs); + return res; + }); + + addSpecificCreator({"ReverseSequence"}, + [](const std::shared_ptr<::ngraph::Node>& node, + const std::map& params) -> CNNLayerPtr { + LayerParams attrs = {node->get_friendly_name(), "ReverseSequence", + details::convertPrecision(node->get_output_element_type(0))}; + auto res = std::make_shared(attrs); + res->params = params; + return res; + }); + + addSpecificCreator({"SeluIE"}, + [](const std::shared_ptr<::ngraph::Node>& node, + const std::map& params) -> CNNLayerPtr { + LayerParams attrs = {node->get_friendly_name(), "Selu", + details::convertPrecision(node->get_output_element_type(0))}; + auto res = std::make_shared(attrs); + res->params = params; + return res; + }); + + addSpecificCreator({"Softmax"}, + [](const std::shared_ptr<::ngraph::Node>& node, + const std::map& params) -> CNNLayerPtr { + LayerParams attrs = {node->get_friendly_name(), "SoftMax", + details::convertPrecision(node->get_output_element_type(0))}; + auto res = std::make_shared(attrs); + res->params = params; + return res; + }); + + addSpecificCreator({"Split"}, + [](const std::shared_ptr<::ngraph::Node>& node, + const std::map& params) -> CNNLayerPtr { + LayerParams attrs = {node->get_friendly_name(), "Split", + details::convertPrecision(node->get_output_element_type(0))}; + auto res = std::make_shared(attrs); + + auto axis_node = node->input_value(1).get_node_shared_ptr(); + const auto axis_node_const = std::dynamic_pointer_cast(axis_node); + if (!axis_node_const) { + THROW_IE_EXCEPTION << "Split " << node->get_friendly_name() << " has no axes as Constant"; + } + auto axis = axis_node_const->cast_vector()[0]; + if (axis < 0) { + axis += node->get_input_shape(0).size(); + } + res->params["axis"] = Builder::asString(axis); + + return res; + }); + + addSpecificCreator({"Tanh"}, + [](const std::shared_ptr<::ngraph::Node>& node, + const std::map& params) -> CNNLayerPtr { + LayerParams attrs = {node->get_friendly_name(), "TanH", + details::convertPrecision(node->get_output_element_type(0))}; + auto res = std::make_shared(attrs); + res->params = params; + return res; + }); + addSpecificCreator({"ScatterElementsUpdate"}, [](const std::shared_ptr<::ngraph::Node>& node, const std::map& params) -> CNNLayerPtr { LayerParams attrs = {node->get_friendly_name(), node->description(), @@ -1032,7 +1212,6 @@ void convertFunctionToICNNNetwork(const std::shared_ptr>(), std::make_shared>(), std::make_shared>(), - std::make_shared>(), std::make_shared>(), std::make_shared>(), std::make_shared>(), @@ -1042,29 +1221,16 @@ void convertFunctionToICNNNetwork(const std::shared_ptr>(), std::make_shared>(), std::make_shared>(), - std::make_shared>(), - std::make_shared>(), std::make_shared>(), - std::make_shared>(), - std::make_shared>(), - std::make_shared>(), - std::make_shared>(), - std::make_shared>(), std::make_shared>(), - std::make_shared>(), std::make_shared>(), std::make_shared>(), std::make_shared>(), - std::make_shared>(), std::make_shared>(), std::make_shared>(), std::make_shared>(), - std::make_shared>(), - std::make_shared>(), std::make_shared>(), std::make_shared>(), - std::make_shared>(), - std::make_shared>(), std::make_shared>(), std::make_shared>(), std::make_shared>(), diff --git a/inference-engine/src/legacy_api/src/ie_cnn_layer_builder_ngraph.cpp b/inference-engine/src/legacy_api/src/ie_cnn_layer_builder_ngraph.cpp index 50bba3d3b5f..faedfc71f9f 100644 --- a/inference-engine/src/legacy_api/src/ie_cnn_layer_builder_ngraph.cpp +++ b/inference-engine/src/legacy_api/src/ie_cnn_layer_builder_ngraph.cpp @@ -424,28 +424,6 @@ CNNLayer::Ptr NodeConverter::createLayer(const std::shared_ptr return res; } -template <> -CNNLayer::Ptr NodeConverter::createLayer(const std::shared_ptr& layer) const { - LayerParams params = {layer->get_friendly_name(), "ReLU", - details::convertPrecision(layer->get_output_element_type(0))}; - auto res = std::make_shared(params); - return res; -} - -template <> -CNNLayer::Ptr NodeConverter::createLayer(const std::shared_ptr& layer) const { - LayerParams params = {layer->get_friendly_name(), "Selu", - details::convertPrecision(layer->get_output_element_type(0))}; - auto res = std::make_shared(params); - - auto castedLayer = ngraph::as_type_ptr(layer); - if (castedLayer == nullptr) THROW_IE_EXCEPTION << "Cannot get " << params.type << " layer " << params.name; - - res->params["alpha"] = asString(castedLayer->alpha); - res->params["gamma"] = asString(castedLayer->gamma); - return res; -} - template <> CNNLayer::Ptr NodeConverter::createLayer(const std::shared_ptr& layer) const { LayerParams params = {layer->get_friendly_name(), "ReLU", @@ -524,18 +502,6 @@ CNNLayer::Ptr NodeConverter::createLayer(const std::shared_p return res; } -template <> -CNNLayer::Ptr NodeConverter::createLayer(const std::shared_ptr& layer) const { - LayerParams params = {layer->get_friendly_name(), "SoftMax", - details::convertPrecision(layer->get_output_element_type(0))}; - auto res = std::make_shared(params); - auto castedLayer = ngraph::as_type_ptr(layer); - if (castedLayer == nullptr) THROW_IE_EXCEPTION << "Cannot get " << params.type << " layer " << params.name; - - res->params["axis"] = asString(castedLayer->get_axis()); - return res; -} - template <> CNNLayer::Ptr NodeConverter::createLayer(const std::shared_ptr& layer) const { LayerParams params = {layer->get_friendly_name(), "Eltwise", @@ -545,15 +511,6 @@ CNNLayer::Ptr NodeConverter::createLayer(const std::sh return res; } -template <> -CNNLayer::Ptr NodeConverter::createLayer(const std::shared_ptr& layer) const { - LayerParams params = {layer->get_friendly_name(), "Eltwise", - details::convertPrecision(layer->get_output_element_type(0))}; - auto res = std::make_shared(params); - res->params["operation"] = "pow"; - return res; -} - template <> CNNLayer::Ptr NodeConverter::createLayer(const std::shared_ptr& layer) const { LayerParams params = {layer->get_friendly_name(), "Eltwise", @@ -814,22 +771,6 @@ CNNLayer::Ptr NodeConverter::createLayer(const std::sha return res; } -template <> -CNNLayer::Ptr NodeConverter::createLayer(const std::shared_ptr& layer) const { - LayerParams params = {layer->get_friendly_name(), "ROIPooling", - details::convertPrecision(layer->get_output_element_type(0))}; - auto res = std::make_shared(params); - auto castedLayer = ngraph::as_type_ptr(layer); - if (castedLayer == nullptr) THROW_IE_EXCEPTION << "Cannot get " << params.type << " layer " << params.name; - - res->params["pooled_h"] = asString(castedLayer->get_output_size()[0]); - res->params["pooled_w"] = asString(castedLayer->get_output_size()[1]); - res->params["spatial_scale"] = asString(castedLayer->get_spatial_scale()); - res->params["method"] = castedLayer->get_method(); - - return res; -} - template <> CNNLayer::Ptr NodeConverter::createLayer(const std::shared_ptr& layer) const { LayerParams params = {layer->get_friendly_name(), "PSROIPooling", @@ -873,56 +814,6 @@ CNNLayer::Ptr NodeConverter::createLayer return res; } -template <> -CNNLayer::Ptr NodeConverter::createLayer(const std::shared_ptr& layer) const { - LayerParams params = {layer->get_friendly_name(), "PReLU", - details::convertPrecision(layer->get_output_element_type(0))}; - auto res = std::make_shared(params); - auto castedLayer = ngraph::as_type_ptr(layer); - if (castedLayer == nullptr) THROW_IE_EXCEPTION << "Cannot get " << params.type << " layer " << params.name; - - const auto weightsNode = castedLayer->input_value(1).get_node_shared_ptr(); - if (auto const_weights = ngraph::as_type_ptr(weightsNode)) { - SizeVector dataShape = const_weights->get_shape(); - if (dataShape.size() >= 2 && ngraph::shape_size(dataShape) == dataShape[1]) { - dataShape = {dataShape[1]}; - } - - Blob::Ptr dataBlb = InferenceEngine::details::shareWeights(const_weights); - - res->blobs["weights"] = dataBlb; - res->_weights = dataBlb; - } - - auto const_shape = castedLayer->input(1).get_shape(), tensor_shape = castedLayer->input(0).get_shape(); - if (const_shape.size() == 1 && const_shape[0] == 1) { - res->params["channel_shared"] = "true"; - } - - return res; -} - -template <> -CNNLayer::Ptr NodeConverter::createLayer(const std::shared_ptr& layer) const { - LayerParams params = {layer->get_friendly_name(), "Split", - details::convertPrecision(layer->get_output_element_type(0))}; - auto res = std::make_shared(params); - auto castedLayer = ngraph::as_type_ptr(layer); - if (castedLayer == nullptr) THROW_IE_EXCEPTION << "Cannot get " << params.type << " layer " << params.name; - - auto axis_node = castedLayer->input_value(1).get_node_shared_ptr(); - const auto axis_node_const = std::dynamic_pointer_cast(axis_node); - if (!axis_node_const) { - THROW_IE_EXCEPTION << "Split " << castedLayer->get_friendly_name() << " has no axes as Constant"; - } - auto axis = axis_node_const->cast_vector()[0]; - if (axis < 0) { - axis += castedLayer->get_input_shape(0).size(); - } - res->params["axis"] = asString(axis); - return res; -} - template <> CNNLayer::Ptr NodeConverter::createLayer(const std::shared_ptr& layer) const { LayerParams params = {layer->get_friendly_name(), "Split", @@ -995,31 +886,6 @@ CNNLayer::Ptr NodeConverter::createLayer(const std::shared_ return res; } -template <> -CNNLayer::Ptr NodeConverter::createLayer(const std::shared_ptr& layer) const { - LayerParams params = {layer->get_friendly_name(), "Reshape", - details::convertPrecision(layer->get_output_element_type(0))}; - - auto castedLayer = ngraph::as_type_ptr(layer); - if (castedLayer == nullptr) - THROW_IE_EXCEPTION << "Cannot get " << params.type << " layer " << params.name; - - - const auto constNode = castedLayer->input_value(1).get_node_shared_ptr(); - if (auto constValue = ngraph::as_type_ptr(constNode)) { - auto value = constValue->cast_vector(); - for (auto & i : value) { - if (i == 0 && !castedLayer->get_special_zero()) - THROW_IE_EXCEPTION << "Reshape " << params.name << " has `special_zero`=False and zeros in second input. This combination is not supported"; - } - } else { - THROW_IE_EXCEPTION << "Reshape " << params.name << " has dynamic second input!"; - } - - auto res = std::make_shared(params); - return res; -} - template <> CNNLayer::Ptr NodeConverter::createLayer(const std::shared_ptr& layer) const { LayerParams params = {layer->get_friendly_name(), "ScaleShift", @@ -1057,164 +923,6 @@ CNNLayer::Ptr NodeConverter::createLayer(const std: return res; } -template <> -CNNLayer::Ptr NodeConverter::createLayer(const std::shared_ptr& layer) const { - LayerParams params = {layer->get_friendly_name(), "Proposal", - details::convertPrecision(layer->get_output_element_type(0))}; - auto res = std::make_shared(params); - auto castedLayer = ngraph::as_type_ptr(layer); - if (castedLayer == nullptr) THROW_IE_EXCEPTION << "Cannot get " << params.type << " layer " << params.name; - - auto attr = castedLayer->get_attrs(); - std::string param; - for (const auto& val : attr.ratio) { - if (!param.empty()) param += ","; - param += asString(val); - } - res->params["ratio"] = param; - - param.clear(); - for (const auto& val : attr.scale) { - if (!param.empty()) param += ","; - param += asString(val); - } - res->params["scale"] = param; - - res->params["base_size"] = asString(attr.base_size); - res->params["pre_nms_topn"] = asString(attr.pre_nms_topn); - res->params["post_nms_topn"] = asString(attr.post_nms_topn); - res->params["nms_thresh"] = asString(attr.nms_thresh); - res->params["feat_stride"] = asString(attr.feat_stride); - res->params["min_size"] = asString(attr.min_size); - res->params["box_size_scale"] = asString(attr.box_size_scale); - res->params["box_coordinate_scale"] = asString(attr.box_coordinate_scale); - res->params["clip_before_nms"] = asString(attr.clip_before_nms ? 1 : 0); - res->params["clip_after_nms"] = asString(attr.clip_after_nms ? 1 : 0); - res->params["normalize"] = asString(attr.normalize ? 1 : 0); - res->params["framework"] = attr.framework; - - return res; -} - -template <> -CNNLayer::Ptr NodeConverter::createLayer( - const std::shared_ptr& layer) const { - LayerParams params = {layer->get_friendly_name(), "PriorBoxClustered", - details::convertPrecision(layer->get_output_element_type(0))}; - auto res = std::make_shared(params); - auto castedLayer = ngraph::as_type_ptr(layer); - if (castedLayer == nullptr) THROW_IE_EXCEPTION << "Cannot get " << params.type << " layer " << params.name; - - auto attr = castedLayer->get_attrs(); - std::string param; - for (const auto& val : attr.widths) { - if (!param.empty()) param += ","; - param += asString(val); - } - res->params["width"] = param; - - param.clear(); - for (const auto& val : attr.heights) { - if (!param.empty()) param += ","; - param += asString(val); - } - res->params["height"] = param; - - param.clear(); - for (const auto& val : attr.variances) { - if (!param.empty()) param += ","; - param += asString(val); - } - res->params["variance"] = param; - - if (std::abs(attr.step_heights - attr.step_widths) < 1e-5) { - res->params["step"] = asString(attr.step_widths); - } else { - res->params["step_w"] = asString(attr.step_widths); - res->params["step_h"] = asString(attr.step_heights); - } - res->params["offset"] = asString(attr.offset); - res->params["clip"] = asString(attr.clip ? 1 : 0); - res->params["flip"] = "1"; - - return res; -} - -template <> -CNNLayer::Ptr NodeConverter::createLayer(const std::shared_ptr& layer) const { - LayerParams params = {layer->get_friendly_name(), "PriorBox", - details::convertPrecision(layer->get_output_element_type(0))}; - auto res = std::make_shared(params); - auto castedLayer = ngraph::as_type_ptr(layer); - auto layer_info = params.type + " layer " + params.name; - - if (castedLayer == nullptr) THROW_IE_EXCEPTION << "Cannot get " << layer_info; - - auto attr = castedLayer->get_attrs(); - std::string param; - - auto data_pshape = castedLayer->get_input_partial_shape(0); - if (data_pshape.is_dynamic()) THROW_IE_EXCEPTION << "Dynamic 0-port input of " << layer_info << " is not supported"; - auto data_shape = data_pshape.to_shape(); - if (data_shape.size() != 4) THROW_IE_EXCEPTION << layer_info << " has " << data_shape.size() << " items in 0-port input, 4 expected"; - - auto img_pshape = castedLayer->get_input_partial_shape(1); - if (img_pshape.is_dynamic()) THROW_IE_EXCEPTION << "Dynamic 1-port input of " << layer_info << " is not supported"; - auto img_shape = img_pshape.to_shape(); - if (img_shape.size() != 4) THROW_IE_EXCEPTION << layer_info << " has " << data_shape.size() << " items in 1-port input, 4 expected"; - - if (!attr.scale_all_sizes) { - // mxnet-like PriorBox - auto img_H = img_shape[2]; - auto data_H = data_shape[2]; - if (attr.step == -1) - attr.step = static_cast(1. * img_H / data_H); - else - attr.step *= img_H; - for (auto& size : attr.min_size) - size *= img_H; - } - - for (const auto& val : attr.max_size) { - if (!param.empty()) param += ","; - param += asString(val); - } - res->params["max_size"] = param; - - param.clear(); - for (const auto& val : attr.min_size) { - if (!param.empty()) param += ","; - param += asString(val); - } - res->params["min_size"] = param; - - param.clear(); - for (const auto& val : attr.aspect_ratio) { - if (!param.empty()) param += ","; - param += asString(val); - } - res->params["aspect_ratio"] = param; - - param.clear(); - for (const auto& val : attr.variance) { - if (!param.empty()) param += ","; - param += asString(val); - } - res->params["variance"] = param; - - res->params["step"] = asString(attr.step); - res->params["offset"] = asString(attr.offset); - res->params["clip"] = asString(attr.clip ? 1 : 0); - res->params["flip"] = asString(attr.flip ? 1 : 0); - res->params["scale_all_sizes"] = asString(attr.scale_all_sizes ? 1 : 0); - - res->params["density"] = asString(attr.density); - res->params["fixed_size"] = asString(attr.fixed_size); - res->params["fixed_ratio"] = asString(attr.fixed_ratio); - - return res; -} - template <> CNNLayer::Ptr NodeConverter::createLayer(const std::shared_ptr& layer) const { LayerParams params = {layer->get_friendly_name(), "Power", @@ -1258,20 +966,6 @@ CNNLayer::Ptr NodeConverter::createLayer(const std::shared_ return res; } -template <> -CNNLayer::Ptr NodeConverter::createLayer(const std::shared_ptr& layer) const { - LayerParams params = {layer->get_friendly_name(), "Tile", - details::convertPrecision(layer->get_output_element_type(0))}; - auto res = std::make_shared(params); - auto castedLayer = ngraph::as_type_ptr(layer); - if (castedLayer == nullptr) THROW_IE_EXCEPTION << "Cannot get " << params.type << " layer " << params.name; - - res->params["axis"] = asString(castedLayer->axis); - res->params["tiles"] = asString(castedLayer->tiles); - - return res; -} - template <> CNNLayer::Ptr NodeConverter::createLayer(const std::shared_ptr& layer) const { LayerParams params = {layer->get_friendly_name(), "Resample", details::convertPrecision(layer->get_output_element_type(0))}; diff --git a/inference-engine/src/legacy_api/src/ie_layers.cpp b/inference-engine/src/legacy_api/src/ie_layers.cpp index 55d0c88f265..11f8f8b0fe8 100644 --- a/inference-engine/src/legacy_api/src/ie_layers.cpp +++ b/inference-engine/src/legacy_api/src/ie_layers.cpp @@ -306,6 +306,16 @@ std::string CNNLayer::GetParamAsString(const char* param) const { return (*it).second; } +std::string CNNLayer::getBoolStrParamAsIntStr(const char *param) const { + std::string val = GetParamAsString(param); + if (val == "true" || val == "True") { + return "1"; + } else if (val == "false" || val == "False") { + return "0"; + } + return val; +} + std::vector CNNLayer::GetParamAsStrings(const char* param, std::vector def) const { std::string vals = GetParamAsString(param, ""); std::vector result; diff --git a/inference-engine/src/legacy_api/src/ngraph_ops/prior_box_clustered_ie.cpp b/inference-engine/src/legacy_api/src/ngraph_ops/prior_box_clustered_ie.cpp index 3bacb014fd1..4f0234c05fc 100644 --- a/inference-engine/src/legacy_api/src/ngraph_ops/prior_box_clustered_ie.cpp +++ b/inference-engine/src/legacy_api/src/ngraph_ops/prior_box_clustered_ie.cpp @@ -37,3 +37,27 @@ std::shared_ptr op::PriorBoxClusteredIE::clone_with_new_inputs(const Outpu check_new_args_count(this, new_args); return make_shared(new_args.at(0), new_args.at(1), m_attrs); } + +bool op::PriorBoxClusteredIE::visit_attributes(AttributeVisitor& visitor) +{ + float step = 0; + + visitor.on_attribute("step", step); + visitor.on_attribute("step_w", m_attrs.step_widths); + visitor.on_attribute("step_h", m_attrs.step_heights); + if(step != 0) { + // deserialization: if step_w/h is 0 replace it with step + if (m_attrs.step_widths == 0) { + m_attrs.step_widths = step; + } + if (m_attrs.step_heights == 0) { + m_attrs.step_heights = step; + } + } + visitor.on_attribute("width", m_attrs.widths); + visitor.on_attribute("height", m_attrs.heights); + visitor.on_attribute("clip", m_attrs.clip); + visitor.on_attribute("offset", m_attrs.offset); + visitor.on_attribute("variance", m_attrs.variances); + return true; +} diff --git a/inference-engine/src/legacy_api/src/ngraph_ops/prior_box_ie.cpp b/inference-engine/src/legacy_api/src/ngraph_ops/prior_box_ie.cpp index 7dbe4280348..8429807b91d 100644 --- a/inference-engine/src/legacy_api/src/ngraph_ops/prior_box_ie.cpp +++ b/inference-engine/src/legacy_api/src/ngraph_ops/prior_box_ie.cpp @@ -34,3 +34,19 @@ std::shared_ptr op::PriorBoxIE::clone_with_new_inputs(const OutputVector& check_new_args_count(this, new_args); return make_shared(new_args.at(0), new_args.at(1), m_attrs); } + +bool op::PriorBoxIE::visit_attributes(AttributeVisitor& visitor) { + visitor.on_attribute("min_size", m_attrs.min_size); + visitor.on_attribute("max_size", m_attrs.max_size); + visitor.on_attribute("aspect_ratio", m_attrs.aspect_ratio); + visitor.on_attribute("density", m_attrs.density); + visitor.on_attribute("fixed_ratio", m_attrs.fixed_ratio); + visitor.on_attribute("fixed_size", m_attrs.fixed_size); + visitor.on_attribute("clip", m_attrs.clip); + visitor.on_attribute("flip", m_attrs.flip); + visitor.on_attribute("step", m_attrs.step); + visitor.on_attribute("offset", m_attrs.offset); + visitor.on_attribute("variance", m_attrs.variance); + visitor.on_attribute("scale_all_sizes", m_attrs.scale_all_sizes); + return true; +} diff --git a/inference-engine/src/legacy_api/src/ngraph_ops/proposal_ie.cpp b/inference-engine/src/legacy_api/src/ngraph_ops/proposal_ie.cpp index 385a70a06bd..a77bcec2089 100644 --- a/inference-engine/src/legacy_api/src/ngraph_ops/proposal_ie.cpp +++ b/inference-engine/src/legacy_api/src/ngraph_ops/proposal_ie.cpp @@ -60,3 +60,21 @@ shared_ptr op::ProposalIE::clone_with_new_inputs(const OutputVector& new_a check_new_args_count(this, new_args); return make_shared(new_args.at(0), new_args.at(1), new_args.at(2), m_attrs); } + +bool op::ProposalIE::visit_attributes(AttributeVisitor& visitor){ + visitor.on_attribute("ratio", m_attrs.ratio); + visitor.on_attribute("scale", m_attrs.scale); + visitor.on_attribute("base_size", m_attrs.base_size); + visitor.on_attribute("pre_nms_topn", m_attrs.pre_nms_topn); + visitor.on_attribute("post_nms_topn", m_attrs.post_nms_topn); + visitor.on_attribute("nms_thresh", m_attrs.nms_thresh); + visitor.on_attribute("feat_stride", m_attrs.feat_stride); + visitor.on_attribute("min_size", m_attrs.min_size); + visitor.on_attribute("box_size_scale", m_attrs.box_size_scale); + visitor.on_attribute("box_coordinate_scale", m_attrs.box_coordinate_scale); + visitor.on_attribute("clip_before_nms", m_attrs.clip_before_nms); + visitor.on_attribute("clip_after_nms", m_attrs.clip_after_nms); + visitor.on_attribute("normalize", m_attrs.normalize); + visitor.on_attribute("framework", m_attrs.framework); + return true; +} diff --git a/inference-engine/src/legacy_api/src/ngraph_ops/selu_ie.cpp b/inference-engine/src/legacy_api/src/ngraph_ops/selu_ie.cpp index c55d4b8b9e9..172e7c63944 100644 --- a/inference-engine/src/legacy_api/src/ngraph_ops/selu_ie.cpp +++ b/inference-engine/src/legacy_api/src/ngraph_ops/selu_ie.cpp @@ -30,3 +30,9 @@ std::shared_ptr op::SeluIE::clone_with_new_inputs(const OutputVector& new_ void op::SeluIE::validate_and_infer_types() { set_output_type(0, get_input_element_type(0), get_input_partial_shape(0)); } + +bool op::SeluIE::visit_attributes(AttributeVisitor& visitor) { + visitor.on_attribute("alpha", alpha); + visitor.on_attribute("gamma", gamma); + return true; +} diff --git a/inference-engine/src/legacy_api/src/ngraph_ops/tile_ie.cpp b/inference-engine/src/legacy_api/src/ngraph_ops/tile_ie.cpp index 01a87887ff9..082ae48c757 100644 --- a/inference-engine/src/legacy_api/src/ngraph_ops/tile_ie.cpp +++ b/inference-engine/src/legacy_api/src/ngraph_ops/tile_ie.cpp @@ -41,3 +41,9 @@ void op::TileIE::validate_and_infer_types() { set_output_type(0, get_input_element_type(0), output_pshape); } + +bool op::TileIE::visit_attributes(AttributeVisitor& visitor){ + visitor.on_attribute("axis", axis); + visitor.on_attribute("tiles", tiles); + return true; +} diff --git a/inference-engine/src/readers/ir_reader/ie_ir_parser.cpp b/inference-engine/src/readers/ir_reader/ie_ir_parser.cpp index 306c9aad074..7bc61a5494c 100644 --- a/inference-engine/src/readers/ir_reader/ie_ir_parser.cpp +++ b/inference-engine/src/readers/ir_reader/ie_ir_parser.cpp @@ -405,7 +405,6 @@ std::shared_ptr V10Parser::createNode(const std::vector>("DepthToSpace"), std::make_shared>("Subtract"), std::make_shared>("Broadcast"), - std::make_shared>("Reshape"), std::make_shared>("StridedSlice"), std::make_shared>("Gather"), std::make_shared>("GreaterEqual"), @@ -424,23 +423,11 @@ std::shared_ptr V10Parser::createNode(const std::vector>("Minimum"), std::make_shared>("NonMaxSuppression"), std::make_shared>("NormalizeL2"), - std::make_shared>("PReLU"), - std::make_shared>("ReLU"), - std::make_shared>("Power"), - std::make_shared>("ReverseSequence"), - std::make_shared>("PriorBox"), - std::make_shared>("PriorBoxClustered"), std::make_shared>("ReorgYolo"), std::make_shared>("RegionYolo"), std::make_shared>("Result"), - std::make_shared>("ROIPooling"), std::make_shared>("PSROIPooling"), - std::make_shared>("Selu"), - std::make_shared>("Softmax"), - std::make_shared>("Split"), std::make_shared>("VariadicSplit"), - std::make_shared>("TanH"), - std::make_shared>("Tile"), std::make_shared>("TensorIterator"), std::make_shared>("Loop"), std::make_shared>("LogicalAnd"), @@ -496,11 +483,16 @@ std::shared_ptr V10Parser::createNode(const std::vector(opset.create(type)); + ngraphNode = std::shared_ptr(opset.create_insensitive(type)); ngraphNode->set_friendly_name(params.name); ngraphNode->set_arguments(inputs); XmlDeserializer visitor(node, weights); @@ -769,72 +761,6 @@ std::shared_ptr V10Parser::LayerCreator::cre return fillSubGraphLayer(inputs, node, weights, layerParsePrms, loop); } -// PriorBoxClustered layer -template <> -std::shared_ptr V10Parser::LayerCreator::createLayer( - const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights, - const GenericLayerParams& layerParsePrms) { - checkParameters(inputs, layerParsePrms, 2); - pugi::xml_node dn = node.child("data"); - - if (dn.empty()) - THROW_IE_EXCEPTION << "Cannot read parameter for " << getType() << " layer with name: " << layerParsePrms.name; - - ngraph::op::PriorBoxClusteredAttrs attr; - attr.widths = getParameters(dn, "width"); - attr.heights = getParameters(dn, "height"); - attr.variances = getParameters(dn, "variance"); - attr.offset = GetFloatAttr(dn, "offset"); - float step = GetFloatAttr(dn, "step", 0); - attr.step_heights = GetFloatAttr(dn, "step_h", step); - attr.step_widths = GetFloatAttr(dn, "step_w", step); - if (step != 0) { - attr.step_heights = step; - attr.step_widths = step; - } - attr.clip = (GetIntAttr(dn, "clip") != 0); - - return std::make_shared(inputs[0], inputs[1], attr); -} - -// PriorBox layer -template <> -std::shared_ptr V10Parser::LayerCreator::createLayer( - const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights, - const GenericLayerParams& layerParsePrms) { - checkParameters(inputs, layerParsePrms, 2); - pugi::xml_node dn = node.child("data"); - - if (dn.empty()) - THROW_IE_EXCEPTION << "Cannot read parameter for " << getType() << " layer with name: " << layerParsePrms.name; - - ngraph::op::PriorBoxAttrs attr; - attr.min_size = getParameters(dn, "min_size", {}); - attr.max_size = getParameters(dn, "max_size", {}); - attr.density = getParameters(dn, "density", {}); - attr.fixed_size = getParameters(dn, "fixed_size", {}); - attr.fixed_ratio = getParameters(dn, "fixed_ratio", {}); - attr.aspect_ratio = getParameters(dn, "aspect_ratio", {}); - attr.variance = getParameters(dn, "variance", {}); - attr.step = GetFloatAttr(dn, "step", 0); - attr.offset = GetFloatAttr(dn, "offset"); - attr.clip = (GetIntAttr(dn, "clip") != 0); - attr.flip = (GetIntAttr(dn, "flip") != 0); - attr.scale_all_sizes = (GetIntAttr(dn, "scale_all_sizes", 1) != 0); - - return std::make_shared(inputs[0], inputs[1], attr); -} - -// ReverseSequence layer -template <> -std::shared_ptr V10Parser::LayerCreator::createLayer(const ngraph::OutputVector & inputs, const pugi::xml_node& node, - const Blob::CPtr& weights, - const GenericLayerParams& layerParsePrms) { - checkParameters(inputs, layerParsePrms, 2); - pugi::xml_node dn = node.child("data"); - return std::make_shared(inputs[0], inputs[1], GetIntAttr(dn, "batch_axis", 0), GetIntAttr(dn, "seq_axis", 1)); -} - // Covnert layer template <> std::shared_ptr V10Parser::LayerCreator::createLayer( @@ -962,21 +888,6 @@ std::shared_ptr V10Parser::LayerCreator return std::make_shared(inputs[0], inputs[1], inputs[2]); } -// Split layer -template <> -std::shared_ptr V10Parser::LayerCreator::createLayer( - const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights, - const GenericLayerParams& layerParsePrms) { - pugi::xml_node dn = node.child("data"); - - if (dn.empty()) - THROW_IE_EXCEPTION << "Cannot read parameter for " << getType() << " layer with name: " << layerParsePrms.name; - - int num_splits = GetIntAttr(dn, "num_splits"); - checkParameters(inputs, layerParsePrms, 2); - return std::make_shared(inputs[0], inputs[1], num_splits); -} - // SpaceToDepth layer template <> std::shared_ptr V10Parser::LayerCreator::createLayer( @@ -1005,42 +916,6 @@ std::shared_ptr V10Parser::LayerCreator: return std::make_shared(inputs[0], GetStrAttr(dn, "mode"), GetIntAttr(dn, "block_size", 1)); } -// SeLU layer -template <> -std::shared_ptr V10Parser::LayerCreator::createLayer( - const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights, - const GenericLayerParams& layerParsePrms) { - checkParameters(inputs, layerParsePrms, 3); - return std::make_shared(inputs[0], inputs[1], inputs[2]); -} - -// PReLU layer -template <> -std::shared_ptr V10Parser::LayerCreator::createLayer( - const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights, - const GenericLayerParams& layerParsePrms) { - checkParameters(inputs, layerParsePrms, 2); - return std::make_shared(inputs[0], inputs[1]); -} - -// ReLU layer -template <> -std::shared_ptr V10Parser::LayerCreator::createLayer( - const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights, - const GenericLayerParams& layerParsePrms) { - checkParameters(inputs, layerParsePrms, 1); - return std::make_shared(inputs[0]); -} - -// Tanh layer -template <> -std::shared_ptr V10Parser::LayerCreator::createLayer( - const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights, - const GenericLayerParams& layerParsePrms) { - checkParameters(inputs, layerParsePrms, 1); - return std::make_shared(inputs[0]); -} - // Result layer template <> std::shared_ptr V10Parser::LayerCreator::createLayer( @@ -1050,15 +925,6 @@ std::shared_ptr V10Parser::LayerCreator::creat return std::make_shared(inputs[0]); } -// Tile layer -template <> -std::shared_ptr V10Parser::LayerCreator::createLayer( - const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights, - const GenericLayerParams& layerParsePrms) { - checkParameters(inputs, layerParsePrms, 2); - return std::make_shared(inputs[0], inputs[1]); -} - // StridedSlice layer template <> std::shared_ptr V10Parser::LayerCreator::createLayer( @@ -1084,20 +950,6 @@ std::shared_ptr V10Parser::LayerCreator -std::shared_ptr V10Parser::LayerCreator::createLayer( - const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights, - const GenericLayerParams& layerParsePrms) { - checkParameters(inputs, layerParsePrms, 2); - - pugi::xml_node dn = node.child("data"); - if (dn.empty()) - THROW_IE_EXCEPTION << "Cannot read parameter for " << getType() << " layer with name: " << layerParsePrms.name; - - return std::make_shared(inputs[0], inputs[1], GetBoolAttr(dn, "special_zero")); -} - // Minimum layer template <> std::shared_ptr V10Parser::LayerCreator::createLayer( @@ -1129,29 +981,6 @@ std::shared_ptr V10Parser::LayerCreator THROW_IE_EXCEPTION << "Invalid number of inputs: " << layerParsePrms.inputPorts.size(); } -// Power layer -template <> -std::shared_ptr V10Parser::LayerCreator::createLayer( - const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights, - const GenericLayerParams& layerParsePrms) { - checkParameters(inputs, layerParsePrms, 2); - return std::make_shared(inputs[0], inputs[1]); -} - -// Softmax layer -template <> -std::shared_ptr V10Parser::LayerCreator::createLayer( - const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights, - const GenericLayerParams& layerParsePrms) { - checkParameters(inputs, layerParsePrms, 1); - pugi::xml_node dn = node.child("data"); - - if (dn.empty()) - THROW_IE_EXCEPTION << "Cannot read parameter for " << getType() << " layer with name: " << layerParsePrms.name; - - return std::make_shared(inputs[0], GetUIntAttr(dn, "axis")); -} - // RegionYolo layer template <> std::shared_ptr V10Parser::LayerCreator::createLayer( @@ -1447,25 +1276,6 @@ std::shared_ptr V10Parser::LayerCreator:: pad_type); } -// ROIPooling layer -template <> -std::shared_ptr V10Parser::LayerCreator::createLayer( - const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights, - const GenericLayerParams& layerParsePrms) { - checkParameters(inputs, layerParsePrms, 2); - pugi::xml_node dn = node.child("data"); - - if (dn.empty()) - THROW_IE_EXCEPTION << "Cannot read parameter for " << getType() << " layer with name: " << layerParsePrms.name; - - auto pooled_h = GetUIntAttr(dn, "pooled_h"); - auto pooled_w = GetUIntAttr(dn, "pooled_w"); - auto spatial_scale = GetFloatAttr(dn, "spatial_scale"); - auto method = GetStrAttr(dn, "method", "max"); - return std::make_shared(inputs[0], inputs[1], - ngraph::Shape {pooled_h, pooled_w}, spatial_scale, method); -} - // PSROIPooling layer template <> std::shared_ptr V10Parser::LayerCreator::createLayer( diff --git a/inference-engine/tests/ie_test_utils/functional_test_utils/network_utils.cpp b/inference-engine/tests/ie_test_utils/functional_test_utils/network_utils.cpp index 8f4a507eec9..ced9fc340c6 100644 --- a/inference-engine/tests/ie_test_utils/functional_test_utils/network_utils.cpp +++ b/inference-engine/tests/ie_test_utils/functional_test_utils/network_utils.cpp @@ -159,6 +159,9 @@ namespace FuncTestUtils { } } else { if (item.first == "originalLayersNames") continue; + // ROIPooling specification says that there should be two parameters- pooled_h and pooled_w + // our implementation of this op has a single parameter - output_size. + if (item.first == "output_size" && layer->type == "ROIPooling") continue; // autob is a WA for nGraph ops if ((item.first != "auto_broadcast" && item.first != "autob") || item.second != "numpy") { success = false; diff --git a/ngraph/core/include/ngraph/op/prior_box.hpp b/ngraph/core/include/ngraph/op/prior_box.hpp index 5256826a26d..c861e680e91 100644 --- a/ngraph/core/include/ngraph/op/prior_box.hpp +++ b/ngraph/core/include/ngraph/op/prior_box.hpp @@ -41,10 +41,10 @@ namespace ngraph std::vector fixed_size; bool clip = false; bool flip = false; - float step = 1.0f; + float step = 0.0f; float offset = 0.0f; std::vector variance; - bool scale_all_sizes = false; + bool scale_all_sizes = true; }; namespace v0 diff --git a/ngraph/core/include/ngraph/op/prior_box_clustered.hpp b/ngraph/core/include/ngraph/op/prior_box_clustered.hpp index f97b15bbbeb..9af4a621640 100644 --- a/ngraph/core/include/ngraph/op/prior_box_clustered.hpp +++ b/ngraph/core/include/ngraph/op/prior_box_clustered.hpp @@ -33,9 +33,9 @@ namespace ngraph // variances Values to adjust prior boxes with std::vector widths; std::vector heights; - bool clip = false; - float step_widths = 1.0f; - float step_heights = 1.0f; + bool clip = true; + float step_widths = 0.0f; + float step_heights = 0.0f; float offset = 0.0f; std::vector variances; }; diff --git a/ngraph/core/include/ngraph/op/relu.hpp b/ngraph/core/include/ngraph/op/relu.hpp index df85a57f8d9..53a47e26de5 100644 --- a/ngraph/core/include/ngraph/op/relu.hpp +++ b/ngraph/core/include/ngraph/op/relu.hpp @@ -46,6 +46,7 @@ namespace ngraph bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; + bool visit_attributes(AttributeVisitor& visitor) override; }; } using v0::Relu; diff --git a/ngraph/core/include/ngraph/op/reverse_sequence.hpp b/ngraph/core/include/ngraph/op/reverse_sequence.hpp index 0746eb296d1..1e7ef15544e 100644 --- a/ngraph/core/include/ngraph/op/reverse_sequence.hpp +++ b/ngraph/core/include/ngraph/op/reverse_sequence.hpp @@ -56,7 +56,7 @@ namespace ngraph void set_sequence_axis(int64_t sequence_axis) { m_seq_axis = sequence_axis; } private: int64_t m_batch_axis; - int64_t m_seq_axis; + int64_t m_seq_axis = 1; size_t m_normalized_batch_axis; size_t m_normalized_seq_axis; }; diff --git a/ngraph/core/include/ngraph/op/roi_pooling.hpp b/ngraph/core/include/ngraph/op/roi_pooling.hpp index 0c45f2e4b7d..de38d26bbb7 100644 --- a/ngraph/core/include/ngraph/op/roi_pooling.hpp +++ b/ngraph/core/include/ngraph/op/roi_pooling.hpp @@ -54,9 +54,9 @@ namespace ngraph bool visit_attributes(AttributeVisitor& visitor) override; private: - Shape m_output_size; + Shape m_output_size{0, 0}; float m_spatial_scale; - std::string m_method; + std::string m_method = "max"; }; } // namespace v0 diff --git a/ngraph/core/include/ngraph/opsets/opset.hpp b/ngraph/core/include/ngraph/opsets/opset.hpp index 0b3b585f9cb..510500a48a1 100644 --- a/ngraph/core/include/ngraph/opsets/opset.hpp +++ b/ngraph/core/include/ngraph/opsets/opset.hpp @@ -98,7 +98,7 @@ namespace ngraph { std::lock_guard guard(get_mutex()); return m_case_insensitive_type_info_map.find(to_upper_name(name)) != - m_name_type_info_map.end(); + m_case_insensitive_type_info_map.end(); } /// \brief Return true if node's type is in the opset diff --git a/ngraph/core/src/op/prior_box_clustered.cpp b/ngraph/core/src/op/prior_box_clustered.cpp index 4b173c6a007..d0ad2773c43 100644 --- a/ngraph/core/src/op/prior_box_clustered.cpp +++ b/ngraph/core/src/op/prior_box_clustered.cpp @@ -96,13 +96,31 @@ shared_ptr op::PriorBoxClustered::clone_with_new_inputs(const OutputVector bool op::PriorBoxClustered::visit_attributes(AttributeVisitor& visitor) { - visitor.on_attribute("widths", m_attrs.widths); - visitor.on_attribute("heights", m_attrs.heights); + float step = 0; + float step_w_tmp = m_attrs.step_widths; + float step_h_tmp = m_attrs.step_heights; + + visitor.on_attribute("step", step); + visitor.on_attribute("step_w", m_attrs.step_widths); + visitor.on_attribute("step_h", m_attrs.step_heights); + if (step != 0) + { + // deserialization: + // if step_w/h is 0 or did not change, replace it with step + if (m_attrs.step_widths == 0 || m_attrs.step_widths == step_w_tmp) + { + m_attrs.step_widths = step; + } + if (m_attrs.step_heights == 0 || m_attrs.step_heights == step_h_tmp) + { + m_attrs.step_heights = step; + } + } + visitor.on_attribute("width", m_attrs.widths); + visitor.on_attribute("height", m_attrs.heights); visitor.on_attribute("clip", m_attrs.clip); - visitor.on_attribute("step_widths", m_attrs.step_widths); - visitor.on_attribute("step_heights", m_attrs.step_heights); visitor.on_attribute("offset", m_attrs.offset); - visitor.on_attribute("variances", m_attrs.variances); + visitor.on_attribute("variance", m_attrs.variances); return true; } diff --git a/ngraph/core/src/op/relu.cpp b/ngraph/core/src/op/relu.cpp index 634d654e66e..253db2653ad 100644 --- a/ngraph/core/src/op/relu.cpp +++ b/ngraph/core/src/op/relu.cpp @@ -81,3 +81,8 @@ bool op::Relu::evaluate(const HostTensorVector& outputs, const HostTensorVector& OV_ITT_SCOPED_TASK(itt::domains::nGraphOp, "op::Relu::evaluate"); return relu::evaluate_relu(inputs[0], outputs[0], shape_size(get_output_shape(0))); } + +bool op::Relu::visit_attributes(AttributeVisitor& visitor) +{ + return true; +} diff --git a/ngraph/core/src/op/roi_pooling.cpp b/ngraph/core/src/op/roi_pooling.cpp index 31dc072ea09..2002dc3654a 100644 --- a/ngraph/core/src/op/roi_pooling.cpp +++ b/ngraph/core/src/op/roi_pooling.cpp @@ -147,6 +147,8 @@ shared_ptr op::ROIPooling::clone_with_new_inputs(const OutputVector& new_a bool op::ROIPooling::visit_attributes(AttributeVisitor& visitor) { visitor.on_attribute("output_size", m_output_size); + visitor.on_attribute("pooled_h", m_output_size[0]); + visitor.on_attribute("pooled_w", m_output_size[1]); visitor.on_attribute("spatial_scale", m_spatial_scale); visitor.on_attribute("method", m_method); return true; diff --git a/ngraph/python/tests/test_ngraph/test_create_op.py b/ngraph/python/tests/test_ngraph/test_create_op.py index 996cad6eb1a..7c8d13b1c87 100644 --- a/ngraph/python/tests/test_ngraph/test_create_op.py +++ b/ngraph/python/tests/test_ngraph/test_create_op.py @@ -866,6 +866,7 @@ def test_prior_box(int_dtype, fp_dtype): "offset": fp_dtype(0), "min_size": np.array([2, 3], dtype=fp_dtype), "aspect_ratio": np.array([1.5, 2.0, 2.5], dtype=fp_dtype), + "scale_all_sizes": False } layer_shape = ng.constant(np.array([32, 32], dtype=int_dtype), int_dtype) @@ -896,8 +897,8 @@ def test_prior_box_clustered(int_dtype, fp_dtype): image_size = np.array([64, 64], dtype=int_dtype) attributes = { "offset": fp_dtype(0.5), - "widths": np.array([4.0, 2.0, 3.2], dtype=fp_dtype), - "heights": np.array([1.0, 2.0, 1.0], dtype=fp_dtype), + "width": np.array([4.0, 2.0, 3.2], dtype=fp_dtype), + "height": np.array([1.0, 2.0, 1.0], dtype=fp_dtype), } output_size = ng.constant(np.array([19, 19], dtype=int_dtype), int_dtype) diff --git a/ngraph/test/type_prop_layers.cpp b/ngraph/test/type_prop_layers.cpp index 1e2c0f01a79..1d4c012089d 100644 --- a/ngraph/test/type_prop_layers.cpp +++ b/ngraph/test/type_prop_layers.cpp @@ -79,6 +79,7 @@ TEST(type_prop_layers, prior_box1) op::PriorBoxAttrs attrs; attrs.min_size = {2.0f, 3.0f}; attrs.aspect_ratio = {1.5f, 2.0f, 2.5f}; + attrs.scale_all_sizes = false; auto layer_shape = op::Constant::create(element::i64, Shape{2}, {32, 32}); auto image_shape = op::Constant::create(element::i64, Shape{2}, {300, 300}); @@ -92,6 +93,7 @@ TEST(type_prop_layers, prior_box2) attrs.min_size = {2.0f, 3.0f}; attrs.aspect_ratio = {1.5f, 2.0f, 2.5f}; attrs.flip = true; + attrs.scale_all_sizes = false; auto layer_shape = op::Constant::create(element::i64, Shape{2}, {32, 32}); auto image_shape = op::Constant::create(element::i64, Shape{2}, {300, 300}); @@ -106,7 +108,6 @@ TEST(type_prop_layers, prior_box3) attrs.max_size = {315.0f}; attrs.aspect_ratio = {2.0f}; attrs.flip = true; - attrs.scale_all_sizes = true; auto layer_shape = op::Constant::create(element::i64, Shape{2}, {1, 1}); auto image_shape = op::Constant::create(element::i64, Shape{2}, {300, 300});