Skip to content

Commit

Permalink
Replace openvino-dev with OpenVINO Runtime inference (ultralytics#7843
Browse files Browse the repository at this point in the history
)

* Uses OpenVINO runtime instead of openvino-dev

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* export with openvino package

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Revert export.py

* Update common.py

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
  • Loading branch information
3 people authored and tdhooghe committed Jun 10, 2022
1 parent 7dbd0fa commit 3fc85f7
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions models/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,12 @@ def __init__(self, weights='yolov5s.pt', device=torch.device('cpu'), dnn=False,
if 'stride' in meta:
stride, names = int(meta['stride']), eval(meta['names'])
elif xml: # OpenVINO

LOGGER.info(f'Loading {w} for OpenVINO inference...')
check_requirements(('openvino-dev',)) # requires openvino-dev: https://pypi.org/project/openvino-dev/
import openvino.inference_engine as ie
from openvino.runtime import Core

ie = Core()
if not Path(w).is_file(): # if not *.xml
w = next(Path(w).glob('*.xml')) # get *.xml file from *_openvino_model dir

Expand All @@ -377,6 +377,9 @@ def __init__(self, weights='yolov5s.pt', device=torch.device('cpu'), dnn=False,
dev = "AUTO" if 'int8' in str(w) else "GPU"#
executable_network = core.load_network(network, device_name=dev, num_requests=0)
print(executable_network.infer)
network = ie.read_model(model=w, weights=Path(w).with_suffix('.bin'))
executable_network = ie.compile_model(model=network, device_name="CPU")
self.output_layer = next(iter(executable_network.outputs))
elif engine: # TensorRT
LOGGER.info(f'Loading {w} for TensorRT inference...')
import tensorrt as trt # https://developer.nvidia.com/nvidia-tensorrt-download
Expand Down Expand Up @@ -467,12 +470,14 @@ def forward(self, im, augment=False, visualize=False, val=False):
# request.infer(inputs={self.input_layer.any_name: im})
# y = request.get_output_tensor(self.output_layer.index).data

desc = self.ie.TensorDesc(precision='FP32', dims=im.shape, layout='NCHW') # Tensor Description,
# precision regarding memory precision
request = self.executable_network.requests[0] # inference request
request.set_blob(blob_name='images', blob=self.ie.Blob(desc, im)) # name=next(iter(request.input_blobs))
request.infer()
# desc = self.ie.TensorDesc(precision='FP32', dims=im.shape, layout='NCHW') # Tensor Description,
# # precision regarding memory precision
# request = self.executable_network.requests[0] # inference request
# request.set_blob(blob_name='images', blob=self.ie.Blob(desc, im)) # name=next(iter(request.input_blobs))
# request.infer()
y = request.output_blobs['output'].buffer # name=next(iter(request.output_blobs)); shape (1, 25200, 85)
im = im.cpu().numpy() # FP32
y = self.executable_network([im])[self.output_layer]
elif self.engine: # TensorRT
assert im.shape == self.bindings['images'].shape, (im.shape, self.bindings['images'].shape)
self.binding_addrs['images'] = int(im.data_ptr())
Expand Down

0 comments on commit 3fc85f7

Please sign in to comment.