|
|
@ -137,17 +137,17 @@ class AutoBackend(nn.Module):
|
|
|
|
LOGGER.info(f'Loading {w} for OpenVINO inference...')
|
|
|
|
LOGGER.info(f'Loading {w} for OpenVINO inference...')
|
|
|
|
check_requirements('openvino') # requires openvino-dev: https://pypi.org/project/openvino-dev/
|
|
|
|
check_requirements('openvino') # requires openvino-dev: https://pypi.org/project/openvino-dev/
|
|
|
|
from openvino.runtime import Core, Layout, get_batch # noqa
|
|
|
|
from openvino.runtime import Core, Layout, get_batch # noqa
|
|
|
|
ie = Core()
|
|
|
|
core = Core()
|
|
|
|
w = Path(w)
|
|
|
|
w = Path(w)
|
|
|
|
if not w.is_file(): # if not *.xml
|
|
|
|
if not w.is_file(): # if not *.xml
|
|
|
|
w = next(w.glob('*.xml')) # get *.xml file from *_openvino_model dir
|
|
|
|
w = next(w.glob('*.xml')) # get *.xml file from *_openvino_model dir
|
|
|
|
network = ie.read_model(model=str(w), weights=w.with_suffix('.bin'))
|
|
|
|
ov_model = core.read_model(model=str(w), weights=w.with_suffix('.bin'))
|
|
|
|
if network.get_parameters()[0].get_layout().empty:
|
|
|
|
if ov_model.get_parameters()[0].get_layout().empty:
|
|
|
|
network.get_parameters()[0].set_layout(Layout('NCHW'))
|
|
|
|
ov_model.get_parameters()[0].set_layout(Layout('NCHW'))
|
|
|
|
batch_dim = get_batch(network)
|
|
|
|
batch_dim = get_batch(ov_model)
|
|
|
|
if batch_dim.is_static:
|
|
|
|
if batch_dim.is_static:
|
|
|
|
batch_size = batch_dim.get_length()
|
|
|
|
batch_size = batch_dim.get_length()
|
|
|
|
executable_network = ie.compile_model(network, device_name='CPU') # device_name="MYRIAD" for NCS2
|
|
|
|
ov_compiled_model = core.compile_model(ov_model, device_name='AUTO') # AUTO selects best available device
|
|
|
|
metadata = w.parent / 'metadata.yaml'
|
|
|
|
metadata = w.parent / 'metadata.yaml'
|
|
|
|
elif engine: # TensorRT
|
|
|
|
elif engine: # TensorRT
|
|
|
|
LOGGER.info(f'Loading {w} for TensorRT inference...')
|
|
|
|
LOGGER.info(f'Loading {w} for TensorRT inference...')
|
|
|
@ -339,7 +339,7 @@ class AutoBackend(nn.Module):
|
|
|
|
y = self.session.run(self.output_names, {self.session.get_inputs()[0].name: im})
|
|
|
|
y = self.session.run(self.output_names, {self.session.get_inputs()[0].name: im})
|
|
|
|
elif self.xml: # OpenVINO
|
|
|
|
elif self.xml: # OpenVINO
|
|
|
|
im = im.cpu().numpy() # FP32
|
|
|
|
im = im.cpu().numpy() # FP32
|
|
|
|
y = list(self.executable_network([im]).values())
|
|
|
|
y = list(self.ov_compiled_model([im]).values())
|
|
|
|
elif self.engine: # TensorRT
|
|
|
|
elif self.engine: # TensorRT
|
|
|
|
if self.dynamic and im.shape != self.bindings['images'].shape:
|
|
|
|
if self.dynamic and im.shape != self.bindings['images'].shape:
|
|
|
|
i = self.model.get_binding_index('images')
|
|
|
|
i = self.model.get_binding_index('images')
|
|
|
|