in source/neuropod/backends/python_bridge/_neuropod_native_bootstrap/executor.py [0:0]
def forward(self, inputs):
"""
Run inference using the specifed inputs.
:param inputs: A dict mapping input names to values. This must match the input
spec in the neuropod config for the loaded model.
Ex: {'x1': np.array([5]), 'x2': np.array([6])}
*Note:* all the keys in this dict must be strings and all the
values must be numpy arrays
:returns: A dict mapping output names to values. All the keys
in this dict are strings and all the values are numpy arrays.
"""
# Convert bytes to unicode
for k, v in inputs.items():
if v.dtype.type == np.bytes_:
try:
inputs[k] = np.char.decode(v, encoding="UTF-8")
except UnicodeDecodeError:
raise ValueError("Error in UTF-8 decoding: {}".format(v))
out = self.model(**inputs)
# Make sure everything is a numpy array
for key, value in out.items():
if not isinstance(value, np.ndarray):
raise RuntimeError(
"All outputs must be numpy arrays! Output `{}` was of type `{}`".format(
key, type(value)
)
)
# Convert unicode to bytes
for k, v in out.items():
if v.dtype.type == np.unicode_:
out[k] = np.char.encode(v, encoding="UTF-8")
return out