15
15
"""
16
16
#pylint:disable=no-name-in-module
17
17
#pylint:disable=package-absolute-imports
18
+ import io
18
19
import multiprocessing
19
20
from pathlib import Path
20
21
import re
45
46
46
47
47
48
format_map = {
48
- 'f32' : np .float32 ,
49
- 'i32' : np .int32 ,
50
- 'i64' : np .int64 ,
51
- 'fp16' : np .float16 ,
52
- 'f16' : np .float16 ,
53
- 'i16' : np .int16 ,
54
- 'u16' : np .uint16 ,
55
- 'i8' : np .int8 ,
56
- 'u8' : np .uint8 ,
49
+ 'f32' : np .float32 , 'i32' : np .int32 , 'i64' : np .int64 ,
50
+ 'fp16' : np .float16 , 'f16' : np .float16 , 'i16' : np .int16 , 'u16' : np .uint16 ,
51
+ 'i8' : np .int8 , 'u8' : np .uint8 ,
57
52
'boolean' : np .uint8
58
53
}
59
54
60
55
PRECISION_STR_TO_TYPE = {
61
- 'FP32' : Type .f32 ,
62
- 'FP16' : Type .f16 ,
63
- 'U8' : Type .u8 ,
64
- 'U16' : Type .u16 ,
65
- 'I8' : Type .i8 ,
66
- 'I16' : Type .i16 ,
67
- 'I32' : Type .i32 ,
68
- 'I64' : Type .i64 ,
69
- 'BOOL' : Type .boolean
56
+ 'FP32' : Type .f32 , 'FP16' : Type .f16 , 'U8' : Type .u8 , 'U16' : Type .u16 , 'I8' : Type .i8 , 'I16' : Type .i16 ,
57
+ 'I32' : Type .i32 , 'I64' : Type .i64 , 'BOOL' : Type .boolean
70
58
}
71
59
72
60
@@ -461,8 +449,7 @@ def _prepare_multi_device(self, log=True):
461
449
if 'num_requests' in self .config :
462
450
warning (
463
451
"number requests already provided in device name specification. "
464
- "'num_requests' option will be ignored."
465
- )
452
+ "'num_requests' option will be ignored." )
466
453
elif 'num_requests' in self .config and self .config ['num_requests' ] != 'AUTO' :
467
454
num_per_device_requests = get_or_parse_value (self .config ['num_request' ], casting_type = int )
468
455
else :
@@ -502,15 +489,15 @@ def _log_versions(self):
502
489
for device_name , device_version in versions .items ():
503
490
print_info (" {device_name} - {descr}: {maj}.{min}.{num}" .format (
504
491
device_name = device_name , descr = device_version .description , maj = device_version .major ,
505
- min = device_version .minor , num = device_version .build_number
506
- ))
492
+ min = device_version .minor , num = device_version .build_number ))
507
493
508
494
def _create_network (self , input_shapes = None ):
509
495
model_path = Path (self ._model )
510
496
compiled_model = model_path .suffix == '.blob'
511
497
if compiled_model :
512
498
self .network = None
513
- self .exec_network = self .ie_core .import_model (str (self ._model ), self ._device )
499
+ with open (str (self ._model ), 'rb' ) as f : #pylint:disable=unspecified-encoding
500
+ self .exec_network = self .ie_core .import_model (io .BytesIO (f ), self ._device )
514
501
self .original_outputs = self .exec_network .outputs
515
502
model_batch = self ._get_model_batch_size ()
516
503
self ._batch = model_batch if model_batch is not None else 1
@@ -560,26 +547,29 @@ def _set_batch_size(self, batch_size):
560
547
if layer_name in self .const_inputs :
561
548
input_shapes [layer_name ] = parse_partial_shape (input_node .get_node ().partial_shape )
562
549
else :
563
- layer_shape = parse_partial_shape (input_node .get_node ().partial_shape )
564
- layout = self .inputs [layer_name ].layout
565
- if '...' in str (layout ):
566
- layout = self .get_layout_from_config (layer_name )
567
- else :
568
- layout = str (layout ).replace ('[' , '' ).replace (']' , '' ).replace (',' , '' )
550
+ layer_shape = list (parse_partial_shape (input_node .get_node ().partial_shape ))
551
+ layout = self ._process_layout (self .inputs [layer_name ].layout , layer_name )
569
552
batch_pos = layout .find ('N' )
570
553
if batch_pos != - 1 :
571
554
layer_shape [batch_pos ] = batch_size
572
555
input_shapes [layer_name ] = layer_shape
573
556
self ._reshape_input (input_shapes , batch_size == - 1 )
574
557
self ._batch = batch_size
575
558
559
+ def _process_layout (self , ov_layout , layer_name ):
560
+ if '...' in str (ov_layout ) or ov_layout is None :
561
+ ov_layout = self .get_layout_from_config (layer_name )
562
+ else :
563
+ ov_layout = str (ov_layout ).replace ('[' , '' ).replace (']' , '' ).replace (',' , '' )
564
+ return ov_layout
565
+
576
566
def _get_model_batch_size (self ):
577
567
input_nodes = self .network .inputs if self .network else self .exec_network .inputs
578
568
input_info = input_nodes [0 ]
579
- if '...' in str ( input_info . get_node (). layout ):
580
- layout = self .get_layout_from_config ( input_info .get_node ().friendly_name )
581
- else :
582
- layout = str ( input_info . get_node (). layout ). replace ( '[' , '' ). replace ( ']' , '' ). replace ( ',' , '' )
569
+ layout = (
570
+ self ._process_layout ( input_info . get_node (). layout , input_info .get_node ().friendly_name )
571
+ or self . default_layout
572
+ )
583
573
batch_pos = layout .find ('N' )
584
574
if batch_pos != - 1 :
585
575
return parse_partial_shape (input_info .partial_shape )[batch_pos ]
@@ -599,7 +589,6 @@ def load_network(self, network=None, log=False, preprocessing=None):
599
589
self .dyn_input_layers , self ._partial_shapes = self .get_dynamic_inputs (self .network )
600
590
self .input_to_tensor_name = self .get_input_tensor_name_mapping (self .network )
601
591
self .input_to_index = {inp .get_node ().friendly_name : idx for idx , inp in enumerate (self .network .inputs )}
602
-
603
592
if not self ._postpone_input_configuration :
604
593
self ._set_precision ()
605
594
self ._set_input_shape ()
@@ -674,7 +663,7 @@ def dyn_batch_only(self):
674
663
if num_undef > 1 :
675
664
return False
676
665
layout = self .inputs [input_name ].layout
677
- if '...' in str (layout ):
666
+ if '...' in str (layout ) or layout is None :
678
667
layout = self .get_layout_from_config (input_name )
679
668
else :
680
669
layout = str (layout ).replace ('[' , '' ).replace (']' , '' ).replace (',' , '' )
@@ -715,6 +704,8 @@ def read_network(self, model, weights):
715
704
network = self .ie_core .read_model (model = str (model ), weights = str (weights ))
716
705
else :
717
706
network = self .ie_core .read_model (model = str (model ))
707
+ self .input_to_tensor_name = self .get_input_tensor_name_mapping (network )
708
+ self .input_to_index = {inp .get_node ().friendly_name : idx for idx , inp in enumerate (network .inputs )}
718
709
return network
719
710
720
711
def inputs_info_for_meta (self , inputs = None ):
@@ -851,8 +842,7 @@ def _set_precision(self):
851
842
if 'precision' in input_config :
852
843
if self .network :
853
844
self .inputs [input_config ['name' ]].set_element_type (
854
- PRECISION_STR_TO_TYPE [input_config ['precision' ].upper ()]
855
- )
845
+ PRECISION_STR_TO_TYPE [input_config ['precision' ].upper ()])
856
846
857
847
def _set_input_shape (self ):
858
848
if not self .network :
0 commit comments