Skip to content

Commit 9453e7e

Browse files
author
Roman Donchenko
authored
Merge pull request #1067 from AnthonyQuantum/replace-deprecated-IENetwork
Replace deprecated IENetwork with ie.read_network() in Python demos
2 parents e81eb31 + eb0b398 commit 9453e7e

File tree

19 files changed

+50
-92
lines changed

19 files changed

+50
-92
lines changed

demos/python_demos/3d_segmentation_demo/3d_segmentation_demo.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from scipy.ndimage import interpolation
2929
from sys import stdout
3030

31-
from openvino.inference_engine import IENetwork, IECore
31+
from openvino.inference_engine import IECore
3232

3333

3434
logging.basicConfig(format="[ %(levelname)s ] %(message)s", level=logging.INFO, stream=stdout)
@@ -269,11 +269,7 @@ def main():
269269
logger.info("Plugin version is {}".format(version_str))
270270

271271
# --------------------- 2. Read IR Generated by ModelOptimizer (.xml and .bin files) ---------------------
272-
273-
xml_filename = os.path.abspath(args.path_to_model)
274-
bin_filename = os.path.abspath(os.path.splitext(xml_filename)[0] + '.bin')
275-
276-
ie_network = IENetwork(xml_filename, bin_filename)
272+
ie_network = ie.read_network(args.path_to_model, os.path.splitext(args.path_to_model)[0] + '.bin')
277273

278274
input_info = ie_network.inputs
279275
if len(input_info) == 0:

demos/python_demos/action_recognition/action_recognition_demo/models.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import cv2
2121
import numpy as np
22-
from openvino.inference_engine import IENetwork
2322

2423

