Common specific creator for ops to be converted to ie ops (#1928)
* Add common specific creator for ops to be converted to ie ops * fix cpu func tests * Add macro for specific creators
This commit is contained in:
parent
b9f698b456
commit
7d1c5877ff
@ -51,13 +51,22 @@
|
||||
namespace InferenceEngine {
|
||||
namespace details {
|
||||
|
||||
// helper for adding creators with a specific exception
|
||||
#define REQUIRED_IE_CONVERSION_CREATOR(type_name, ie_type_name)\
|
||||
addSpecificCreator({type_name}, [](const std::shared_ptr<::ngraph::Node>& node,\
|
||||
const std::map<std::string, std::string>& params) -> CNNLayerPtr {\
|
||||
THROW_IE_EXCEPTION << type_name << " operation has a form that is not supported. " << node->get_friendly_name()\
|
||||
<< " should be converted to " << ie_type_name << " operation.";\
|
||||
return nullptr;\
|
||||
});\
|
||||
|
||||
/**
|
||||
* @brief Creator for CNNLayer from nGraph op
|
||||
*/
|
||||
class CNNLayerCreator : public ::ngraph::AttributeVisitor {
|
||||
public:
|
||||
using CreatorFor = std::function<CNNLayerPtr(const std::shared_ptr<::ngraph::Node>& node,
|
||||
const std::map<std::string, std::string> param)>;
|
||||
const std::map<std::string, std::string>& param)>;
|
||||
explicit CNNLayerCreator(const std::shared_ptr<::ngraph::Node>& node);
|
||||
|
||||
CNNLayerPtr create();
|
||||
@ -138,6 +147,9 @@ void InferenceEngine::details::CNNLayerCreator::on_adapter(const std::string& na
|
||||
} else if (auto a = ::ngraph::as_type<::ngraph::AttributeAdapter<::ngraph::Strides>>(&adapter)) {
|
||||
auto shape = static_cast<::ngraph::Strides&>(*a);
|
||||
params[name] = joinVec(shape);
|
||||
} else if (auto a = ::ngraph::as_type<::ngraph::AttributeAdapter<std::vector<size_t>>>(& adapter)) {
|
||||
auto data = a->get();
|
||||
params[name] = joinVec(data);
|
||||
} else {
|
||||
THROW_IE_EXCEPTION << "Error converting ngraph to CNN network. "
|
||||
"Attribute adapter can not be found for " << name << " parameter";
|
||||
@ -146,7 +158,7 @@ void InferenceEngine::details::CNNLayerCreator::on_adapter(const std::string& na
|
||||
|
||||
InferenceEngine::details::CNNLayerCreator::CNNLayerCreator(const std::shared_ptr<::ngraph::Node>& node): node(node) {
|
||||
addSpecificCreator({"Parameter"}, [](const std::shared_ptr<::ngraph::Node>& node,
|
||||
const std::map<std::string, std::string> params) -> CNNLayerPtr {
|
||||
const std::map<std::string, std::string>& params) -> CNNLayerPtr {
|
||||
LayerParams attrs = {node->get_friendly_name(), "Input",
|
||||
details::convertPrecision(node->get_output_element_type(0))};
|
||||
auto res = std::make_shared<CNNLayer>(attrs);
|
||||
@ -155,7 +167,7 @@ InferenceEngine::details::CNNLayerCreator::CNNLayerCreator(const std::shared_ptr
|
||||
// TODO - Remove "GreaterEq" once ngraph transitions to GreaterEqual
|
||||
addSpecificCreator({"Eltwise", "Subtract", "Power", "Maximum", "Divide", "Greater", "GreaterEqual", "FloorMod", "LogicalOr", "LogicalAnd", "LogicalXor",
|
||||
"GreaterEq", "Less", "LessEqual", "Equal", "NotEqual", "Multiply", "Add"}, [](const std::shared_ptr<::ngraph::Node>& node,
|
||||
const std::map<std::string, std::string> params) -> CNNLayerPtr {
|
||||
const std::map<std::string, std::string>& params) -> CNNLayerPtr {
|
||||
LayerParams attrs = {node->get_friendly_name(), "Eltwise",
|
||||
details::convertPrecision(node->get_output_element_type(0))};
|
||||
auto res = std::make_shared<EltwiseLayer>(attrs);
|
||||
@ -214,7 +226,7 @@ InferenceEngine::details::CNNLayerCreator::CNNLayerCreator(const std::shared_ptr
|
||||
return res;
|
||||
});
|
||||
addSpecificCreator({"Concat"}, [](const std::shared_ptr<::ngraph::Node>& node,
|
||||
const std::map<std::string, std::string> params) -> CNNLayerPtr {
|
||||
const std::map<std::string, std::string>& params) -> CNNLayerPtr {
|
||||
LayerParams attrs = {node->get_friendly_name(), node->description(),
|
||||
details::convertPrecision(node->get_output_element_type(0))};
|
||||
auto res = std::make_shared<ConcatLayer>(attrs);
|
||||
@ -222,7 +234,7 @@ InferenceEngine::details::CNNLayerCreator::CNNLayerCreator(const std::shared_ptr
|
||||
return res;
|
||||
});
|
||||
addSpecificCreator({"AvgPool", "MaxPool"}, [](const std::shared_ptr<::ngraph::Node>& node,
|
||||
const std::map<std::string, std::string> params) -> CNNLayerPtr {
|
||||
const std::map<std::string, std::string>& params) -> CNNLayerPtr {
|
||||
LayerParams attrs = {node->get_friendly_name(), "Pooling",
|
||||
details::convertPrecision(node->get_output_element_type(0))};
|
||||
auto res = std::make_shared<PoolingLayer>(attrs);
|
||||
@ -244,7 +256,7 @@ InferenceEngine::details::CNNLayerCreator::CNNLayerCreator(const std::shared_ptr
|
||||
return res;
|
||||
});
|
||||
addSpecificCreator({"Select"}, [](const std::shared_ptr<::ngraph::Node>& node,
|
||||
const std::map<std::string, std::string> params) -> CNNLayerPtr {
|
||||
const std::map<std::string, std::string>& params) -> CNNLayerPtr {
|
||||
LayerParams attrs = {node->get_friendly_name(), node->description(),
|
||||
details::convertPrecision(node->get_output_element_type(0))};
|
||||
auto res = std::make_shared<SelectLayer>(attrs);
|
||||
@ -252,7 +264,7 @@ InferenceEngine::details::CNNLayerCreator::CNNLayerCreator(const std::shared_ptr
|
||||
return res;
|
||||
});
|
||||
addSpecificCreator({"BinaryConvolution"}, [](const std::shared_ptr<::ngraph::Node>& node,
|
||||
const std::map<std::string, std::string> params) -> CNNLayerPtr {
|
||||
const std::map<std::string, std::string>& params) -> CNNLayerPtr {
|
||||
LayerParams attrs = {node->get_friendly_name(), node->description(),
|
||||
details::convertPrecision(node->get_output_element_type(0))};
|
||||
auto res = std::make_shared<BinaryConvolutionLayer>(attrs);
|
||||
@ -341,7 +353,7 @@ InferenceEngine::details::CNNLayerCreator::CNNLayerCreator(const std::shared_ptr
|
||||
});
|
||||
|
||||
addSpecificCreator({"SpaceToBatch"}, [](const std::shared_ptr<::ngraph::Node>& node,
|
||||
const std::map<std::string, std::string> params) -> CNNLayerPtr {
|
||||
const std::map<std::string, std::string>& params) -> CNNLayerPtr {
|
||||
LayerParams attrs = {node->get_friendly_name(), node->description(),
|
||||
details::convertPrecision(node->get_output_element_type(0))};
|
||||
auto res = std::make_shared<SpaceToBatchLayer>(attrs);
|
||||
@ -350,7 +362,7 @@ InferenceEngine::details::CNNLayerCreator::CNNLayerCreator(const std::shared_ptr
|
||||
});
|
||||
|
||||
addSpecificCreator({"BatchToSpace"}, [](const std::shared_ptr<::ngraph::Node>& node,
|
||||
const std::map<std::string, std::string> params) -> CNNLayerPtr {
|
||||
const std::map<std::string, std::string>& params) -> CNNLayerPtr {
|
||||
LayerParams attrs = {node->get_friendly_name(), node->description(),
|
||||
details::convertPrecision(node->get_output_element_type(0))};
|
||||
auto res = std::make_shared<BatchToSpaceLayer>(attrs);
|
||||
@ -359,7 +371,7 @@ InferenceEngine::details::CNNLayerCreator::CNNLayerCreator(const std::shared_ptr
|
||||
});
|
||||
|
||||
addSpecificCreator({"Assign"}, [](const std::shared_ptr<::ngraph::Node>& node,
|
||||
const std::map<std::string, std::string> params) -> CNNLayerPtr {
|
||||
const std::map<std::string, std::string>& params) -> CNNLayerPtr {
|
||||
LayerParams attrs = {node->get_friendly_name(), "Memory",
|
||||
details::convertPrecision(node->get_output_element_type(0))};
|
||||
auto res = std::make_shared<CNNLayer>(attrs);
|
||||
@ -370,7 +382,7 @@ InferenceEngine::details::CNNLayerCreator::CNNLayerCreator(const std::shared_ptr
|
||||
});
|
||||
|
||||
addSpecificCreator({"ReadValue"}, [](const std::shared_ptr<::ngraph::Node>& node,
|
||||
const std::map<std::string, std::string> params) -> CNNLayerPtr {
|
||||
const std::map<std::string, std::string>& params) -> CNNLayerPtr {
|
||||
LayerParams attrs = {node->get_friendly_name(), "Memory",
|
||||
details::convertPrecision(node->get_output_element_type(0))};
|
||||
auto res = std::make_shared<CNNLayer>(attrs);
|
||||
@ -381,7 +393,7 @@ InferenceEngine::details::CNNLayerCreator::CNNLayerCreator(const std::shared_ptr
|
||||
});
|
||||
|
||||
addSpecificCreator({"DepthToSpace"}, [](const std::shared_ptr<::ngraph::Node>& node,
|
||||
const std::map<std::string, std::string> params) -> CNNLayerPtr {
|
||||
const std::map<std::string, std::string>& params) -> CNNLayerPtr {
|
||||
LayerParams attrs = {node->get_friendly_name(), node->description(),
|
||||
details::convertPrecision(node->get_output_element_type(0))};
|
||||
auto res = std::make_shared<DepthToSpaceLayer>(attrs);
|
||||
@ -390,7 +402,7 @@ InferenceEngine::details::CNNLayerCreator::CNNLayerCreator(const std::shared_ptr
|
||||
});
|
||||
|
||||
addSpecificCreator({"SpaceToDepth"}, [](const std::shared_ptr<::ngraph::Node>& node,
|
||||
const std::map<std::string, std::string> params) -> CNNLayerPtr {
|
||||
const std::map<std::string, std::string>& params) -> CNNLayerPtr {
|
||||
LayerParams attrs = {node->get_friendly_name(), node->description(),
|
||||
details::convertPrecision(node->get_output_element_type(0))};
|
||||
auto res = std::make_shared<SpaceToDepthLayer>(attrs);
|
||||
@ -398,22 +410,8 @@ InferenceEngine::details::CNNLayerCreator::CNNLayerCreator(const std::shared_ptr
|
||||
return res;
|
||||
});
|
||||
|
||||
addSpecificCreator({"RNNCell"}, [](const std::shared_ptr<::ngraph::Node>& node,
|
||||
const std::map<std::string, std::string> params) -> CNNLayerPtr {
|
||||
THROW_IE_EXCEPTION << "RNNCell operation has a form that is not supported." << node->get_friendly_name()
|
||||
<< " should be converted to RNNCellIE operation";
|
||||
return nullptr;
|
||||
});
|
||||
|
||||
addSpecificCreator({"GRUCell"}, [](const std::shared_ptr<::ngraph::Node>& node,
|
||||
const std::map<std::string, std::string> params) -> CNNLayerPtr {
|
||||
THROW_IE_EXCEPTION << "GRUCell operation has a form that is not supported." << node->get_friendly_name()
|
||||
<< " should be converted to GRUCellIE operation";
|
||||
return nullptr;
|
||||
});
|
||||
|
||||
addSpecificCreator({"RNNCellIE"}, [](const std::shared_ptr<::ngraph::Node>& node,
|
||||
const std::map<std::string, std::string> params) -> CNNLayerPtr {
|
||||
const std::map<std::string, std::string>& params) -> CNNLayerPtr {
|
||||
LayerParams attrs = {node->get_friendly_name(), "RNNCell",
|
||||
details::convertPrecision(node->get_output_element_type(0))};
|
||||
auto res = std::make_shared<RNNCell>(attrs);
|
||||
@ -437,7 +435,7 @@ InferenceEngine::details::CNNLayerCreator::CNNLayerCreator(const std::shared_ptr
|
||||
});
|
||||
|
||||
addSpecificCreator({"GRUCellIE"}, [](const std::shared_ptr<::ngraph::Node>& node,
|
||||
const std::map<std::string, std::string> params) -> CNNLayerPtr {
|
||||
const std::map<std::string, std::string>& params) -> CNNLayerPtr {
|
||||
LayerParams attrs = {node->get_friendly_name(), "GRUCell",
|
||||
details::convertPrecision(node->get_output_element_type(0))};
|
||||
auto res = std::make_shared<GRUCell>(attrs);
|
||||
@ -461,7 +459,7 @@ InferenceEngine::details::CNNLayerCreator::CNNLayerCreator(const std::shared_ptr
|
||||
});
|
||||
|
||||
addSpecificCreator({"ScatterElementsUpdate"}, [](const std::shared_ptr<::ngraph::Node>& node,
|
||||
const std::map<std::string, std::string> params) -> CNNLayerPtr {
|
||||
const std::map<std::string, std::string>& params) -> CNNLayerPtr {
|
||||
LayerParams attrs = {node->get_friendly_name(), node->description(),
|
||||
details::convertPrecision(node->get_output_element_type(0))};
|
||||
auto res = std::make_shared<ScatterElementsUpdateLayer>(attrs);
|
||||
@ -470,7 +468,7 @@ InferenceEngine::details::CNNLayerCreator::CNNLayerCreator(const std::shared_ptr
|
||||
});
|
||||
|
||||
addSpecificCreator({"ScatterUpdate"}, [](const std::shared_ptr<::ngraph::Node>& node,
|
||||
const std::map<std::string, std::string> params) -> CNNLayerPtr {
|
||||
const std::map<std::string, std::string>& params) -> CNNLayerPtr {
|
||||
LayerParams attrs = {node->get_friendly_name(), node->description(),
|
||||
details::convertPrecision(node->get_output_element_type(0))};
|
||||
auto res = std::make_shared<ScatterUpdateLayer>(attrs);
|
||||
@ -479,7 +477,7 @@ InferenceEngine::details::CNNLayerCreator::CNNLayerCreator(const std::shared_ptr
|
||||
});
|
||||
|
||||
addSpecificCreator({"StaticShapeTopK"}, [](const std::shared_ptr<::ngraph::Node>& node,
|
||||
const std::map<std::string, std::string> params) -> CNNLayerPtr {
|
||||
const std::map<std::string, std::string>& params) -> CNNLayerPtr {
|
||||
LayerParams attrs = {node->get_friendly_name(), "TopK",
|
||||
details::convertPrecision(node->get_output_element_type(0))};
|
||||
auto res = std::make_shared<TopKLayer>(attrs);
|
||||
@ -488,7 +486,7 @@ InferenceEngine::details::CNNLayerCreator::CNNLayerCreator(const std::shared_ptr
|
||||
});
|
||||
|
||||
addSpecificCreator({"Transpose"}, [](const std::shared_ptr<::ngraph::Node>& node,
|
||||
const std::map<std::string, std::string> params) -> CNNLayerPtr {
|
||||
const std::map<std::string, std::string>& params) -> CNNLayerPtr {
|
||||
LayerParams attrs = {node->get_friendly_name(), "Permute",
|
||||
details::convertPrecision(node->get_output_element_type(0))};
|
||||
auto res = std::make_shared<InferenceEngine::CNNLayer>(attrs);
|
||||
@ -501,7 +499,7 @@ InferenceEngine::details::CNNLayerCreator::CNNLayerCreator(const std::shared_ptr
|
||||
});
|
||||
|
||||
addSpecificCreator({"SwishIE"}, [](const std::shared_ptr<::ngraph::Node>& node,
|
||||
const std::map<std::string, std::string> params) -> CNNLayerPtr {
|
||||
const std::map<std::string, std::string>& params) -> CNNLayerPtr {
|
||||
LayerParams attrs = {node->get_friendly_name(), "Swish",
|
||||
details::convertPrecision(node->get_output_element_type(0))};
|
||||
auto res = std::make_shared<InferenceEngine::CNNLayer>(attrs);
|
||||
@ -510,36 +508,34 @@ InferenceEngine::details::CNNLayerCreator::CNNLayerCreator(const std::shared_ptr
|
||||
|
||||
});
|
||||
|
||||
addSpecificCreator({"PriorBox"}, [](const std::shared_ptr<::ngraph::Node>& node,
|
||||
const std::map<std::string, std::string> params) -> CNNLayerPtr {
|
||||
// Todo (itikhono): replace the message after supporting constants as outputs in plugins
|
||||
// THROW_IE_EXCEPTION << "PriorBox operation has a form that is not supported." << node->get_friendly_name()
|
||||
// << " should be replaced by constant during constant folding.";
|
||||
THROW_IE_EXCEPTION << "PriorBox operation has a form that is not supported." << node->get_friendly_name()
|
||||
<< " should be converted to PriorBoxIE operation";
|
||||
return nullptr;
|
||||
});
|
||||
|
||||
addSpecificCreator({"PriorBoxClustered"}, [](const std::shared_ptr<::ngraph::Node>& node,
|
||||
const std::map<std::string, std::string> params) -> CNNLayerPtr {
|
||||
// Todo (itikhono): replace the message after supporting constants as outputs in plugins
|
||||
// THROW_IE_EXCEPTION << "PriorBoxClustered operation has a form that is not supported." << node->get_friendly_name()
|
||||
// << " should be replaced by constant during constant folding.";
|
||||
THROW_IE_EXCEPTION << "PriorBoxClustered operation has a form that is not supported." << node->get_friendly_name()
|
||||
<< " should be converted to PriorBoxClusteredIE operation";
|
||||
return nullptr;
|
||||
});
|
||||
|
||||
addSpecificCreator({"NonMaxSuppressionIE"}, [](const std::shared_ptr<::ngraph::Node>& node,
|
||||
const std::map<std::string, std::string> params) -> CNNLayerPtr {
|
||||
const std::map<std::string, std::string>& params) -> CNNLayerPtr {
|
||||
LayerParams attrs = {node->get_friendly_name(), "NonMaxSuppression", details::convertPrecision(node->get_output_element_type(0))};
|
||||
auto res = std::make_shared<InferenceEngine::NonMaxSuppressionLayer>(attrs);
|
||||
res->params = params;
|
||||
return res;
|
||||
});
|
||||
|
||||
REQUIRED_IE_CONVERSION_CREATOR("Broadcast", "Tile");
|
||||
REQUIRED_IE_CONVERSION_CREATOR("Interpolate", "Interp");
|
||||
REQUIRED_IE_CONVERSION_CREATOR("NormalizeL2", "NormalizeIE");
|
||||
REQUIRED_IE_CONVERSION_CREATOR("GroupConvolution", "ConvolutionIE");
|
||||
REQUIRED_IE_CONVERSION_CREATOR("ConvolutionBackpropData", "DeconvolutionIE");
|
||||
REQUIRED_IE_CONVERSION_CREATOR("GroupConvolutionBackpropData", "DeconvolutionIE");
|
||||
|
||||
addSpecificCreator({ "Convolution", "Gather", "GatherTree", "GRUCell", "GRUSequence", "HardSigmoid",
|
||||
"LRN", "LSTMCell", "LSTMSequence", "NonMaxSuppression", "RNNCell", "RNNSequence", "OneHot",
|
||||
"Pad", "PriorBoxClustered", "PriorBox", "Proposal", "Selu", "Swish", "Tile", "TopK"},
|
||||
[](const std::shared_ptr<::ngraph::Node>& node, const std::map<std::string, std::string>& params)
|
||||
-> CNNLayerPtr {
|
||||
const std::string& type_name = node->get_type_name();
|
||||
THROW_IE_EXCEPTION << type_name << " operation has a form that is not supported. " << node->get_friendly_name()
|
||||
<< " should be converted to " << type_name + "IE operation.";
|
||||
return nullptr;
|
||||
});
|
||||
|
||||
addSpecificCreator({"ReduceMin", "ReduceMax", "ReduceMean", "ReduceProd", "ReduceSum", "ReduceL1", "ReduceL2"},
|
||||
[](const std::shared_ptr<::ngraph::Node>& node, const std::map<std::string, std::string> params) -> CNNLayerPtr {
|
||||
[](const std::shared_ptr<::ngraph::Node>& node, const std::map<std::string, std::string>& params) -> CNNLayerPtr {
|
||||
LayerParams attrs = {node->get_friendly_name(), node->description(), details::convertPrecision(node->get_output_element_type(0))};
|
||||
auto reduce_node = std::dynamic_pointer_cast<ngraph::op::util::ArithmeticReductionKeepDims>(node);
|
||||
auto res = std::make_shared<InferenceEngine::ReduceLayer>(attrs);
|
||||
@ -548,7 +544,7 @@ InferenceEngine::details::CNNLayerCreator::CNNLayerCreator(const std::shared_ptr
|
||||
return res;
|
||||
});
|
||||
|
||||
addSpecificCreator({"ReduceLogicalAnd"}, [](const std::shared_ptr<::ngraph::Node>& node, const std::map<std::string, std::string> params) -> CNNLayerPtr {
|
||||
addSpecificCreator({"ReduceLogicalAnd"}, [](const std::shared_ptr<::ngraph::Node>& node, const std::map<std::string, std::string>& params) -> CNNLayerPtr {
|
||||
LayerParams attrs = {node->get_friendly_name(), "ReduceAnd", details::convertPrecision(node->get_output_element_type(0))};
|
||||
auto reduce_node = std::dynamic_pointer_cast<ngraph::op::util::LogicalReductionKeepDims>(node);
|
||||
auto res = std::make_shared<InferenceEngine::ReduceLayer>(attrs);
|
||||
@ -557,7 +553,7 @@ InferenceEngine::details::CNNLayerCreator::CNNLayerCreator(const std::shared_ptr
|
||||
return res;
|
||||
});
|
||||
|
||||
addSpecificCreator({"ReduceLogicalOr"}, [](const std::shared_ptr<::ngraph::Node>& node, const std::map<std::string, std::string> params) -> CNNLayerPtr {
|
||||
addSpecificCreator({"ReduceLogicalOr"}, [](const std::shared_ptr<::ngraph::Node>& node, const std::map<std::string, std::string>& params) -> CNNLayerPtr {
|
||||
LayerParams attrs = {node->get_friendly_name(), "ReduceOr", details::convertPrecision(node->get_output_element_type(0))};
|
||||
auto reduce_node = std::dynamic_pointer_cast<ngraph::op::util::LogicalReductionKeepDims>(node);
|
||||
auto res = std::make_shared<InferenceEngine::ReduceLayer>(attrs);
|
||||
@ -599,7 +595,6 @@ void convertFunctionToICNNNetwork(const std::shared_ptr<const ::ngraph::Function
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::Atan>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::v1::AvgPool>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::BatchNormInference>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::v1::Broadcast>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::Clamp>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::Concat>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::Constant>>(),
|
||||
@ -623,12 +618,9 @@ void convertFunctionToICNNNetwork(const std::shared_ptr<const ::ngraph::Function
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::Floor>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::Ceiling>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::GatherIE>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::v1::GatherTree>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::GatherTreeIE>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::Interp>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::Interpolate>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::Log>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::LRN>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::LRN_IE>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::MVN>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::FullyConnected>>(),
|
||||
@ -639,16 +631,12 @@ void convertFunctionToICNNNetwork(const std::shared_ptr<const ::ngraph::Function
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::v1::Maximum>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::v1::Minimum>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::v1::Multiply>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::v1::NonMaxSuppression>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::NormalizeL2>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::NormalizeIE>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::OneHotIE>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::PRelu>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::PadIE>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::v1::Power>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::PowerIE>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::PriorBox>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::PriorBoxClustered>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::PriorBoxClusteredIE>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::PriorBoxIE>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::ProposalIE>>(),
|
||||
@ -684,7 +672,6 @@ void convertFunctionToICNNNetwork(const std::shared_ptr<const ::ngraph::Function
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::Unsqueeze>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::TensorIterator>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::LSTMCellIE>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::HardSigmoid>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::HardSigmoid_IE>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::v1::LogicalNot>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::ShuffleChannels>>(),
|
||||
|
@ -517,11 +517,6 @@ CNNLayer::Ptr NodeConverter<ngraph::op::MVN>::createLayer(const std::shared_ptr<
|
||||
return res;
|
||||
}
|
||||
|
||||
template <>
|
||||
CNNLayer::Ptr NodeConverter<ngraph::op::LRN>::createLayer(const std::shared_ptr<ngraph::Node>& layer) const {
|
||||
THROW_IE_EXCEPTION << "LRN operation should be converted to LRN_IE";
|
||||
}
|
||||
|
||||
template <>
|
||||
CNNLayer::Ptr NodeConverter<ngraph::op::LRN_IE>::createLayer(const std::shared_ptr<ngraph::Node>& layer) const {
|
||||
LayerParams params = {layer->get_friendly_name(), "Norm",
|
||||
@ -654,12 +649,6 @@ CNNLayer::Ptr NodeConverter<ngraph::op::v1::Add>::createLayer(const std::shared_
|
||||
return res;
|
||||
}
|
||||
|
||||
template <>
|
||||
CNNLayer::Ptr NodeConverter<ngraph::op::v1::Broadcast>::createLayer(const std::shared_ptr<ngraph::Node>& layer) const {
|
||||
THROW_IE_EXCEPTION << "Broadcast operation " << layer->get_friendly_name()
|
||||
<< " should be converted to Tile operation";
|
||||
}
|
||||
|
||||
template <>
|
||||
CNNLayer::Ptr NodeConverter<ngraph::op::BatchNormInference>::createLayer(
|
||||
const std::shared_ptr<ngraph::Node>& layer) const {
|
||||
@ -1219,11 +1208,6 @@ CNNLayer::Ptr NodeConverter<ngraph::op::GatherIE>::createLayer(const std::shared
|
||||
return res;
|
||||
}
|
||||
|
||||
template <>
|
||||
CNNLayer::Ptr NodeConverter<ngraph::op::v1::GatherTree>::createLayer(const std::shared_ptr<ngraph::Node>& layer) const {
|
||||
THROW_IE_EXCEPTION << "GatherTree operation should be converted to GatherTreeIE";
|
||||
}
|
||||
|
||||
template <>
|
||||
CNNLayer::Ptr NodeConverter<ngraph::op::GatherTreeIE>::createLayer(const std::shared_ptr<ngraph::Node>& layer) const {
|
||||
LayerParams params = {layer->get_friendly_name(), "GatherTree",
|
||||
@ -1425,11 +1409,6 @@ CNNLayer::Ptr NodeConverter<ngraph::op::DetectionOutput>::createLayer(
|
||||
return res;
|
||||
}
|
||||
|
||||
template <>
|
||||
CNNLayer::Ptr NodeConverter<ngraph::op::v0::Proposal>::createLayer(const std::shared_ptr<ngraph::Node>& layer) const {
|
||||
THROW_IE_EXCEPTION << "Proposal operation should be converted to ProposalIE";
|
||||
}
|
||||
|
||||
template <>
|
||||
CNNLayer::Ptr NodeConverter<ngraph::op::ProposalIE>::createLayer(const std::shared_ptr<ngraph::Node>& layer) const {
|
||||
LayerParams params = {layer->get_friendly_name(), "Proposal",
|
||||
@ -1513,12 +1492,6 @@ CNNLayer::Ptr NodeConverter<ngraph::op::PriorBoxClusteredIE>::createLayer(
|
||||
return res;
|
||||
}
|
||||
|
||||
template <>
|
||||
CNNLayer::Ptr NodeConverter<ngraph::op::PriorBoxClustered>::createLayer(
|
||||
const std::shared_ptr<ngraph::Node>& layer) const {
|
||||
THROW_IE_EXCEPTION << "PriorBoxClustered operation must be converted to PriorBoxClusteredIE operation.";
|
||||
}
|
||||
|
||||
template <>
|
||||
CNNLayer::Ptr NodeConverter<ngraph::op::PriorBoxIE>::createLayer(const std::shared_ptr<ngraph::Node>& layer) const {
|
||||
LayerParams params = {layer->get_friendly_name(), "PriorBox",
|
||||
@ -1594,11 +1567,6 @@ CNNLayer::Ptr NodeConverter<ngraph::op::PriorBoxIE>::createLayer(const std::shar
|
||||
return res;
|
||||
}
|
||||
|
||||
template <>
|
||||
CNNLayer::Ptr NodeConverter<ngraph::op::PriorBox>::createLayer(const std::shared_ptr<ngraph::Node>& layer) const {
|
||||
THROW_IE_EXCEPTION << "PriorBox operation must be converted to PriorBoxIE operation.";
|
||||
}
|
||||
|
||||
template <>
|
||||
CNNLayer::Ptr NodeConverter<ngraph::op::PowerIE>::createLayer(const std::shared_ptr<ngraph::Node>& layer) const {
|
||||
LayerParams params = {layer->get_friendly_name(), "Power",
|
||||
@ -1738,11 +1706,6 @@ CNNLayer::Ptr NodeConverter<ngraph::op::Interp>::createLayer(const std::shared_p
|
||||
return res;
|
||||
}
|
||||
|
||||
template <>
|
||||
CNNLayer::Ptr NodeConverter<ngraph::op::Interpolate>::createLayer(const std::shared_ptr<ngraph::Node>& layer) const {
|
||||
THROW_IE_EXCEPTION << "Interpolate operation should be converted to Interp";
|
||||
}
|
||||
|
||||
template <>
|
||||
CNNLayer::Ptr NodeConverter<ngraph::op::FullyConnected>::createLayer(const std::shared_ptr<ngraph::Node>& layer) const {
|
||||
LayerParams params = {layer->get_friendly_name(), "FullyConnected",
|
||||
@ -1778,11 +1741,6 @@ CNNLayer::Ptr NodeConverter<ngraph::op::FullyConnected>::createLayer(const std::
|
||||
return res;
|
||||
}
|
||||
|
||||
template <>
|
||||
CNNLayer::Ptr NodeConverter<ngraph::op::LSTMCell>::createLayer(const std::shared_ptr<ngraph::Node>& layer) const {
|
||||
THROW_IE_EXCEPTION << "LSTMCell operation must be converted to LSTMCellIE operation.";
|
||||
}
|
||||
|
||||
template <>
|
||||
CNNLayer::Ptr NodeConverter<ngraph::op::LSTMCellIE>::createLayer(const std::shared_ptr<ngraph::Node>& layer) const {
|
||||
LayerParams params = {layer->get_friendly_name(), "LSTMCell",
|
||||
@ -1931,11 +1889,6 @@ CNNLayer::Ptr NodeConverter<ngraph::op::ReorgYolo>::createLayer(const std::share
|
||||
return res;
|
||||
}
|
||||
|
||||
template <>
|
||||
CNNLayer::Ptr NodeConverter<ngraph::op::NormalizeL2>::createLayer(const std::shared_ptr<ngraph::Node>& layer) const {
|
||||
THROW_IE_EXCEPTION << "NormalizeL2 operation should be converted to NormalizeIE";
|
||||
}
|
||||
|
||||
template <>
|
||||
CNNLayer::Ptr NodeConverter<ngraph::op::Log>::createLayer(const std::shared_ptr<ngraph::Node>& layer) const {
|
||||
LayerParams params = {layer->get_friendly_name(), "Log",
|
||||
@ -2133,11 +2086,6 @@ CNNLayer::Ptr NodeConverter<ngraph::op::OneHotIE>::createLayer(const std::shared
|
||||
return res;
|
||||
}
|
||||
|
||||
template <>
|
||||
CNNLayer::Ptr NodeConverter<ngraph::op::HardSigmoid>::createLayer(const std::shared_ptr<ngraph::Node>& layer) const {
|
||||
THROW_IE_EXCEPTION << "HardSigmoid operation should be converted to HardSigmoid_IE";
|
||||
}
|
||||
|
||||
template <>
|
||||
CNNLayer::Ptr NodeConverter<ngraph::op::HardSigmoid_IE>::createLayer(const std::shared_ptr<ngraph::Node>& layer) const {
|
||||
LayerParams params = { layer->get_friendly_name(), "HardSigmoid", details::convertPrecision(layer->get_output_element_type(0)) };
|
||||
@ -2171,10 +2119,5 @@ CNNLayer::Ptr NodeConverter<ngraph::op::v1::LogicalNot>::createLayer(const std::
|
||||
return res;
|
||||
}
|
||||
|
||||
template <>
|
||||
CNNLayer::Ptr NodeConverter<ngraph::op::v1::NonMaxSuppression>::createLayer(const std::shared_ptr<ngraph::Node>& layer) const {
|
||||
THROW_IE_EXCEPTION << "NonMaxSuppression operation must be converted to NonMaxSuppressionIE operation.";
|
||||
}
|
||||
|
||||
} // namespace Builder
|
||||
} // namespace InferenceEngine
|
||||
|
@ -9,8 +9,10 @@
|
||||
|
||||
#include <ngraph/function.hpp>
|
||||
#include <ngraph/opsets/opset1.hpp>
|
||||
#include <ngraph/opsets/opset4.hpp>
|
||||
#include <ngraph_ops/convolution_ie.hpp>
|
||||
#include <transformations/init_node_info.hpp>
|
||||
#include <legacy/convert_function_to_cnn_network.hpp>
|
||||
|
||||
using namespace testing;
|
||||
using namespace InferenceEngine;
|
||||
@ -66,3 +68,79 @@ TEST(ConvertFunctionToCNNNetworkTests, ConvertConvolutionNetwork) {
|
||||
FAIL();
|
||||
}
|
||||
}
|
||||
|
||||
TEST(ConvertFunctionToCNNNetworkTests, OpsShouldBeConvertedToIERepresentation) {
|
||||
ngraph::NodeVector should_converted_to_ie = {
|
||||
std::make_shared<ngraph::opset4::Broadcast>(),
|
||||
std::make_shared<ngraph::opset4::Convolution>(),
|
||||
std::make_shared<ngraph::opset4::ConvolutionBackpropData>(),
|
||||
std::make_shared<ngraph::opset4::Gather>(),
|
||||
std::make_shared<ngraph::opset4::GatherTree>(),
|
||||
std::make_shared<ngraph::opset4::GroupConvolution>(),
|
||||
std::make_shared<ngraph::opset4::GroupConvolutionBackpropData>(),
|
||||
std::make_shared<ngraph::opset4::GRUCell>(),
|
||||
// std::make_shared<ngraph::opset4::GRUSequence>(), todo: enable after GRUSequence support
|
||||
std::make_shared<ngraph::opset4::HardSigmoid>(),
|
||||
std::make_shared<ngraph::opset4::Interpolate>(),
|
||||
std::make_shared<ngraph::opset4::LRN>(),
|
||||
std::make_shared<ngraph::opset4::LSTMCell>(),
|
||||
// std::make_shared<ngraph::opset4::LSTMSequence>(), todo: enable after LSTMSequence support
|
||||
std::make_shared<ngraph::opset4::NonMaxSuppression>(),
|
||||
std::make_shared<ngraph::opset4::NormalizeL2>(),
|
||||
std::make_shared<ngraph::opset4::RNNCell>(),
|
||||
// std::make_shared<ngraph::opset4::RNNSequence>(), todo: enable after RNNSequence support
|
||||
std::make_shared<ngraph::opset4::OneHot>(),
|
||||
std::make_shared<ngraph::opset4::Pad>(),
|
||||
std::make_shared<ngraph::opset4::PriorBoxClustered>(),
|
||||
std::make_shared<ngraph::opset4::PriorBox>(),
|
||||
std::make_shared<ngraph::opset4::Proposal>(),
|
||||
std::make_shared<ngraph::opset4::Selu>(),
|
||||
std::make_shared<ngraph::opset4::Swish>(),
|
||||
std::make_shared<ngraph::opset4::Tile>(),
|
||||
std::make_shared<ngraph::opset4::TopK>(),
|
||||
};
|
||||
|
||||
// create simple ngraph function Parameter -> Result
|
||||
std::shared_ptr<ngraph::Function> f;
|
||||
auto param = std::make_shared<ngraph::opset4::Parameter>(ngraph::element::f32, ngraph::Shape{});
|
||||
auto res = std::make_shared<ngraph::opset4::Result>(param);
|
||||
f = std::make_shared<ngraph::Function>(ngraph::ResultVector{res}, ngraph::ParameterVector{param});
|
||||
InferenceEngine::CNNNetwork nGraphImpl(f);
|
||||
|
||||
for (const auto& ngraph_node : should_converted_to_ie) {
|
||||
// add node without inputs to the ngraph function
|
||||
ngraph_node->set_output_type(0, ngraph::element::f32, ngraph::Shape{});
|
||||
res->input(0).replace_source_output(ngraph_node->output(0));
|
||||
|
||||
EXPECT_THROW(InferenceEngine::details::convertFunctionToICNNNetwork(f, nGraphImpl, true),
|
||||
InferenceEngine::details::InferenceEngineException)
|
||||
<< "failed node: " << ngraph_node->get_type_name() << std::endl;
|
||||
try {
|
||||
InferenceEngine::details::convertFunctionToICNNNetwork(f, nGraphImpl, true);
|
||||
} catch (InferenceEngine::details::InferenceEngineException &err) {
|
||||
std::string type_name = ngraph_node->get_type_name();
|
||||
|
||||
std::map<std::string, std::string> exceptions = { {"Broadcast", "Tile"}, {"Interpolate", "Interp"},
|
||||
{"NormalizeL2", "NormalizeIE"},
|
||||
{"GroupConvolution", "ConvolutionIE"},
|
||||
{"ConvolutionBackpropData", "DeconvolutionIE"},
|
||||
{"GroupConvolutionBackpropData", "DeconvolutionIE"},
|
||||
};
|
||||
std::string type_name_ie = type_name + "IE";
|
||||
if (exceptions[type_name].empty()) {
|
||||
type_name_ie = type_name + "IE";
|
||||
} else {
|
||||
type_name_ie = exceptions[type_name];
|
||||
}
|
||||
std::string expected_error_message = type_name + " operation has a form that is not supported. "
|
||||
+ ngraph_node->get_friendly_name() + " should be converted to " + type_name_ie + " operation.";
|
||||
std::string real_message = err.what();
|
||||
bool is_messages_match = real_message.find(expected_error_message) != std::string::npos;
|
||||
EXPECT_TRUE(is_messages_match) << "failed node: " << type_name << std::endl
|
||||
<< "Exception massage: " << err.what() << std::endl
|
||||
<< "Expected message: " << expected_error_message << std:: endl;
|
||||
} catch (...) {
|
||||
FAIL() << "ERROR: Unexpected exception thrown: " << std::current_exception << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user