Skip to content

Pass onnx model output directly to post_inference request handler #476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 19, 2019
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/pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ def pre_inference(sample, metadata):


def post_inference(prediction, metadata):
predicted_class_id = int(np.argmax(prediction[0][0]))
predicted_class_id = int(np.argmax(prediction[0].squeeze()))
return labels[predicted_class_id]
14 changes: 4 additions & 10 deletions pkg/workloads/cortex/onnx_serve/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,19 +192,13 @@ def predict(app_name, api_name):
) from e

inference_input = convert_to_onnx_input(prepared_sample, input_metadata)
model_outputs = sess.run([], inference_input)
result = []
for model_output in model_outputs:
if type(model_output) is np.ndarray:
result.append(model_output.tolist())
else:
result.append(model_output)

debug_obj("inference", result, debug)
model_output = sess.run([], inference_input)

debug_obj("inference", model_output, debug)
result = model_output
if request_handler is not None and util.has_function(request_handler, "post_inference"):
try:
result = request_handler.post_inference(result, output_metadata)
result = request_handler.post_inference(model_output, output_metadata)
except Exception as e:
raise UserRuntimeException(
api["request_handler"], "post_inference request handler", str(e)
Expand Down