From be42a24d2376d997a98d10433373af84fa85917b Mon Sep 17 00:00:00 2001 From: Colin Wong Date: Thu, 7 Jul 2022 16:53:09 -0500 Subject: [PATCH] Properly expose `batch_size` from OpenVINO similarly to TensorRT (#8514) Properly expose `batch_size` from OpenVINO Co-authored-by: Glenn Jocher --- models/common.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/models/common.py b/models/common.py index a6488dd85648..61e94296b6d0 100644 --- a/models/common.py +++ b/models/common.py @@ -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')