Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/iris-classifier/handlers/sklearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def pre_inference(sample, metadata):
sample["petal_width"],
]
)
return ((x - scalars["mean"]) / scalars["stddev"]).astype(np.float32)
return (x - scalars["mean"]) / scalars["stddev"]


def post_inference(prediction, metadata):
Expand Down
14 changes: 11 additions & 3 deletions pkg/workloads/cortex/onnx_serve/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,18 @@ def transform_to_numpy(input_pyobj, input_metadata):
if dim is None:
target_shape[idx] = 1

if type(input_pyobj) is not np.ndarray:
np_arr = np.array(input_pyobj, dtype=target_dtype)
else:
if type(input_pyobj) is np.ndarray:
np_arr = input_pyobj
if np.issubdtype(np_arr.dtype, np.number) == np.issubdtype(target_dtype, np.number):
if str(np_arr.dtype) != target_dtype:
np_arr = np_arr.astype(target_dtype)
else:
raise ValueError(
"expected dtype '{}' but found '{}'".format(target_dtype, np_arr.dtype)
)
else:
np_arr = np.array(input_pyobj, dtype=target_dtype)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you drop the astype() in the sklearn handler and tolist() in the imagenet handler, and confirm they work?

np_arr = np_arr.reshape(target_shape)
return np_arr
except Exception as e:
Expand Down