Skip to content

Commit 8d74aaa

Browse files
dkurtalalek
authored andcommitted
Merge pull request #1006 from dkurt:get_layer_inputs
Getting layer inputs (#1006)
1 parent f39f415 commit 8d74aaa

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

modules/dnn/include/opencv2/dnn/dnn.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ namespace dnn //! This namespace is used for dnn module functionlaity.
182182
/** @brief Returns pointer to layer with specified name which the network use. */
183183
CV_WRAP Ptr<Layer> getLayer(LayerId layerId);
184184

185+
/** @brief Returns pointers to input layers of specific layer. */
186+
CV_WRAP std::vector<Ptr<Layer> > getLayerInputs(LayerId layerId);
187+
185188
/** @brief Delete layer for the network (not implemented yet) */
186189
CV_WRAP void deleteLayer(LayerId layer);
187190

modules/dnn/src/dnn.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,10 +568,25 @@ Ptr<Layer> Net::getLayer(LayerId layerId)
568568
{
569569
LayerData &ld = impl->getLayerData(layerId);
570570
if (!ld.layerInstance)
571-
CV_Error(Error::StsNullPtr, format("Requseted layer \"%s\" was not initialized", ld.name.c_str()));
571+
CV_Error(Error::StsNullPtr, format("Requested layer \"%s\" was not initialized", ld.name.c_str()));
572572
return ld.layerInstance;
573573
}
574574

575+
std::vector<Ptr<Layer> > Net::getLayerInputs(LayerId layerId)
576+
{
577+
LayerData &ld = impl->getLayerData(layerId);
578+
if (!ld.layerInstance)
579+
CV_Error(Error::StsNullPtr, format("Requested layer \"%s\" was not initialized", ld.name.c_str()));
580+
581+
std::vector<Ptr<Layer> > inputLayers;
582+
inputLayers.reserve(ld.inputLayersId.size());
583+
std::set<int>::iterator it;
584+
for (it = ld.inputLayersId.begin(); it != ld.inputLayersId.end(); ++it) {
585+
inputLayers.push_back(getLayer(*it));
586+
}
587+
return inputLayers;
588+
}
589+
575590
std::vector<String> Net::getLayerNames() const
576591
{
577592
std::vector<String> res;

0 commit comments

Comments
 (0)