2524
def center_crop(frame, crop_size):
@@ -87,7 +86,7 @@ def __init__(self, model_xml, model_bin, ie_core, target_device, num_requests, b
8786

8887
# Read IR
8988
print("Reading IR...")
90-
self.net = IENetwork(model_xml, model_bin)
89+
self.net = ie_core.read_network(model_xml, model_bin)
9190
self.net.batch_size = batch_size
9291
assert len(self.net.inputs.keys()) == 1, "One input is expected"
9392
assert len(self.net.outputs) == 1, "One output is expected"

demos/python_demos/asl_recognition_demo/asl_recognition_demo/common.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
limitations under the License.
1515
"""
1616

17-
from openvino.inference_engine import IENetwork, IECore # pylint: disable=no-name-in-module
17+
from openvino.inference_engine import IECore # pylint: disable=no-name-in-module
1818

1919

2020
def load_ie_core(device, cpu_extension=None):
@@ -34,9 +34,7 @@ def __init__(self, model_path, device, ie_core, num_requests, output_shape=None)
3434
"""Constructor"""
3535
if model_path.endswith((".xml", ".bin")):
3636
model_path = model_path[:-4]
37-
model_xml = model_path + ".xml"
38-
model_bin = model_path + ".bin"
39-
self.net = IENetwork(model=model_xml, weights=model_bin)
37+
self.net = ie_core.read_network(model_path + ".xml", model_path + ".bin")
4038
assert len(self.net.inputs.keys()) == 1, "One input is expected"
4139

4240
supported_layers = ie_core.query_network(self.net, device)

demos/python_demos/colorization_demo/colorization_demo.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
limitations under the License.
1616
"""
1717

18-
from openvino.inference_engine import IENetwork, IECore
18+
from openvino.inference_engine import IECore
1919
import cv2 as cv
2020
import numpy as np
2121
import os
@@ -48,18 +48,17 @@ def build_arg():
4848

4949
if __name__ == '__main__':
5050
args = build_arg().parse_args()
51-
model_path = os.path.splitext(args.model)[0]
52-
weights_bin = model_path + ".bin"
5351
coeffs = args.coeffs
5452

5553
# mean is stored in the source caffe model and passed to IR
5654
log.basicConfig(format="[ %(levelname)s ] %(message)s",
5755
level=log.INFO if not args.verbose else log.DEBUG, stream=sys.stdout)
5856

5957
log.debug("Load network")
60-
load_net = IENetwork(model=args.model, weights=weights_bin)
58+
ie = IECore()
59+
load_net = ie.read_network(args.model, os.path.splitext(args.model)[0] + ".bin")
6160
load_net.batch_size = 1
62-
exec_net = IECore().load_network(network=load_net, device_name=args.device)
61+
exec_net = ie.load_network(network=load_net, device_name=args.device)
6362

6463
assert len(load_net.inputs) == 1, "Expected number of inputs is equal 1"
6564
input_blob = next(iter(load_net.inputs))

demos/python_demos/face_recognition_demo/face_recognition_demo.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import cv2
2525
import numpy as np
2626

27-
from openvino.inference_engine import IENetwork
2827
from ie_module import InferenceContext
2928
from landmarks_detector import LandmarksDetector
3029
from face_detector import FaceDetector
@@ -167,14 +166,13 @@ def __init__(self, args):
167166

168167
def load_model(self, model_path):
169168
model_path = osp.abspath(model_path)
170-
model_description_path = model_path
171169
model_weights_path = osp.splitext(model_path)[0] + ".bin"
172-
log.info("Loading the model from '%s'" % (model_description_path))
173-
assert osp.isfile(model_description_path), \
174-
"Model description is not found at '%s'" % (model_description_path)
170+
log.info("Loading the model from '%s'" % (model_path))
171+
assert osp.isfile(model_path), \
172+
"Model description is not found at '%s'" % (model_path)
175173
assert osp.isfile(model_weights_path), \
176174
"Model weights are not found at '%s'" % (model_weights_path)
177-
model = IENetwork(model_description_path, model_weights_path)
175+
model = self.context.ie_core.read_network(model_path, model_weights_path)
178176
log.info("Model is loaded")
179177
return model
180178

demos/python_demos/handwritten_japanese_recognition_demo/handwritten_japanese_recognition_demo.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import cv2
2222
import numpy as np
2323

24-
from openvino.inference_engine import IENetwork, IECore
24+
from openvino.inference_engine import IECore
2525
from utils.codec import CTCCodec
2626

2727

@@ -66,14 +66,12 @@ def preprocess_input(image_name, height, width):
6666
def main():
6767
log.basicConfig(format="[ %(levelname)s ] %(message)s", level=log.INFO, stream=sys.stdout)
6868
args = build_argparser().parse_args()
69-
model_xml = args.model
70-
model_bin = os.path.splitext(model_xml)[0] + ".bin"
7169

7270
# Plugin initialization
7371
ie = IECore()
7472
# Read IR
75-
log.info("Loading network files:\n\t{}\n\t{}".format(model_xml, model_bin))
76-
net = IENetwork(model=model_xml, weights=model_bin)
73+
log.info("Loading network")
74+
net = ie.read_network(args.model, os.path.splitext(args.model)[0] + ".bin")
7775

7876
assert len(net.inputs) == 1, "Demo supports only single input topologies"
7977
assert len(net.outputs) == 1, "Demo supports only single output topologies"

demos/python_demos/human_pose_estimation_3d_demo/modules/inference_engine.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,24 @@
1616

1717
import numpy as np
1818

19-
from openvino.inference_engine import IENetwork, IECore
19+
from openvino.inference_engine import IECore
2020

2121

2222
class InferenceEngine:
2323
def __init__(self, net_model_xml_path, device, stride):
2424
self.device = device
2525
self.stride = stride
2626

27-
net_model_bin_path = os.path.splitext(net_model_xml_path)[0] + '.bin'
28-
self.net = IENetwork(model=net_model_xml_path, weights=net_model_bin_path)
27+
self.ie = IECore()
28+
29+
self.net = self.ie.read_network(net_model_xml_path, os.path.splitext(net_model_xml_path)[0] + '.bin')
2930
required_input_key = {'data'}
3031
assert required_input_key == set(self.net.inputs.keys()), \
3132
'Demo supports only topologies with the following input key: {}'.format(', '.join(required_input_key))
3233
required_output_keys = {'features', 'heatmaps', 'pafs'}
3334
assert required_output_keys.issubset(self.net.outputs.keys()), \
3435
'Demo supports only topologies with the following output keys: {}'.format(', '.join(required_output_keys))
3536

36-
self.ie = IECore()
3737
self.exec_net = self.ie.load_network(network=self.net, num_requests=1, device_name=device)
3838

3939
def infer(self, img):

demos/python_demos/image_inpainting_demo/inpainting.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@
1515
import cv2
1616
import numpy as np
1717

18-
from openvino.inference_engine import IENetwork, IECore
1918

2019
class ImageInpainting(object):
2120
def __init__(self, ie, model_path, parts, max_brush_width, max_length, max_vertex, device='CPU'):
22-
model = IENetwork(model=model_path, weights=os.path.splitext(model_path)[0] + '.bin')
21+
model = ie.read_network(model_path, os.path.splitext(model_path)[0] + '.bin')
2322

2423
assert len(model.inputs) == 2, "Expected 2 input blob"
2524
assert len(model.outputs) == 1, "Expected 1 output blobs"

demos/python_demos/image_retrieval_demo/image_retrieval_demo/image_retrieval.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
from image_retrieval_demo.common import from_list, crop_resize
2424

25-
from openvino.inference_engine import IENetwork, IECore # pylint: disable=no-name-in-module
25+
from openvino.inference_engine import IECore # pylint: disable=no-name-in-module
2626

2727

2828
class IEModel(): # pylint: disable=too-few-public-methods
@@ -34,7 +34,7 @@ def __init__(self, model_path, device, cpu_extension):
3434
ie.add_extension(cpu_extension, 'CPU')
3535

3636
path = '.'.join(model_path.split('.')[:-1])
37-
self.net = IENetwork(model=path + '.xml', weights=path + '.bin')
37+
self.net = ie.read_network(path + '.xml', path + '.bin')
3838
self.output_name = list(self.net.outputs.keys())[0]
3939
self.exec_net = ie.load_network(network=self.net, device_name=device)
4040

demos/python_demos/instance_segmentation_demo/instance_segmentation_demo.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
import cv2
2727
import numpy as np
28-
from openvino.inference_engine import IENetwork, IECore
28+
from openvino.inference_engine import IECore
2929

3030
from instance_segmentation_demo.tracker import StaticIOUTracker
3131
from instance_segmentation_demo.visualizer import Visualizer
@@ -121,17 +121,14 @@ def main():
121121
log.basicConfig(format='[ %(levelname)s ] %(message)s', level=log.INFO, stream=sys.stdout)
122122
args = build_argparser().parse_args()
123123

124-
model_xml = args.model
125-
model_bin = os.path.splitext(model_xml)[0] + '.bin'
126-
127124
# Plugin initialization for specified device and load extensions library if specified.
128125
log.info('Creating Inference Engine...')
129126
ie = IECore()
130127
if args.cpu_extension and 'CPU' in args.device:
131128
ie.add_extension(args.cpu_extension, 'CPU')
132129
# Read IR
133-
log.info('Loading network files:\n\t{}\n\t{}'.format(model_xml, model_bin))
134-
net = IENetwork(model=model_xml, weights=model_bin)
130+
log.info('Loading network')
131+
net = ie.read_network(args.model, os.path.splitext(args.model)[0] + '.bin')
135132

136133
if 'CPU' in args.device:
137134
supported_layers = ie.query_network(net, 'CPU')

0 commit comments

Comments
 (0)