mirror of
https://github.com/opencv/opencv.git
synced 2025-06-12 04:12:52 +08:00
dnn(ngraph): fix outputs handling, drop 'unconnected' logic
This commit is contained in:
parent
67978b5746
commit
b57ff73086
@ -1937,6 +1937,9 @@ struct Net::Impl : public detail::NetImplBase
|
||||
|
||||
|
||||
#ifdef HAVE_DNN_NGRAPH
|
||||
/** mark input pins as outputs from other subnetworks
|
||||
* FIXIT must be done by DNN engine not ngraph.
|
||||
*/
|
||||
void addNgraphOutputs(LayerData &ld)
|
||||
{
|
||||
CV_TRACE_FUNCTION();
|
||||
@ -1967,8 +1970,7 @@ struct Net::Impl : public detail::NetImplBase
|
||||
if (layerNet != ieInpNode->net)
|
||||
{
|
||||
CV_LOG_DEBUG(NULL, "DNN/IE: pin output between subnets: " << ieInpNode->node->get_friendly_name());
|
||||
ieInpNode->net->addOutput(ieInpNode->node->get_friendly_name());
|
||||
ieInpNode->net->setUnconnectedNodes(ieInpNode);
|
||||
ieInpNode->net->addOutput(ieInpNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2118,7 +2120,7 @@ struct Net::Impl : public detail::NetImplBase
|
||||
if (!inpNode.empty()) {
|
||||
Ptr<InfEngineNgraphNode> ieNode = inpNode.dynamicCast<InfEngineNgraphNode>();
|
||||
CV_Assert(!ieNode.empty());
|
||||
ieNode->net->setUnconnectedNodes(ieNode);
|
||||
ieNode->net->addOutput(ieNode);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
@ -2259,15 +2261,11 @@ struct Net::Impl : public detail::NetImplBase
|
||||
CV_Assert(!ieNode.empty());
|
||||
ieNode->net = net;
|
||||
|
||||
if (ld.consumers.empty()) {
|
||||
// TF EAST_text_detection
|
||||
ieNode->net->setUnconnectedNodes(ieNode);
|
||||
}
|
||||
for (const auto& pin : blobsToKeep_)
|
||||
{
|
||||
if (pin.lid == ld.id)
|
||||
{
|
||||
ieNode->net->addOutput(ieNode->node->get_friendly_name());
|
||||
ieNode->net->addOutput(ieNode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -2298,7 +2296,7 @@ struct Net::Impl : public detail::NetImplBase
|
||||
|
||||
if (!ieNode->net->isInitialized())
|
||||
{
|
||||
ieNode->net->setUnconnectedNodes(ieNode);
|
||||
ieNode->net->addOutput(ieNode);
|
||||
ieNode->net->createNet((Target)preferableTarget);
|
||||
ld.skip = false;
|
||||
}
|
||||
|
@ -379,16 +379,21 @@ InfEngineNgraphNet::InfEngineNgraphNet(detail::NetImplBase& netImpl, InferenceEn
|
||||
device_name = "CPU";
|
||||
}
|
||||
|
||||
void InfEngineNgraphNet::addOutput(const std::string& name)
|
||||
void InfEngineNgraphNet::addOutput(const Ptr<InfEngineNgraphNode>& node)
|
||||
{
|
||||
requestedOutputs.push_back(name);
|
||||
CV_Assert(node);
|
||||
CV_Assert(node->node);
|
||||
const std::string& name = node->node->get_friendly_name();
|
||||
requestedOutputs.insert({name, node});
|
||||
}
|
||||
|
||||
void InfEngineNgraphNet::setNodePtr(std::shared_ptr<ngraph::Node>* ptr) {
|
||||
all_nodes.emplace((*ptr)->get_friendly_name(), ptr);
|
||||
}
|
||||
|
||||
void InfEngineNgraphNet::release() {
|
||||
void InfEngineNgraphNet::release()
|
||||
{
|
||||
// FIXIT release should not be conditional, release ALL
|
||||
for (auto& node : components.back()) {
|
||||
#if INF_ENGINE_VER_MAJOR_GT(INF_ENGINE_RELEASE_2020_4)
|
||||
if (!(ngraph::op::is_parameter(node) || ngraph::op::is_output(node) || ngraph::op::is_constant(node)) ) {
|
||||
@ -397,7 +402,6 @@ void InfEngineNgraphNet::setNodePtr(std::shared_ptr<ngraph::Node>* ptr) {
|
||||
#endif
|
||||
auto it = all_nodes.find(node->get_friendly_name());
|
||||
if (it != all_nodes.end()) {
|
||||
unconnectedNodes.erase(*(it->second));
|
||||
it->second->reset();
|
||||
all_nodes.erase(it);
|
||||
}
|
||||
@ -422,7 +426,8 @@ void InfEngineNgraphNet::dfs(std::shared_ptr<ngraph::Node>& node,
|
||||
}
|
||||
}
|
||||
|
||||
int InfEngineNgraphNet::getNumComponents() {
|
||||
int InfEngineNgraphNet::getNumComponents()
|
||||
{
|
||||
if (!components.empty()) {
|
||||
return components.size();
|
||||
}
|
||||
@ -445,12 +450,14 @@ int InfEngineNgraphNet::getNumComponents() {
|
||||
void InfEngineNgraphNet::createNet(Target targetId) {
|
||||
if (!hasNetOwner)
|
||||
{
|
||||
CV_Assert(!unconnectedNodes.empty());
|
||||
CV_Assert(!requestedOutputs.empty());
|
||||
ngraph::ResultVector outs;
|
||||
for (auto& node : unconnectedNodes)
|
||||
|
||||
for (auto output_node_it = requestedOutputs.begin(); output_node_it != requestedOutputs.end(); ++output_node_it)
|
||||
{
|
||||
CV_LOG_DEBUG(NULL, "DNN/IE: +network_output[" << outs.size() << "]: name='" << node->get_friendly_name() << "'");
|
||||
auto out = std::make_shared<ngraph::op::Result>(node);
|
||||
CV_LOG_DEBUG(NULL, "DNN/NGRAPH: Add 'Result' output: " << output_node_it->first);
|
||||
CV_Assert(output_node_it->second);
|
||||
auto out = std::make_shared<ngraph::op::Result>(output_node_it->second->node);
|
||||
outs.push_back(out);
|
||||
}
|
||||
CV_Assert_N(!inputs_vec.empty(), !outs.empty());
|
||||
@ -576,7 +583,7 @@ void InfEngineNgraphNet::init(Target targetId)
|
||||
auto node = ngraph_function->output(i).get_node();
|
||||
for (size_t j = 0; j < node->get_input_size(); ++j) {
|
||||
std::string name = node->input_value(j).get_node()->get_friendly_name();
|
||||
auto iter = std::find(requestedOutputs.begin(), requestedOutputs.end(), name);
|
||||
auto iter = requestedOutputs.find(name);
|
||||
if (iter != requestedOutputs.end()) {
|
||||
requestedOutputs.erase(iter);
|
||||
cnn.addOutput(name);
|
||||
@ -584,10 +591,6 @@ void InfEngineNgraphNet::init(Target targetId)
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const auto& name : requestedOutputs)
|
||||
{
|
||||
cnn.addOutput(name);
|
||||
}
|
||||
|
||||
for (const auto& it : cnn.getInputsInfo())
|
||||
{
|
||||
@ -632,9 +635,6 @@ ngraph::ParameterVector InfEngineNgraphNet::setInputs(const std::vector<cv::Mat>
|
||||
return current_inp;
|
||||
}
|
||||
|
||||
void InfEngineNgraphNet::setUnconnectedNodes(Ptr<InfEngineNgraphNode>& node) {
|
||||
unconnectedNodes.insert(node->node);
|
||||
}
|
||||
|
||||
void InfEngineNgraphNet::initPlugin(InferenceEngine::CNNNetwork& net)
|
||||
{
|
||||
|
@ -37,7 +37,7 @@ public:
|
||||
InfEngineNgraphNet(detail::NetImplBase& netImpl);
|
||||
InfEngineNgraphNet(detail::NetImplBase& netImpl, InferenceEngine::CNNNetwork& net);
|
||||
|
||||
void addOutput(const std::string& name);
|
||||
void addOutput(const Ptr<InfEngineNgraphNode>& node);
|
||||
|
||||
bool isInitialized();
|
||||
void init(Target targetId);
|
||||
@ -47,7 +47,6 @@ public:
|
||||
void initPlugin(InferenceEngine::CNNNetwork& net);
|
||||
ngraph::ParameterVector setInputs(const std::vector<cv::Mat>& inputs, const std::vector<std::string>& names);
|
||||
|
||||
void setUnconnectedNodes(Ptr<InfEngineNgraphNode>& node);
|
||||
void addBlobs(const std::vector<cv::Ptr<BackendWrapper> >& ptrs);
|
||||
|
||||
void createNet(Target targetId);
|
||||
@ -88,8 +87,7 @@ public:
|
||||
|
||||
InferenceEngine::CNNNetwork cnn;
|
||||
bool hasNetOwner;
|
||||
std::vector<std::string> requestedOutputs;
|
||||
std::unordered_set<std::shared_ptr<ngraph::Node>> unconnectedNodes;
|
||||
std::unordered_map<std::string, Ptr<InfEngineNgraphNode> > requestedOutputs;
|
||||
|
||||
std::map<std::string, InferenceEngine::TensorDesc> outputsDesc;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user