Remove ops from Layer Creator/ Node Converter - part 9 (#4019)
* remove variadicsplit op from layer creator * remove reorgyolo op from layer creator * remove psroipooling op from layer creator * remove empty layer creator list and not used creator * missing endline * add reorgyolo case to ops missing in opset1 * remove trivial creators
This commit is contained in:
parent
4e601eb315
commit
b97a986048
@ -1586,11 +1586,25 @@ InferenceEngine::details::CNNLayerCreator::CNNLayerCreator(const std::shared_ptr
|
||||
return res;
|
||||
});
|
||||
|
||||
addSpecificCreator({"PSROIPooling"}, [](const std::shared_ptr<::ngraph::Node> &node,
|
||||
const std::map<std::string, std::string> ¶ms) -> CNNLayerPtr {
|
||||
LayerParams attrs = {node->get_friendly_name(), "PSROIPooling", details::convertPrecision(node->get_output_element_type(0))};
|
||||
auto res = std::make_shared<InferenceEngine::CNNLayer>(attrs);
|
||||
res->params = params;
|
||||
addSpecificCreator({"VariadicSplit"}, [](const std::shared_ptr<::ngraph::Node>& node,
|
||||
const std::map<std::string, std::string>& params) -> CNNLayerPtr {
|
||||
LayerParams attrs = {node->get_friendly_name(), "Split", details::convertPrecision(node->get_output_element_type(0))};
|
||||
auto res = std::make_shared<InferenceEngine::SplitLayer>(attrs);
|
||||
auto castedLayer = std::dynamic_pointer_cast<ngraph::op::VariadicSplit>(node);
|
||||
if (!castedLayer) THROW_IE_EXCEPTION << "Cannot get " << attrs.type << " layer " << attrs.name;
|
||||
|
||||
auto axis_node = castedLayer->input_value(1).get_node_shared_ptr();
|
||||
const auto axis_node_const = ngraph::as_type_ptr<ngraph::op::Constant>(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<int64_t>()[0];
|
||||
if (axis < 0) {
|
||||
axis += castedLayer->get_input_shape(0).size();
|
||||
}
|
||||
|
||||
res->params["axis"] = Builder::asString(axis);
|
||||
return res;
|
||||
});
|
||||
}
|
||||
@ -1628,9 +1642,7 @@ void convertFunctionToICNNNetwork(const std::shared_ptr<const ::ngraph::Function
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::PowerIE>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::ReLUIE>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::ResampleV2>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::ReorgYolo>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::ScaleShiftIE>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::VariadicSplit>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::ShuffleChannels>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ngraph::op::v4::Interpolate>>(),
|
||||
std::make_shared<Builder::NodeConverter<::ExecGraphInfoSerialization::ExecutionNode>>(),
|
||||
|
@ -250,27 +250,6 @@ CNNLayer::Ptr NodeConverter<ngraph::op::v0::Unsqueeze>::createLayer(const std::s
|
||||
return res;
|
||||
}
|
||||
|
||||
template <>
|
||||
CNNLayer::Ptr NodeConverter<ngraph::op::VariadicSplit>::createLayer(const std::shared_ptr<ngraph::Node>& layer) const {
|
||||
LayerParams params = {layer->get_friendly_name(), "Split",
|
||||
details::convertPrecision(layer->get_output_element_type(0))};
|
||||
auto res = std::make_shared<InferenceEngine::SplitLayer>(params);
|
||||
auto castedLayer = ngraph::as_type_ptr<ngraph::op::VariadicSplit>(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<ngraph::op::Constant>(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<int64_t>()[0];
|
||||
if (axis < 0) {
|
||||
axis += castedLayer->get_input_shape(0).size();
|
||||
}
|
||||
res->params["axis"] = asString(axis);
|
||||
return res;
|
||||
}
|
||||
|
||||
template <>
|
||||
CNNLayer::Ptr NodeConverter<ngraph::op::Concat>::createLayer(const std::shared_ptr<ngraph::Node>& layer) const {
|
||||
LayerParams params = {layer->get_friendly_name(), "Concat",
|
||||
@ -599,24 +578,6 @@ CNNLayer::Ptr NodeConverter<ExecGraphInfoSerialization::ExecutionNode>::createLa
|
||||
return res;
|
||||
}
|
||||
|
||||
template <>
|
||||
CNNLayer::Ptr NodeConverter<ngraph::op::ReorgYolo>::createLayer(const std::shared_ptr<ngraph::Node>& layer) const {
|
||||
LayerParams params = {layer->get_friendly_name(), "ReorgYolo",
|
||||
details::convertPrecision(layer->get_output_element_type(0))};
|
||||
auto res = std::make_shared<InferenceEngine::CNNLayer>(params);
|
||||
auto castedLayer = ngraph::as_type_ptr<ngraph::op::ReorgYolo>(layer);
|
||||
if (castedLayer == nullptr) THROW_IE_EXCEPTION << "Cannot get " << params.type << " layer " << params.name;
|
||||
|
||||
std::string value;
|
||||
for (const auto& val : castedLayer->get_strides()) {
|
||||
if (!value.empty()) value += ",";
|
||||
value += asString(val);
|
||||
}
|
||||
|
||||
res->params["stride"] = value;
|
||||
return res;
|
||||
}
|
||||
|
||||
template <>
|
||||
CNNLayer::Ptr NodeConverter<ngraph::op::Log>::createLayer(const std::shared_ptr<ngraph::Node>& layer) const {
|
||||
LayerParams params = {layer->get_friendly_name(), "Log",
|
||||
|
@ -668,22 +668,7 @@ std::shared_ptr<ngraph::Node> V10Parser::XmlDeserializer::createNode(
|
||||
const pugi::xml_node& node,
|
||||
const Blob::CPtr& weights,
|
||||
const GenericLayerParams& params) {
|
||||
static const InferenceEngine::details::caseless_unordered_map<std::string, std::shared_ptr<LayerBaseCreator>> creators = {
|
||||
{ "ReorgYolo", std::make_shared<LayerCreator<ngraph::op::ReorgYolo>>("ReorgYolo") },
|
||||
{ "PSROIPooling", std::make_shared<LayerCreator<ngraph::op::PSROIPooling>>("PSROIPooling") },
|
||||
{ "VariadicSplit", std::make_shared<LayerCreator<ngraph::op::VariadicSplit>>("VariadicSplit") },
|
||||
};
|
||||
|
||||
// Check that operation in default opsets
|
||||
auto isDefaultOpSet = [](const std::string& version) -> bool {
|
||||
static char const * prefix = "opset";
|
||||
static size_t const prefixLen = strlen(prefix);
|
||||
return version.length() == prefixLen + 1
|
||||
&& version.compare(0, prefixLen, prefix) == 0
|
||||
&& version[prefixLen] >= '1'
|
||||
&& version[prefixLen] <= '6';
|
||||
};
|
||||
|
||||
// Check that inputs are correctly defined
|
||||
for (size_t i = 0; i < inputs.size(); i++) {
|
||||
if (!inputs[i].get_node())
|
||||
THROW_IE_EXCEPTION << params.type << " layer " << params.name << " with id: " << params.layerId
|
||||
@ -698,21 +683,6 @@ std::shared_ptr<ngraph::Node> V10Parser::XmlDeserializer::createNode(
|
||||
// Find registerd opset
|
||||
auto opsetIt = opsets.find(params.version);
|
||||
|
||||
if (isDefaultOpSet(params.version)) {
|
||||
// Try to create operation from creators
|
||||
auto creatorIt = creators.find(params.type);
|
||||
if (creatorIt != creators.end()) {
|
||||
auto const & creator = creatorIt->second;
|
||||
// Check that opset isn't registered
|
||||
// or opset should contains the same version of operation
|
||||
// or doesn't contain operation with current type
|
||||
if (opsetIt == opsets.end()
|
||||
|| opsetIt->second.contains_type(creator->getNodeType())
|
||||
|| !opsetIt->second.contains_type(params.type))
|
||||
ngraphNode = creator->createLayer(inputs, node, weights, params);
|
||||
}
|
||||
}
|
||||
|
||||
// Try to create operation from loaded opsets
|
||||
auto version = params.version;
|
||||
static const std::unordered_set<std::string> experimental_detectrons = {"ExperimentalDetectronDetectionOutput",
|
||||
@ -732,8 +702,8 @@ std::shared_ptr<ngraph::Node> V10Parser::XmlDeserializer::createNode(
|
||||
: params.type;
|
||||
|
||||
if (params.version == "opset1") {
|
||||
// MVN and ROIPooling were missing in opset1
|
||||
if (type == "MVN" || type == "ROIPooling") {
|
||||
// MVN, ROIPooling and ReorgYolo were missing in opset1
|
||||
if (type == "MVN" || type == "ROIPooling" || type == "ReorgYolo") {
|
||||
opsetIt = opsets.find("opset2");
|
||||
if (opsetIt == opsets.end()) {
|
||||
THROW_IE_EXCEPTION << "Cannot create " << params.type << " layer " << params.name << " id:" << params.layerId
|
||||
@ -836,67 +806,3 @@ std::shared_ptr<ngraph::Node> V10Parser::XmlDeserializer::createNode(
|
||||
|
||||
return ngraphNode;
|
||||
}
|
||||
|
||||
namespace InferenceEngine {
|
||||
// VariadicSplit layer
|
||||
template <>
|
||||
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::VariadicSplit>::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<ngraph::op::VariadicSplit>(inputs[0], inputs[1], inputs[2]);
|
||||
}
|
||||
|
||||
// DepthToSpace layer
|
||||
template <>
|
||||
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::DepthToSpace>::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<ngraph::op::DepthToSpace>(inputs[0], GetStrAttr(dn, "mode"), GetIntAttr(dn, "block_size", 1));
|
||||
}
|
||||
|
||||
// ReorgYolo layer
|
||||
template <>
|
||||
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::ReorgYolo>::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;
|
||||
|
||||
auto stride = GetUIntAttr(dn, "stride");
|
||||
return std::make_shared<ngraph::op::ReorgYolo>(inputs[0], ngraph::Strides {stride});
|
||||
}
|
||||
|
||||
// PSROIPooling layer
|
||||
template <>
|
||||
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::PSROIPooling>::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 output_dim = GetIntAttr(dn, "output_dim");
|
||||
auto group_size = GetIntAttr(dn, "group_size", 1);
|
||||
auto spatial_bins_x = GetIntAttr(dn, "spatial_bins_x", 1);
|
||||
auto spatial_bins_y = GetIntAttr(dn, "spatial_bins_y", 1);
|
||||
auto spatial_scale = GetFloatAttr(dn, "spatial_scale");
|
||||
auto mode = GetStrAttr(dn, "mode", "average");
|
||||
|
||||
return std::make_shared<ngraph::op::PSROIPooling>(inputs[0], inputs[1],
|
||||
output_dim, group_size, spatial_scale, spatial_bins_x,
|
||||
spatial_bins_y, mode);
|
||||
}
|
||||
|
||||
} // namespace InferenceEngine
|
||||
|
Loading…
Reference in New Issue
Block a user