democat glenn-jocher commited on
Commit
be42a24
·
unverified ·
1 Parent(s): f17444a

Properly expose `batch_size` from OpenVINO similarly to TensorRT (#8514)

Browse files

Properly expose `batch_size` from OpenVINO

Co-authored-by: Glenn Jocher <[email protected]>

Files changed (1) hide show
  1. models/common.py +6 -1
models/common.py CHANGED
@@ -361,11 +361,16 @@ class DetectMultiBackend(nn.Module):
361
  elif xml: # OpenVINO
362
  LOGGER.info(f'Loading {w} for OpenVINO inference...')
363
  check_requirements(('openvino',)) # requires openvino-dev: https://pypi.org/project/openvino-dev/
364
- from openvino.runtime import Core
365
  ie = Core()
366
  if not Path(w).is_file(): # if not *.xml
367
  w = next(Path(w).glob('*.xml')) # get *.xml file from *_openvino_model dir
368
  network = ie.read_model(model=w, weights=Path(w).with_suffix('.bin'))
 
 
 
 
 
369
  executable_network = ie.compile_model(network, device_name="CPU") # device_name="MYRIAD" for Intel NCS2
370
  output_layer = next(iter(executable_network.outputs))
371
  meta = Path(w).with_suffix('.yaml')
 
361
  elif xml: # OpenVINO
362
  LOGGER.info(f'Loading {w} for OpenVINO inference...')
363
  check_requirements(('openvino',)) # requires openvino-dev: https://pypi.org/project/openvino-dev/
364
+ from openvino.runtime import Core, Layout, get_batch
365
  ie = Core()
366
  if not Path(w).is_file(): # if not *.xml
367
  w = next(Path(w).glob('*.xml')) # get *.xml file from *_openvino_model dir
368
  network = ie.read_model(model=w, weights=Path(w).with_suffix('.bin'))
369
+ if network.get_parameters()[0].get_layout().empty:
370
+ network.get_parameters()[0].set_layout(Layout("NCHW"))
371
+ batch_dim = get_batch(network)
372
+ if batch_dim.is_static:
373
+ batch_size = batch_dim.get_length()
374
  executable_network = ie.compile_model(network, device_name="CPU") # device_name="MYRIAD" for Intel NCS2
375
  output_layer = next(iter(executable_network.outputs))
376
  meta = Path(w).with_suffix('.yaml')