From c6f9ce451e2897351ca746ebfff06d9649677ec4 Mon Sep 17 00:00:00 2001 From: vishal Date: Thu, 19 Sep 2019 15:13:55 -0400 Subject: [PATCH 1/2] Remove response key --- examples/image-classifier/image.py | 3 +-- examples/iris-classifier/handlers/tensorflow.py | 2 +- examples/sentiment-analysis/sentiment.py | 2 +- examples/text-generator/handler.py | 2 +- pkg/workloads/cortex/tf_api/api.py | 6 ++---- 5 files changed, 6 insertions(+), 9 deletions(-) diff --git a/examples/image-classifier/image.py b/examples/image-classifier/image.py index 11b99fc1ed..6187ca53bc 100644 --- a/examples/image-classifier/image.py +++ b/examples/image-classifier/image.py @@ -21,5 +21,4 @@ def pre_inference(sample, metadata): def post_inference(prediction, metadata): - classes = prediction["response"]["classes"] - return labels[np.argmax(classes)] + return labels[np.argmax(prediction["classes"])] diff --git a/examples/iris-classifier/handlers/tensorflow.py b/examples/iris-classifier/handlers/tensorflow.py index 08343aec72..23249f82fd 100644 --- a/examples/iris-classifier/handlers/tensorflow.py +++ b/examples/iris-classifier/handlers/tensorflow.py @@ -2,5 +2,5 @@ def post_inference(prediction, metadata): - predicted_class_id = int(prediction["response"]["class_ids"][0]) + predicted_class_id = int(prediction["class_ids"][0]) return labels[predicted_class_id] diff --git a/examples/sentiment-analysis/sentiment.py b/examples/sentiment-analysis/sentiment.py index da60626673..ca88c7c1dc 100644 --- a/examples/sentiment-analysis/sentiment.py +++ b/examples/sentiment-analysis/sentiment.py @@ -19,4 +19,4 @@ def pre_inference(sample, metadata): def post_inference(prediction, metadata): - return labels[prediction["response"]["labels"][0]] + return labels[prediction["labels"][0]] diff --git a/examples/text-generator/handler.py b/examples/text-generator/handler.py index 5e3321b330..5e1fa98dfd 100644 --- a/examples/text-generator/handler.py +++ b/examples/text-generator/handler.py @@ -9,5 +9,5 @@ def pre_inference(sample, metadata): def post_inference(prediction, metadata): - response = prediction["response"]["sample"] + response = prediction["sample"] return {encoder.decode(response)} diff --git a/pkg/workloads/cortex/tf_api/api.py b/pkg/workloads/cortex/tf_api/api.py index cff2bb543e..bf78f3a4ec 100644 --- a/pkg/workloads/cortex/tf_api/api.py +++ b/pkg/workloads/cortex/tf_api/api.py @@ -161,13 +161,11 @@ def run_get_model_metadata(): def parse_response_proto(response_proto): results_dict = json_format.MessageToDict(response_proto) outputs = results_dict["outputs"] - outputs_simplified = {} - for key in outputs.keys(): + for key in outputs: value_key = DTYPE_TO_VALUE_KEY[outputs[key]["dtype"]] outputs_simplified[key] = outputs[key][value_key] - - return {"response": outputs_simplified} + return outputs_simplified def run_predict(sample, debug=False): From 974c844487f8a8597be7f96042d8892a9601f9fb Mon Sep 17 00:00:00 2001 From: vishal Date: Thu, 19 Sep 2019 16:20:21 -0400 Subject: [PATCH 2/2] Remove response key from docs --- examples/iris-classifier/README.md | 2 +- examples/sentiment-analysis/README.md | 2 +- examples/text-generator/README.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/iris-classifier/README.md b/examples/iris-classifier/README.md index 76f6e821a5..938d85725f 100644 --- a/examples/iris-classifier/README.md +++ b/examples/iris-classifier/README.md @@ -25,7 +25,7 @@ labels = ["iris-setosa", "iris-versicolor", "iris-virginica"] def post_inference(prediction, metadata): - label_index = int(prediction["response"]["class_ids"][0]) + label_index = int(prediction["class_ids"][0]) return labels[label_index] ``` diff --git a/examples/sentiment-analysis/README.md b/examples/sentiment-analysis/README.md index bd93441053..78c3f88aee 100644 --- a/examples/sentiment-analysis/README.md +++ b/examples/sentiment-analysis/README.md @@ -42,7 +42,7 @@ def pre_inference(sample, metadata): def post_inference(prediction, metadata): - return labels[prediction["response"]["labels"][0]] + return labels[prediction["labels"][0]] ``` ## Deploy to AWS diff --git a/examples/text-generator/README.md b/examples/text-generator/README.md index eadd9da6e6..04eb05a76f 100644 --- a/examples/text-generator/README.md +++ b/examples/text-generator/README.md @@ -34,7 +34,7 @@ def pre_inference(sample, metadata): def post_inference(prediction, metadata): - response = prediction["response"]["sample"] + response = prediction["sample"] return {encoder.decode(response)} ```