in python/dlr/dlr_model.py [0:0]
def run(self, input_values):
"""
Run inference with given input(s)
Parameters
----------
input_values : a single :py:class:`numpy.ndarray` or a dictionary
For decision tree models, provide a single :py:class:`numpy.ndarray`
to indicate a single input, as decision trees always accept only one
input.
For deep learning models, provide a dictionary where keys are input
names (of type :py:class:`str`) and values are input tensors (of type
:py:class:`numpy.ndarray`). Deep learning models allow more than one
input, so each input must have a unique name.
Returns
-------
out : :py:class:`numpy.ndarray`
Prediction result
"""
out = []
# set input(s)
if isinstance(input_values, (np.ndarray, np.generic)):
# Treelite model or single input tvm/treelite model.
# Treelite has a dummy input name 'data'.
if self.input_names:
self._set_input(self.input_names[0], input_values)
elif isinstance(input_values, dict):
# TVM model
for key, value in input_values.items():
if (self.input_names and key not in self.input_names) and \
(self.weight_names and key not in self.weight_names):
raise ValueError("%s is not a valid input name." % key)
self._set_input(key, value)
else:
raise ValueError("input_values must be of type dict (tvm model) " +
"or a np.ndarray/generic (representing treelite models)")
# run model
self._run()
# get output
for i in range(self.num_outputs):
ith_out = self._get_output(i)
out.append(ith_out)
return out