29 inputs_array: List[np.ndarray],
32 ) -> Union[List[np.ndarray], Tuple[List[np.ndarray], Dict[str, float]]]:
34 Run a complete inference cycle:
35 - If the session has not been prepared or outputs have not been set, call prepare().
36 - Automatically configure input buffers based on the provided numpy arrays.
37 - Execute the inference session.
38 - Return the output tensors with proper multi-dimensional shapes.
40 This method supports dynamic shape modification:
41 - The input shapes can be adjusted dynamically.
44 inputs_array (list[np.ndarray]): List of numpy arrays representing the input data.
45 measure (bool): If True, measure prepare/io/run latencies (ms).
48 list[np.ndarray]: A list containing the output numpy arrays.
50 (outputs, metrics): Tuple where metrics is a dict with keys
51 'prepare_time_ms', 'io_time_ms', 'run_time_ms'
53 metrics: Dict[str, float] = {}
56 expected_input_size: int = self.
session.input_size()
57 if len(inputs_array) != expected_input_size:
59 f
"Expected {expected_input_size} input(s), but received {len(inputs_array)}."
65 with self.
_time_block(metrics,
'prepare_time_ms', measure):
69 for idx, info
in enumerate(original_infos):
70 input_shape = inputs_array[idx].shape
72 static_dim_changed =
False
74 for j, d
in enumerate(info.dims[:info.rank]):
77 new_dims.append(input_shape[j])
78 elif d == input_shape[j]:
82 static_dim_changed =
True
84 if static_dim_changed:
86 f
"infer() called with input {idx}'s shape={input_shape}, "
87 f
"which differs from model's expected shape={tuple(info.dims)}. "
88 "Ensure this is intended.", UserWarning)
91 fixed_infos.append(info)
96 self.
session.set_prepare_config(
97 prepare_config.ENABLE_INTERNAL_OUTPUT_ALLOC)
102 except Exception
as e:
103 raise OnertError(f
"Session preparation failed: {e}")
from e
107 with self.
_time_block(metrics,
'input_time_ms', measure):
108 self.
set_inputs(expected_input_size, inputs_array)
111 except Exception
as e:
112 raise OnertError(f
"Failed to bind inputs: {e}")
from e
116 with self.
_time_block(metrics,
'run_time_ms', measure):
120 except Exception
as e:
121 raise OnertError(f
"Inference execution failed: {e}")
from e
124 with self.
_time_block(metrics,
'output_time_ms', measure):
128 except Exception
as e:
129 raise OnertError(f
"Failed to bind outputs: {e}")
from e