Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python fix #1

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ cdef extern from "<inference_engine.hpp>" namespace "InferenceEngine":
CN
BLOCKED


cdef extern from "<ie_layers.h>" 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:
Expand Down
18 changes: 18 additions & 0 deletions inference-engine/ie_bridges/python/tests/test_DataPtr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
14 changes: 14 additions & 0 deletions inference-engine/ie_bridges/python/tests/test_IENetLayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')