Skip to content

Commit

Permalink
Properly expose batch_size from OpenVINO similarly to TensorRT (#8514)
Browse files Browse the repository at this point in the history
Properly expose `batch_size` from OpenVINO

Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
  • Loading branch information
democat3457 and glenn-jocher committed Jul 7, 2022
1 parent f17444a commit be42a24
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion models/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,16 @@ def __init__(self, weights='yolov5s.pt', device=torch.device('cpu'), dnn=False,
elif xml: # OpenVINO
LOGGER.info(f'Loading {w} for OpenVINO inference...')
check_requirements(('openvino',)) # requires openvino-dev: https://pypi.org/project/openvino-dev/
from openvino.runtime import Core
from openvino.runtime import Core, Layout, get_batch
ie = Core()
if not Path(w).is_file(): # if not *.xml
w = next(Path(w).glob('*.xml')) # get *.xml file from *_openvino_model dir
network = ie.read_model(model=w, weights=Path(w).with_suffix('.bin'))
if network.get_parameters()[0].get_layout().empty:
network.get_parameters()[0].set_layout(Layout("NCHW"))
batch_dim = get_batch(network)
if batch_dim.is_static:
batch_size = batch_dim.get_length()
executable_network = ie.compile_model(network, device_name="CPU") # device_name="MYRIAD" for Intel NCS2
output_layer = next(iter(executable_network.outputs))
meta = Path(w).with_suffix('.yaml')
Expand Down

0 comments on commit be42a24

Please sign in to comment.