101 Set the input tensors for the session.
104 size (int): Number of input tensors.
105 inputs_array (list): List of numpy arrays for the input data.
108 ValueError: If session uninitialized.
109 OnertError: If any C-API call fails.
113 "Session is not initialized with a model. Please compile with a model before setting inputs."
117 for i
in range(size):
119 input_tensorinfo = self.
session.input_tensorinfo(i)
122 except Exception
as e:
123 raise OnertError(f
"Failed to get input tensorinfo #{i}: {e}")
from e
125 if len(inputs_array) > i:
126 input_array = np.array(inputs_array[i], dtype=input_tensorinfo.dtype)
129 f
"Model's input size is {size}, but given inputs_array size is {len(inputs_array)}.\n{i}-th index input is replaced by an array filled with 0."
131 input_array = np.zeros((
num_elems(input_tensorinfo)),
132 dtype=input_tensorinfo.dtype)
135 if input_array.shape != tuple(input_tensorinfo.dims):
138 input_tensorinfo.rank = len(input_array)
139 input_tensorinfo.dims = list(input_array.shape)
140 self.
session.set_input_tensorinfo(i, input_tensorinfo)
141 except Exception
as e:
142 raise OnertError(f
"Failed to set input tensor info #{i}: {e}")
from e
145 self.
session.set_input(i, input_array)
148 except Exception
as e:
149 raise OnertError(f
"Failed to set input #{i}: {e}")
from e
151 self.
inputs.append(input_array)