43
43
)
44
44
from .launcher import Launcher
45
45
from ..logging import print_info
46
- from .input_feeder import PRECISION_TO_DTYPE
47
46
48
47
49
48
format_map = {
@@ -193,11 +192,14 @@ def predict(self, inputs, metadata=None, **kwargs):
193
192
results = []
194
193
for infer_inputs in inputs :
195
194
if self ._do_reshape :
196
- input_shapes = {layer_name : data .shape for layer_name , data in infer_inputs .items ()}
195
+ input_shapes = {
196
+ layer_name : data .shape for layer_name , data in infer_inputs .items ()
197
+ }
197
198
self ._reshape_input (input_shapes )
198
199
if self .infer_request is None :
199
200
self .infer_request = self .exec_network .create_infer_request ()
200
- outputs = self .infer_request .infer (inputs = infer_inputs )
201
+ feed_dict = {self .input_to_tensor_name [layer_name ]: data for layer_name , data in infer_inputs .items ()}
202
+ outputs = self .infer_request .infer (inputs = feed_dict )
201
203
results .append ({
202
204
out_node .get_node ().friendly_name : out_res
203
205
for out_node , out_res in zip (self .exec_network .outputs , outputs )
@@ -214,10 +216,13 @@ def predict(self, inputs, metadata=None, **kwargs):
214
216
215
217
def _predict_sequential (self , inputs , metadata = None , ** kwargs ):
216
218
lstm_inputs_feed = self ._fill_lstm_inputs ()
219
+ if not self .infer_request :
220
+ self .infer_request = self .exec_network .create_infer_request ()
217
221
results = []
218
222
for feed_dict in inputs :
219
223
feed_dict .update (lstm_inputs_feed )
220
- out_tensors = self .exec_network .infer_new_request (feed_dict )
224
+ infer_inputs = {self .input_to_tensor_name [layer_name ]: data for layer_name , data in feed_dict .items ()}
225
+ out_tensors = self .infer_request .infer (infer_inputs )
221
226
output_result = {
222
227
out_node .get_node ().friendly_name : out_tensor
223
228
for out_node , out_tensor in zip (self .exec_network .outputs , out_tensors )
@@ -236,9 +241,10 @@ def _predict_sequential(self, inputs, metadata=None, **kwargs):
236
241
237
242
def predict_async (self , ir , inputs , metadata = None , context = None , ** kwargs ):
238
243
infer_inputs = inputs [0 ]
244
+ feed_dict = {self .input_to_tensor_name [name ]: data for name , data in infer_inputs .items ()}
239
245
if metadata is not None :
240
246
self ._fill_meta (metadata )
241
- ir .infer (infer_inputs , metadata , context )
247
+ ir .infer (feed_dict , metadata , context )
242
248
243
249
def _fill_meta (self , metadata ):
244
250
for meta_ in metadata :
@@ -319,7 +325,7 @@ def _reshape_input(self, shapes, make_dynamic=False):
319
325
del self .exec_network
320
326
if self .infer_request is not None :
321
327
self .infer_request = None
322
- self .network .reshape ({k : PartialShape (shape ) for k , shape in shapes .items ()})
328
+ self .network .reshape ({self . input_to_tensor_name [ k ] : PartialShape (shape ) for k , shape in shapes .items ()})
323
329
self .dyn_input_layers , self ._partial_shapes = self .get_dynamic_inputs (self .network )
324
330
if self .dyn_input_layers and make_dynamic :
325
331
return
@@ -523,6 +529,7 @@ def load_network(self, network=None, log=False, preprocessing=None):
523
529
self .network = network
524
530
if self .network is not None :
525
531
self .dyn_input_layers , self ._partial_shapes = self .get_dynamic_inputs (self .network )
532
+ self .input_to_tensor_name = self .get_input_tensor_name_mapping (self .network )
526
533
527
534
if not self ._postpone_input_configuration :
528
535
self ._set_precision ()
@@ -572,6 +579,13 @@ def is_dynamic(data_info):
572
579
573
580
return inputs_with_undefined_shapes , partial_shapes
574
581
582
+ @staticmethod
583
+ def get_input_tensor_name_mapping (network ):
584
+ inputs_mapping = {}
585
+ for input_node in network .inputs :
586
+ inputs_mapping [input_node .get_node ().friendly_name ] = input_node .get_tensor ().get_any_name ()
587
+ return inputs_mapping
588
+
575
589
@property
576
590
def dyn_batch_only (self ):
577
591
if not self .dyn_input_layers :
@@ -772,9 +786,11 @@ def _configure_lstm_inputs(self):
772
786
def _fill_lstm_inputs (self , infer_outputs = None ):
773
787
feed_dict = {}
774
788
for lstm_var , output_layer in self ._lstm_inputs .items ():
775
- layer_shape = self .inputs [lstm_var ].shape
789
+ layer_shape = parse_partial_shape (self .inputs [lstm_var ].partial_shape )
790
+ if infer_outputs and output_layer not in infer_outputs :
791
+ raise 'Output node with name {} not found' .format (output_layer )
776
792
input_data = infer_outputs [output_layer ].reshape (layer_shape ) if infer_outputs else np .zeros (
777
- layer_shape , dtype = PRECISION_TO_DTYPE [self .inputs [lstm_var ].precision ]
793
+ layer_shape , dtype = format_map [self .inputs [lstm_var ].element_type . get_type_name () ]
778
794
)
779
795
feed_dict [lstm_var ] = input_data
780
796
return feed_dict
@@ -856,10 +872,11 @@ def prepare_data_for_request(self,
856
872
inputs , batch_meta , batch_id , batch_input_ids ,
857
873
batch_annotation , batch_identifiers ):
858
874
infer_inputs = inputs [0 ]
875
+ feed_dict = {self .input_to_tensor_name [name ]: data for name , data in infer_inputs .items ()}
859
876
if batch_meta is not None :
860
877
self ._fill_meta (batch_meta )
861
878
context = (batch_id , batch_input_ids , batch_annotation , batch_identifiers , batch_meta )
862
- return infer_inputs , context
879
+ return feed_dict , context
863
880
864
881
def get_result_from_request (self , request ):
865
882
return [{
0 commit comments