mirror of
https://github.com/opencv/opencv.git
synced 2026-07-21 19:33:03 +04:00
Merge pull request #28982 from Prasadayus:fix_unconnected_out_layers
fix getUnconnectedOutLayers() in new engine #28982 Solves https://github.com/opencv/opencv/issues/26491 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
committed by
GitHub
parent
3cebf7d61e
commit
2ad46b860b
@@ -2378,11 +2378,33 @@ std::vector<String> Net::Impl::getLayerNames() const
|
||||
}
|
||||
|
||||
|
||||
// FIXIT drop "unconnected" API
|
||||
std::vector<int> Net::Impl::getUnconnectedOutLayers() const
|
||||
{
|
||||
std::vector<int> layersIds;
|
||||
|
||||
if (mainGraph) {
|
||||
const std::vector<Arg>& outargs = mainGraph->outputs();
|
||||
std::set<int> outArgIdxs;
|
||||
for (const auto& out : outargs)
|
||||
outArgIdxs.insert(out.idx);
|
||||
|
||||
int graph_ofs = 0;
|
||||
for (const auto& graph : allgraphs) {
|
||||
const std::vector<Ptr<Layer>>& prog = graph->prog();
|
||||
for (int i = 0; i < (int)prog.size(); i++) {
|
||||
for (const auto& layerOut : prog[i]->outputs) {
|
||||
if (outArgIdxs.count(layerOut.idx)) {
|
||||
layersIds.push_back(graph_ofs + i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
graph_ofs += (int)prog.size();
|
||||
}
|
||||
if (!layersIds.empty())
|
||||
return layersIds;
|
||||
}
|
||||
|
||||
// registerOutput() flow
|
||||
if (!outputNameToId.empty())
|
||||
{
|
||||
|
||||
@@ -3566,4 +3566,28 @@ TEST_P(Test_ONNX_layers, RandomNormalLike_complex)
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(/**/, Test_ONNX_nets, dnnBackendsAndTargets());
|
||||
|
||||
TEST_P(Test_ONNX_layers, getUnconnectedOutLayers)
|
||||
{
|
||||
auto engine_forced = static_cast<cv::dnn::EngineType>(
|
||||
cv::utils::getConfigurationParameterSizeT("OPENCV_FORCE_DNN_ENGINE", cv::dnn::ENGINE_AUTO));
|
||||
if (engine_forced == cv::dnn::ENGINE_ORT)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_PARSER);
|
||||
|
||||
Net net = readNetFromONNX(_tf("models/yolov8x.onnx", false));
|
||||
ASSERT_FALSE(net.empty());
|
||||
net.setPreferableBackend(backend);
|
||||
net.setPreferableTarget(target);
|
||||
|
||||
std::vector<int> outIds = net.getUnconnectedOutLayers();
|
||||
std::vector<String> outNames = net.getUnconnectedOutLayersNames();
|
||||
|
||||
EXPECT_EQ(outIds.size(), outNames.size());
|
||||
EXPECT_EQ(1, outIds.size());
|
||||
|
||||
EXPECT_EQ("output0", outNames[0]);
|
||||
EXPECT_GT(outIds[0], 0);
|
||||
Ptr<Layer> layer = net.getLayer(outIds[0]);
|
||||
ASSERT_TRUE(layer);
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
|
||||
Reference in New Issue
Block a user