Aligned python read_network() with C/C++ behaviour (#2916)
authorMikhail Ryzhov <mikhail.ryzhov@intel.com>
Tue, 3 Nov 2020 13:18:43 +0000 (16:18 +0300)
committerGitHub <noreply@github.com>
Tue, 3 Nov 2020 13:18:43 +0000 (16:18 +0300)
Aligned python read_network() with C/C++ behaviour

Excluded mandatory check of weights file, it is redundant

* Added unit tests

inference-engine/ie_bridges/python/sample/classification_sample_async/classification_sample_async.py
inference-engine/ie_bridges/python/sample/hello_classification/hello_classification.py
inference-engine/ie_bridges/python/sample/object_detection_sample_ssd/object_detection_sample_ssd.py
inference-engine/ie_bridges/python/sample/style_transfer_sample/style_transfer_sample.py
inference-engine/ie_bridges/python/src/openvino/inference_engine/ie_api.pyx
inference-engine/ie_bridges/python/tests/test_IECore.py

index 315d3e3..aa38d5a 100644 (file)
@@ -105,14 +105,8 @@ def main():
 
     # Read a model in OpenVINO Intermediate Representation (.xml and .bin files) or ONNX (.onnx file) format
     model = args.model
-    model_bin = None
-    model_name, model_ext = os.path.splitext(model)
-    log.info(f"Loading network files:\n\t{model}")
-    if model_ext == ".xml":
-        # Read .bin weights for IR format only
-        model_bin = model_name + ".bin"
-        log.info(f"\n\t{model_bin}")
-    net = ie.read_network(model=model, weights=model_bin)
+    log.info(f"Loading network:\n\t{model}")
+    net = ie.read_network(model=model)
 
     assert len(net.input_info.keys()) == 1, "Sample supports only single input topologies"
     assert len(net.outputs) == 1, "Sample supports only single output topologies"
index 0de5732..091b463 100644 (file)
@@ -60,14 +60,8 @@ def main():
 
     # Read a model in OpenVINO Intermediate Representation (.xml and .bin files) or ONNX (.onnx file) format
     model = args.model
-    model_bin = None
-    model_name, model_ext = os.path.splitext(model)
-    log.info(f"Loading network files:\n\t{model}")
-    if model_ext == ".xml":
-        # Read .bin weights for IR format only
-        model_bin = model_name + ".bin"
-        log.info(f"\n\t{model_bin}")
-    net = ie.read_network(model=model, weights=model_bin)
+    log.info(f"Loading network:\n\t{model}")
+    net = ie.read_network(model=model)
 
     assert len(net.input_info.keys()) == 1, "Sample supports only single input topologies"
     assert len(net.outputs) == 1, "Sample supports only single output topologies"
index 35ecd58..081a5fd 100644 (file)
@@ -56,14 +56,8 @@ def main():
 
     # ---1. Read a model in OpenVINO Intermediate Representation (.xml and .bin files) or ONNX (.onnx file) format ---
     model = args.model
-    model_bin = None
-    model_name, model_ext = os.path.splitext(model)
-    log.info(f"Loading network files:\n\t{model}")
-    if model_ext == ".xml":
-        # Read .bin weights for IR format only
-        model_bin = model_name + ".bin"
-        log.info(f"\n\t{model_bin}")
-    net = ie.read_network(model=model, weights=model_bin)
+    log.info(f"Loading network:\n\t{model}")
+    net = ie.read_network(model=model)
     func = ng.function_from_cnn(net)
     ops = func.get_ordered_ops()
     # -----------------------------------------------------------------------------------------------------
index ce1d221..22905fa 100644 (file)
@@ -64,14 +64,8 @@ def main():
 
     # Read a model in OpenVINO Intermediate Representation (.xml and .bin files) or ONNX (.onnx file) format
     model = args.model
-    model_bin = None
-    model_name, model_ext = os.path.splitext(model)
-    log.info(f"Loading network files:\n\t{model}")
-    if model_ext == ".xml":
-        # Read .bin weights for IR format only
-        model_bin = model_name + ".bin"
-        log.info(f"\n\t{model_bin}")
-    net = ie.read_network(model=model, weights=model_bin)
+    log.info(f"Loading network:\n\t{model}")
+    net = ie.read_network(model=model)
 
     assert len(net.input_info.keys()) == 1, "Sample supports only single input topologies"
     assert len(net.outputs) == 1, "Sample supports only single output topologies"
index 67c2ed6..a883b46 100644 (file)
@@ -276,7 +276,7 @@ cdef class IECore:
                 raise Exception("Path to the model {} doesn't exist or it's a directory".format(model))
             model_ = model.encode()
 
-            if not (fnmatch(model, "*.onnx") or fnmatch(model, "*.prototxt")):
+            if not (fnmatch(model, "*.onnx") or fnmatch(model, "*.prototxt")) and weights:
                 weights = os.fspath(weights)
                 if not os.path.isfile(weights):
                     raise Exception("Path to the weights {} doesn't exist or it's a directory".format(weights))
index 90c4120..3e020d8 100644 (file)
@@ -155,6 +155,9 @@ def test_read_network_from_xml():
     net = ie.read_network(model=test_net_xml, weights=test_net_bin)
     assert isinstance(net, IENetwork)
 
+    net = ie.read_network(model=test_net_xml)
+    assert isinstance(net, IENetwork)
+
 
 def test_read_network_as_path():
     ie = IECore()
@@ -165,6 +168,9 @@ def test_read_network_as_path():
     net = ie.read_network(model=test_net_xml, weights=Path(test_net_bin))
     assert isinstance(net, IENetwork)
 
+    net = ie.read_network(model=Path(test_net_xml))
+    assert isinstance(net, IENetwork)
+
 
 def test_read_network_from_onnx():
     ie = IECore()