## This class represents a main layer information and providing setters allowing to modify layer properties
+#
+# \note This class is deprecated: for working with layers, please, use nGraph Python API.
+# This class is going to be removed in 2021.2
+#
cdef class IENetLayer:
## Name of the layer
@property
def type(self):
return deref(self._ptr).type.decode()
- ## \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 precision.
- #
- # Layer base operating precision. Provides getter and setter interfaces.
- @property
- def precision(self):
- warnings.warn("precision property of IENetLayer is deprecated. "
- "Please instead use precision property of DataPtr objects "
- "returned by out_data property",
- DeprecationWarning)
- return deref(self._ptr).precision.name().decode()
-
- @precision.setter
- def precision(self, precision: str):
- deref(self._ptr).precision = C.Precision.FromStr(precision.encode())
## Layer affinity set by user or a default affinity may be setted using `IECore.query_network() method`
# which returns dictionary {layer_name : device}.
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
- #
- # Returns the layout of the layer output data on 1st port
- @property
- def layout(self):
- warnings.warn("layout property of IENetLayer is deprecated. "
- "Please instead use shape property of DataPtr objects "
- "returned by in_data or out_data property to access shape of input or output data "
- "on corresponding ports",
- DeprecationWarning)
- cdef C.DataPtr c_input = deref(self._ptr).outData[0]
- return layout_int_to_str_map[deref(c_input).getLayout()]
-
- ## \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 shape
- #
- # Return the list of dimension of the layer output data on 1st port
- @property
- def shape(self):
- warnings.warn("shape property of IENetLayer is deprecated. "
- "Please use shape property of DataPtr instead objects "
- "returned by in_data or out_data property to access shape of input or output data "
- "on corresponding ports",
- DeprecationWarning)
- cdef C.DataPtr c_input = deref(self._ptr).outData[0]
- return deref(c_input).getDims()
## Returns a list of DataPtr objects representing the output data of the layer on corresponding port
@property
blobs_map[blob.first.decode()] = weights_buffer.to_numpy()
return blobs_map
- ## \note This property is deprecated.
- # Please use blobs property instead.
- #
- # Dictionary with layer weights, biases or custom blobs if any
- @property
- def weights(self):
- warnings.warn("weights property of IENetLayer is deprecated. "
- "Please use blobs property instead.",
- DeprecationWarning)
- return self.blobs
-
## This class contains the information about the network model read from IR and allows you to manipulate with
# some model parameters such as layers affinity and output layers.
raise AttributeError("Invalid batch size {}! Batch size should be positive integer value".format(batch))
self.impl.setBatch(batch)
- ## Return dictionary that maps network layer names in topological order to IENetLayer
+ ## \note The property is deprecated. Please use get_ops()/get_ordered_ops() methods
+ # from nGraph Python API.
+ # This property will be removed in 2021.2.
+ #
+ # Return dictionary that maps network layer names in topological order to IENetLayer
# objects containing layer properties
@property
def layers(self):
+ warnings.warn("'layers' property of IENetwork class is deprecated. "
+ "For iteration over network please use get_ops()/get_ordered_ops() methods "
+ "from nGraph Python API",
+ DeprecationWarning)
cdef vector[C.CNNLayerPtr] c_layers = self.impl.getLayers()
layers = OrderedDict()
cdef IENetLayer net_l
import pytest
+import warnings
from openvino.inference_engine import IECore, IENetLayer, DataPtr
from conftest import model_path
return net.layers['19/Fused_Add_'].out_data[0]
-def test_name():
+def test_name(recwarn):
+ warnings.simplefilter("always")
assert layer_out_data().name == "19/Fused_Add_", "Incorrect name for layer '19/Fused_Add_'"
+ assert len(recwarn) == 1
+ assert recwarn.pop(DeprecationWarning)
-def test_precision():
+def test_precision(recwarn):
+ warnings.simplefilter("always")
assert layer_out_data().precision == "FP32", "Incorrect precision for layer '19/Fused_Add_'"
+ assert len(recwarn) == 1
+ assert recwarn.pop(DeprecationWarning)
-def test_precision_setter():
+def test_precision_setter(recwarn):
+ warnings.simplefilter("always")
ie = IECore()
net = ie.read_network(model=test_net_xml, weights=test_net_bin)
net.layers['19/Fused_Add_'].out_data[0].precision = "I8"
assert net.layers['19/Fused_Add_'].out_data[0].precision == "I8", "Incorrect precision for layer '19/Fused_Add_'"
+ assert len(recwarn) == 2
+ assert recwarn.pop(DeprecationWarning)
-def test_incorrect_precision_setter():
+def test_incorrect_precision_setter(recwarn):
+ warnings.simplefilter("always")
with pytest.raises(ValueError) as e:
layer_out_data().precision = "123"
assert "Unsupported precision 123! List of supported precisions:" in str(e.value)
+ assert len(recwarn) == 1
+ assert recwarn.pop(DeprecationWarning)
-def test_layout():
+def test_layout(recwarn):
+ warnings.simplefilter("always")
assert layer_out_data().layout == "NCHW", "Incorrect layout for layer '19/Fused_Add_'"
+ assert len(recwarn) == 1
+ assert recwarn.pop(DeprecationWarning)
-def test_initialized():
+def test_initialized(recwarn):
+ warnings.simplefilter("always")
assert layer_out_data().initialized, "Incorrect value for initialized property for layer '19/Fused_Add_'"
+ assert len(recwarn) == 1
+ assert recwarn.pop(DeprecationWarning)
-def test_input_to():
+def test_input_to(recwarn):
+ warnings.simplefilter("always")
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'
+ assert len(recwarn) == 1
+ assert recwarn.pop(DeprecationWarning)
+
def test_input_to_via_input_info():
ie = IECore()
assert len(input_to) == 1
assert input_to[0].name == '19/Fused_Add_'
-def test_input_to_via_inputs():
+
+def test_input_to_via_inputs(recwarn):
+ warnings.simplefilter("always")
ie = IECore()
net = ie.read_network(model=test_net_xml, weights=test_net_bin)
inputs = net.inputs
input_to = inputs['data'].input_to
assert len(input_to) == 1
assert input_to[0].name == '19/Fused_Add_'
+ assert len(recwarn) == 1
+ assert recwarn.pop(DeprecationWarning)
+
def test_creator_layer():
ie = IECore()
creator_layer = outputs['fc_out'].creator_layer
params = creator_layer.params
params['originalLayersNames'] == 'fc_out'
- params['axis'] == '1'
\ No newline at end of file
+ params['axis'] == '1'
@pytest.mark.skip(reason="IENetwork.layers return not all layers in case of ngraph representation due to inner conversion into legacy representation")
-def test_query_network(device):
+def test_query_network(device, recwarn):
ie = IECore()
net = ie.read_network(model=test_net_xml, weights=test_net_bin)
query_res = ie.query_network(net, device)
assert net.layers.keys() == query_res.keys(), "Not all network layers present in query_network results"
assert next(iter(set(query_res.values()))) == device, "Wrong device for some layers"
+ assert len(recwarn) == 1
+ assert recwarn.pop(DeprecationWarning)
@pytest.mark.skipif(os.environ.get("TEST_DEVICE", "CPU") != "CPU", reason="Device independent test")
assert isinstance(net, IENetwork)
-def test_net_from_buffer_valid():
+def test_net_from_buffer_valid(recwarn):
ie = IECore()
with open(test_net_bin, 'rb') as f:
bin = f.read()
for blob, data in layer.blobs.items():
assert np.allclose(data, net2.layers[name].blobs[blob]), \
"Incorrect weights for layer {} and blob {}".format(name, blob)
+ assert len(recwarn) == 2
+ assert recwarn.pop(DeprecationWarning)
test_net_xml, test_net_bin = model_path()
-def test_name():
- ie = IECore()
- net = ie.read_network(model=test_net_xml, weights=test_net_bin)
- assert net.layers['27'].name == "27"
-
-
-def test_type():
- ie = IECore()
- net = ie.read_network(model=test_net_xml, weights=test_net_bin)
- assert net.layers['27'].type == "Pooling"
-
-
-def test_precision_getter(recwarn):
+def test_name(recwarn):
warnings.simplefilter("always")
ie = IECore()
net = ie.read_network(model=test_net_xml, weights=test_net_bin)
- assert net.layers['27'].precision == "FP32"
+ assert net.layers['27'].name == "27"
assert len(recwarn) == 1
assert recwarn.pop(DeprecationWarning)
-def test_precision_setter(recwarn):
+def test_type(recwarn):
warnings.simplefilter("always")
ie = IECore()
net = ie.read_network(model=test_net_xml, weights=test_net_bin)
- net.layers['27'].precision = "I8"
- assert net.layers['27'].precision == "I8"
+ assert net.layers['27'].type == "Pooling"
assert len(recwarn) == 1
assert recwarn.pop(DeprecationWarning)
-def test_affinity_getter():
+def test_affinity_getter(recwarn):
+ warnings.simplefilter("always")
ie = IECore()
net = ie.read_network(model=test_net_xml, weights=test_net_bin)
assert net.layers['27'].affinity == ""
+ assert len(recwarn) == 1
+ assert recwarn.pop(DeprecationWarning)
-def test_affinity_setter():
+def test_affinity_setter(recwarn):
+ warnings.simplefilter("always")
ie = IECore()
net = ie.read_network(model=test_net_xml, weights=test_net_bin)
net.layers['27'].affinity = "CPU"
assert net.layers['27'].affinity == "CPU"
+ assert len(recwarn) == 2
+ assert recwarn.pop(DeprecationWarning)
-def test_blobs():
+def test_blobs(recwarn):
+ warnings.simplefilter("always")
ie = IECore()
net = ie.read_network(model=test_net_xml, weights=test_net_bin)
assert isinstance(net.layers['19/Fused_Add_'].blobs["biases"], numpy.ndarray)
assert isinstance(net.layers['19/Fused_Add_'].blobs["weights"], numpy.ndarray)
assert net.layers['19/Fused_Add_'].blobs["biases"].size != 0
assert net.layers['19/Fused_Add_'].blobs["weights"].size != 0
-
-
-def test_weights(recwarn):
- warnings.simplefilter("always")
- ie = IECore()
- net = ie.read_network(model=test_net_xml, weights=test_net_bin)
- assert isinstance(net.layers['19/Fused_Add_'].weights["biases"], numpy.ndarray)
- assert isinstance(net.layers['19/Fused_Add_'].weights["weights"], numpy.ndarray)
- assert net.layers['19/Fused_Add_'].weights["biases"].size != 0
- assert net.layers['19/Fused_Add_'].weights["weights"].size != 0
assert len(recwarn) == 4
assert recwarn.pop(DeprecationWarning)
-def test_params_getter():
+def test_params_getter(recwarn):
+ warnings.simplefilter("always")
ie = IECore()
net = ie.read_network(model=test_net_xml, weights=test_net_bin)
assert net.layers['27'].params == {"kernel" : "2,2", "pads_begin" : "0,0",
"pads_end" : "0,0", "rounding_type" : "floor",
"strides" : "2,2", "pool-method" : "max",
"originalLayersNames" : "27"}
+ assert len(recwarn) == 1
+ assert recwarn.pop(DeprecationWarning)
-def test_params_setter():
+def test_params_setter(recwarn):
+ warnings.simplefilter("always")
ie = IECore()
net = ie.read_network(model=test_net_xml, weights=test_net_bin)
params = net.layers['27'].params
"pads_end" : "0,0", "rounding_type" : "floor",
"strides" : "2,2", "pool-method" : "max",
"originalLayersNames" : "27", 'PrimitivesPriority': 'cpu:ref_any'}
+ assert len(recwarn) == 3
+ assert recwarn.pop(DeprecationWarning)
+
-def test_layout(recwarn):
+def test_out_data(recwarn):
warnings.simplefilter("always")
ie = IECore()
net = ie.read_network(model=test_net_xml, weights=test_net_bin)
- assert net.layers['27'].layout == 'NCHW'
+ assert isinstance(net.layers['27'].out_data[0], DataPtr)
assert len(recwarn) == 1
assert recwarn.pop(DeprecationWarning)
-def test_shape(recwarn):
+def test_in_data(recwarn):
warnings.simplefilter("always")
ie = IECore()
net = ie.read_network(model=test_net_xml, weights=test_net_bin)
- assert net.layers['27'].shape == [1, 64, 9, 9]
+ assert isinstance(net.layers['27'].in_data[0], DataPtr)
assert len(recwarn) == 1
+ assert recwarn.pop(DeprecationWarning)
-def test_out_data():
- ie = IECore()
- net = ie.read_network(model=test_net_xml, weights=test_net_bin)
- assert isinstance(net.layers['27'].out_data[0], DataPtr)
-
-
-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():
+def test_parents(recwarn):
+ warnings.simplefilter("always")
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')
+ assert len(recwarn) == 1
+ assert recwarn.pop(DeprecationWarning)
+
-def test_children():
+def test_children(recwarn):
+ warnings.simplefilter("always")
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
+ assert(children[0] == '27')
+ assert len(recwarn) == 1
+ assert recwarn.pop(DeprecationWarning)
assert net.input_info['data'].input_data.shape == [8, 3, 32, 32]
-def test_layers():
+def test_layers(recwarn):
+ warnings.simplefilter("always")
ie = IECore()
net = ie.read_network(model=test_net_xml, weights=test_net_bin)
layers_name = [key for key in net.layers]
assert sorted(layers_name) == ['19/Fused_Add_', '21', '22', '23', '24/Fused_Add_',
'26', '27', '29', 'data', 'fc_out']
assert isinstance(net.layers['19/Fused_Add_'], IENetLayer)
+ assert len(recwarn) == 2
+ assert recwarn.pop(DeprecationWarning)
@pytest.mark.skip(reason="Test is failed due-to ngraph conversion")
-def test_serialize():
+def test_serialize(recwarn):
+ warnings.simplefilter("always")
ie = IECore()
net = ie.read_network(model=test_net_xml, weights=test_net_bin)
net.serialize("./serialized_net.xml", "./serialized_net.bin")
assert net.layers.keys() == serialized_net.layers.keys()
os.remove("./serialized_net.xml")
os.remove("./serialized_net.bin")
+ assert len(recwarn) == 2
+ assert recwarn.pop(DeprecationWarning)
def test_reshape():
for blob, data in l.blobs.items():
assert np.allclose(data, net2.layers[name].blobs[blob]), \
"Incorrect weights for layer {} and blob {}".format(name, blob)
- assert len(w) == 2
- for warns in w:
- assert issubclass(warns.category, DeprecationWarning)
- assert "Reading network using constructor is deprecated. " \
- "Please, use IECore.read_network() method instead" in str(warns.message)
+ assert len(w) == 11
def test_multi_out_data():
-from openvino.inference_engine import IENetwork
+from openvino.inference_engine import IECore, IENetwork
try:
import ngraph as ng
except:
ngraph_available=False
-import numpy as np
import pytest
+from conftest import model_path
+
+
+test_net_xml, test_net_bin = model_path()
+
if not ngraph_available:
pytest.skip("NGraph is not installed, skip", allow_module_level=True)
-def test_CreateIENetworkFromNGraph():
+
+def test_create_IENetwork_from_nGraph():
element_type = Type.f32
param = Parameter(element_type, Shape([1, 3, 22, 22]))
relu = ng.relu(param)
caps = Function.to_capsule(func)
cnnNetwork = IENetwork(caps)
assert cnnNetwork != None
- assert ng.function_from_cnn(cnnNetwork) != None
- assert len(cnnNetwork.layers) == 2
+ func2 = ng.function_from_cnn(cnnNetwork)
+ assert func2 != None
+ assert len(func2.get_ops()) == 3
+
-def test_GetIENetworkFromNGraph():
+def test_get_IENetwork_from_nGraph():
element_type = Type.f32
param = Parameter(element_type, Shape([1, 3, 22, 22]))
relu = ng.relu(param)
assert ng.function_from_cnn(cnnNetwork) != None
func2 = ng.function_from_cnn(cnnNetwork)
assert func2 != None
+
+
+def test_get_ops_from_IENetwork():
+ ie = IECore()
+ net = ie.read_network(model=test_net_xml, weights=test_net_bin)
+ func = ng.function_from_cnn(net)
+ ops = func.get_ordered_ops()
+ ops_names = [op.friendly_name for op in ops]
+ assert ops_names == ['data', '20/mean/Fused_Mul_614616_const', '19/WithoutBiases', 'data_add_575/copy_const',
+ '19/Fused_Add_', '21', '22', 'onnx_initializer_node_8/Output_0/Data__const',
+ '23/WithoutBiases', '23/Dims357/copy_const', '23', '25/mean/Fused_Mul_618620_const',
+ '24/WithoutBiases', 'data_add_578583/copy_const', '24/Fused_Add_', '26', '27',
+ '28/Reshape/Cast_1955_const', '28/Reshape', 'onnx_initializer_node_17/Output_0/Data__const',
+ '29/WithoutBiases', 'onnx_initializer_node_18/Output_0/Data_/copy_const', '29', 'fc_out',
+ 'fc_out/sink_port_0']