Skip to content
Open
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
12 changes: 6 additions & 6 deletions modules/inference_engine_openvino.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import os

import numpy as np
from openvino.inference_engine import IENetwork, IECore
from openvino.inference_engine import IECore


class InferenceEngineOpenVINO:
def __init__(self, net_model_xml_path, device):
self.device = device
self.ie = IECore()

net_model_bin_path = os.path.splitext(net_model_xml_path)[0] + '.bin'
self.net = IENetwork(model=net_model_xml_path, weights=net_model_bin_path)
self.net = self.ie.read_network(model=net_model_xml_path, weights=net_model_bin_path)
required_input_key = {'data'}
assert required_input_key == set(self.net.inputs.keys()), \
assert required_input_key == set(self.net.input_info.keys()), \
'Demo supports only topologies with the following input key: {}'.format(', '.join(required_input_key))
required_output_keys = {'features', 'heatmaps', 'pafs'}
assert required_output_keys.issubset(self.net.outputs.keys()), \
'Demo supports only topologies with the following output keys: {}'.format(', '.join(required_output_keys))

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

def infer(self, img):
input_layer = next(iter(self.net.inputs))
n, c, h, w = self.net.inputs[input_layer].shape
input_layer = next(iter(self.net.input_info))
n, c, h, w = self.net.input_info[input_layer].input_data.shape
if h != img.shape[0] or w != img.shape[1]:
self.net.reshape({input_layer: (n, c, img.shape[0], img.shape[1])})
self.exec_net = self.ie.load_network(network=self.net, num_requests=1, device_name=self.device)
Expand Down