|
1 | 1 | #!/usr/bin/env python3
|
2 | 2 | """
|
3 |
| - Copyright (c) 2018-2020 Intel Corporation |
| 3 | + Copyright (c) 2018-2021 Intel Corporation |
4 | 4 |
|
5 | 5 | Licensed under the Apache License, Version 2.0 (the "License");
|
6 | 6 | you may not use this file except in compliance with the License.
|
|
15 | 15 | limitations under the License.
|
16 | 16 | """
|
17 | 17 |
|
18 |
| -from openvino.inference_engine import IECore, get_version |
| 18 | +from openvino.runtime import Core, get_version |
19 | 19 | import cv2 as cv
|
20 | 20 | import numpy as np
|
21 | 21 | import logging as log
|
@@ -60,33 +60,28 @@ def build_arg():
|
60 | 60 | help="Optional. List of monitors to show initially.")
|
61 | 61 | return parser
|
62 | 62 |
|
63 |
| - |
64 |
| -if __name__ == '__main__': |
65 |
| - args = build_arg().parse_args() |
66 |
| - |
| 63 | +def main(args): |
67 | 64 | cap = open_images_capture(args.input, args.loop)
|
68 | 65 |
|
69 | 66 | log.info('OpenVINO Inference Engine')
|
70 | 67 | log.info('\tbuild: {}'.format(get_version()))
|
71 |
| - ie = IECore() |
| 68 | + core = Core() |
72 | 69 |
|
73 | 70 | log.info('Reading model {}'.format(args.model))
|
74 |
| - load_net = ie.read_network(args.model, args.model.with_suffix(".bin")) |
75 |
| - load_net.batch_size = 1 |
| 71 | + model = core.read_model(args.model, args.model.with_suffix(".bin")) |
76 | 72 |
|
77 |
| - input_blob = next(iter(load_net.input_info)) |
78 |
| - input_shape = load_net.input_info[input_blob].input_data.shape |
| 73 | + input_tensor_name = 'data_l' |
| 74 | + input_shape = model.input(input_tensor_name).shape |
79 | 75 | assert input_shape[1] == 1, "Expected model input shape with 1 channel"
|
80 | 76 |
|
81 | 77 | inputs = {}
|
82 |
| - for input_name in load_net.input_info: |
83 |
| - inputs[input_name] = np.zeros(load_net.input_info[input_name].input_data.shape) |
| 78 | + for input in model.inputs: |
| 79 | + inputs[input.get_any_name()] = np.zeros(input.shape) |
84 | 80 |
|
85 |
| - assert len(load_net.outputs) == 1, "Expected number of outputs is equal 1" |
86 |
| - output_blob = next(iter(load_net.outputs)) |
87 |
| - output_shape = load_net.outputs[output_blob].shape |
| 81 | + assert len(model.outputs) == 1, "Expected number of outputs is equal 1" |
88 | 82 |
|
89 |
| - exec_net = ie.load_network(network=load_net, device_name=args.device) |
| 83 | + compiled_model = core.compile_model(model, device_name=args.device) |
| 84 | + infer_request = compiled_model.create_infer_request() |
90 | 85 | log.info('The model {} is loaded to {}'.format(args.model, args.device))
|
91 | 86 |
|
92 | 87 | _, _, h_in, w_in = input_shape
|
@@ -118,11 +113,12 @@ def build_arg():
|
118 | 113 | img_rgb = frame.astype(np.float32) / 255
|
119 | 114 | img_lab = cv.cvtColor(img_rgb, cv.COLOR_RGB2Lab)
|
120 | 115 | img_l_rs = cv.resize(img_lab.copy(), (w_in, h_in))[:, :, 0]
|
121 |
| - inputs[input_blob] = img_l_rs |
122 | 116 |
|
123 |
| - res = exec_net.infer(inputs=inputs) |
| 117 | + inputs[input_tensor_name] = np.expand_dims(img_l_rs, axis=[0, 1]) |
124 | 118 |
|
125 |
| - update_res = np.squeeze(res[output_blob]) |
| 119 | + res = next(iter(infer_request.infer(inputs).values())) |
| 120 | + |
| 121 | + update_res = np.squeeze(res) |
126 | 122 |
|
127 | 123 | out = update_res.transpose((1, 2, 0))
|
128 | 124 | out = cv.resize(out, (w_orig, h_orig))
|
@@ -166,3 +162,7 @@ def build_arg():
|
166 | 162 | metrics.log_total()
|
167 | 163 | for rep in presenter.reportMeans():
|
168 | 164 | log.info(rep)
|
| 165 | + |
| 166 | +if __name__ == "__main__": |
| 167 | + args = build_arg().parse_args() |
| 168 | + sys.exit(main(args) or 0) |
0 commit comments