diff --git a/inference-engine/ie_bridges/python/src/openvino/inference_engine/ie_api.pyx b/inference-engine/ie_bridges/python/src/openvino/inference_engine/ie_api.pyx index 24465aad20ffc9..235f25800cd1c4 100644 --- a/inference-engine/ie_bridges/python/src/openvino/inference_engine/ie_api.pyx +++ b/inference-engine/ie_bridges/python/src/openvino/inference_engine/ie_api.pyx @@ -715,6 +715,28 @@ cdef class DataPtr: def initialized(self): return deref(self._ptr).isInitialized() + @property + def creator_layer(self): + cdef C.CNNLayerWeakPtr _l_ptr = C.getCreatorLayer(self._ptr) + cdef IENetLayer creator_layer + creator_layer = IENetLayer() + if _l_ptr.lock() != NULL: + creator_layer._ptr = _l_ptr.lock() + else: + raise RuntimeError("Creator IENetLayer of DataPtr object with name {} already released!".format(self.name)) + return creator_layer + + @property + def input_to(self): + cdef map[string, C.CNNLayerPtr] _l_ptr_map = C.getInputTo(self._ptr) + cdef IENetLayer input_to + input_to_list = [] + for layer in _l_ptr_map: + input_to = IENetLayer() + input_to._ptr = layer.second + input_to_list.append(input_to) + return input_to_list + ## This class is the layer constant data representation. Provides same interface as DataPtr object except properties setters cdef class CDataPtr: ## Name of the data object @@ -1250,6 +1272,29 @@ cdef class IENetLayer: def params(self, new_params): deref(self._ptr).params = dict_to_c_map(new_params) + ## Returns a list, which contains names of layers preceding this layer + @property + def parents(self): + cdef vector[C.DataWeakPtr] c_inputs = deref(self._ptr).insData + parents = [] + for l in c_inputs: + if l.lock() != NULL: + parents.append(deref(l.lock()).getName().decode()) + else: + raise RuntimeError("Input Data of layer {} already released!".format(self.name)) + return parents + ## Returns a list, which contains names of layers following this layer + @property + def children(self): + cdef vector[C.DataPtr] c_outs = deref(self._ptr).outData + children = [] + cdef map[string, C.CNNLayerPtr] _l_ptr_map + input_to_list = [] + for l in c_outs: + _l_ptr_map = C.getInputTo(l) + for layer in _l_ptr_map: + input_to_list.append(deref(layer.second).name.decode()) + return input_to_list ## \note This property is deprecated. # Please, use out_data property to access DataPtr objects for all output ports, which contains full # information about layer's output data including layout diff --git a/inference-engine/ie_bridges/python/src/openvino/inference_engine/ie_api_impl_defs.pxd b/inference-engine/ie_bridges/python/src/openvino/inference_engine/ie_api_impl_defs.pxd index f2c23e02111826..0b1978e0e6d993 100644 --- a/inference-engine/ie_bridges/python/src/openvino/inference_engine/ie_api_impl_defs.pxd +++ b/inference-engine/ie_bridges/python/src/openvino/inference_engine/ie_api_impl_defs.pxd @@ -141,6 +141,11 @@ cdef extern from "" namespace "InferenceEngine": CN BLOCKED + +cdef extern from "" namespace "InferenceEngine": + cdef weak_ptr[CNNLayer] getCreatorLayer(const shared_ptr[Data] & data) + map[string, shared_ptr[CNNLayer]] & getInputTo(const shared_ptr[Data] & data) + cdef extern from "ie_api_impl.hpp" namespace "InferenceEnginePython": cdef cppclass ProfileInfo: diff --git a/inference-engine/ie_bridges/python/tests/test_DataPtr.py b/inference-engine/ie_bridges/python/tests/test_DataPtr.py index 302e6ac054b052..4628486cd71974 100644 --- a/inference-engine/ie_bridges/python/tests/test_DataPtr.py +++ b/inference-engine/ie_bridges/python/tests/test_DataPtr.py @@ -40,3 +40,21 @@ def test_layout(): def test_initialized(): assert layer_out_data().initialized, "Incorrect value for initialized property for layer '19/Fused_Add_'" + + +def test_input_to(): + ie = IECore() + net = ie.read_network(model=test_net_xml, weights=test_net_bin) + input_to = net.layers['26'].out_data[0].input_to + assert len(input_to) == 1 + assert input_to[0].name == '27' + +def test_creator_layer(): + ie = IECore() + net = ie.read_network(model=test_net_xml, weights=test_net_bin) + outputs = net.outputs + assert len(outputs) == 1 + creator_layer = outputs['fc_out'].creator_layer + params = creator_layer.params + params['originalLayersNames'] == 'fc_out' + params['axis'] == '1' \ No newline at end of file diff --git a/inference-engine/ie_bridges/python/tests/test_IENetLayer.py b/inference-engine/ie_bridges/python/tests/test_IENetLayer.py index 54630343d73f89..6404c51908a76a 100644 --- a/inference-engine/ie_bridges/python/tests/test_IENetLayer.py +++ b/inference-engine/ie_bridges/python/tests/test_IENetLayer.py @@ -120,3 +120,17 @@ def test_in_data(): ie = IECore() net = ie.read_network(model=test_net_xml, weights=test_net_bin) assert isinstance(net.layers['27'].in_data[0], DataPtr) + +def test_parents(): + ie = IECore() + net = ie.read_network(model=test_net_xml, weights=test_net_bin) + parents = net.layers['27'].parents + assert len(parents) == 1 + assert(parents[0] == '26') + +def test_children(): + ie = IECore() + net = ie.read_network(model=test_net_xml, weights=test_net_bin) + children = net.layers['26'].children + assert len(children) == 1 + assert(children[0] == '27') \ No newline at end of file