diff --git a/cli/cmd/get.go b/cli/cmd/get.go index 2149a39635..1f04cd778c 100644 --- a/cli/cmd/get.go +++ b/cli/cmd/get.go @@ -490,7 +490,7 @@ func describeAPI(name string, resourcesRes *schema.GetResourcesResponse, flagVer apiEndpoint := urls.Join(resourcesRes.APIsBaseURL, anyAPIStatus.Path) out := "\nURL: " + apiEndpoint + "\n" - out += fmt.Sprintf("cURL: curl -k -X POST -H \"Content-Type: application/json\" %s -d @\n", apiEndpoint) + out += fmt.Sprintf("cURL: curl -k -X POST -H \"Content-Type: application/json\" %s -d @samples.json\n", apiEndpoint) out += "\n" out += fmt.Sprintf("Status: %s\n", groupStatus.Message()) out += fmt.Sprintf("Available replicas: %s\n", s.Int32(groupStatus.Available())) diff --git a/docs/apis/packaging-models.md b/docs/apis/packaging-models.md index 8c5e3c738d..15ae195135 100644 --- a/docs/apis/packaging-models.md +++ b/docs/apis/packaging-models.md @@ -47,10 +47,10 @@ with open("sklearn.onnx", "wb") as f: Here are examples of converting models from some of the common ML frameworks to ONNX: -* [PyTorch](https://github.com/cortexlabs/cortex/blob/master/examples/iris/pytorch/model.py) -* [Sklearn](https://github.com/cortexlabs/cortex/blob/master/examples/iris/sklearn/model.py) -* [XGBoost](https://github.com/cortexlabs/cortex/blob/master/examples/iris/xgboost/model.py) -* [Keras](https://github.com/cortexlabs/cortex/blob/master/examples/iris/keras/model.py) +* [PyTorch](https://github.com/cortexlabs/cortex/blob/master/examples/iris/models/pytorch_model.py) +* [Sklearn](https://github.com/cortexlabs/cortex/blob/master/examples/iris/models/sklearn_model.py) +* [XGBoost](https://github.com/cortexlabs/cortex/blob/master/examples/iris/models/xgboost_model.py) +* [Keras](https://github.com/cortexlabs/cortex/blob/master/examples/iris/models/keras_model.py) Upload your trained model in ONNX format to Amazon S3: diff --git a/examples/iris/cortex.yaml b/examples/iris/cortex.yaml index c61a4c794c..db0f730f58 100644 --- a/examples/iris/cortex.yaml +++ b/examples/iris/cortex.yaml @@ -8,19 +8,19 @@ - kind: api name: pytorch model: s3://cortex-examples/iris/pytorch.onnx - request_handler: pytorch/handler.py + request_handler: handlers/pytorch.py - kind: api name: xgboost model: s3://cortex-examples/iris/xgboost.onnx - request_handler: xgboost/handler.py + request_handler: handlers/xgboost.py - kind: api name: sklearn model: s3://cortex-examples/iris/sklearn.onnx - request_handler: sklearn/handler.py + request_handler: handlers/sklearn.py - kind: api name: keras model: s3://cortex-examples/iris/keras.onnx - request_handler: keras/handler.py + request_handler: handlers/keras.py diff --git a/examples/iris/keras/handler.py b/examples/iris/handlers/keras.py similarity index 61% rename from examples/iris/keras/handler.py rename to examples/iris/handlers/keras.py index 8c7217f8ca..bbd90d001b 100644 --- a/examples/iris/keras/handler.py +++ b/examples/iris/handlers/keras.py @@ -3,6 +3,17 @@ iris_labels = ["Iris-setosa", "Iris-versicolor", "Iris-virginica"] +def pre_inference(sample, metadata): + return { + metadata[0].name: [ + sample["sepal_length"], + sample["sepal_width"], + sample["petal_length"], + sample["petal_width"], + ] + } + + def post_inference(prediction, metadata): probabilites = prediction[0][0] predicted_class_id = int(np.argmax(probabilites)) diff --git a/examples/iris/pytorch/handler.py b/examples/iris/handlers/pytorch.py similarity index 100% rename from examples/iris/pytorch/handler.py rename to examples/iris/handlers/pytorch.py diff --git a/examples/iris/sklearn/handler.py b/examples/iris/handlers/sklearn.py similarity index 100% rename from examples/iris/sklearn/handler.py rename to examples/iris/handlers/sklearn.py diff --git a/examples/iris/handlers/xgboost.py b/examples/iris/handlers/xgboost.py new file mode 100644 index 0000000000..d728effc81 --- /dev/null +++ b/examples/iris/handlers/xgboost.py @@ -0,0 +1,19 @@ +import numpy as np + +iris_labels = ["Iris-setosa", "Iris-versicolor", "Iris-virginica"] + + +def pre_inference(sample, metadata): + return { + metadata[0].name: [ + sample["sepal_length"], + sample["sepal_width"], + sample["petal_length"], + sample["petal_width"], + ] + } + + +def post_inference(prediction, metadata): + predicted_class_id = prediction[0][0] + return {"class_label": iris_labels[predicted_class_id], "class_index": predicted_class_id} diff --git a/examples/iris/keras/irises.json b/examples/iris/keras/irises.json deleted file mode 100644 index e949d9211f..0000000000 --- a/examples/iris/keras/irises.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "samples": [ - [ - 5.9, - 3.0, - 5.1, - 1.8 - ], - [ - 5.6, - 2.5, - 3.9, - 1.1 - ] - ] -} diff --git a/examples/iris/keras/requirements.txt b/examples/iris/keras/requirements.txt deleted file mode 100644 index dbc2f28b5f..0000000000 --- a/examples/iris/keras/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -scikit-learn -keras -keras2onnx -tensorflow diff --git a/examples/iris/keras/model.py b/examples/iris/models/keras_model.py similarity index 100% rename from examples/iris/keras/model.py rename to examples/iris/models/keras_model.py diff --git a/examples/iris/pytorch/model.py b/examples/iris/models/pytorch_model.py similarity index 100% rename from examples/iris/pytorch/model.py rename to examples/iris/models/pytorch_model.py diff --git a/examples/iris/models/requirements.txt b/examples/iris/models/requirements.txt new file mode 100644 index 0000000000..5b26b3cf36 --- /dev/null +++ b/examples/iris/models/requirements.txt @@ -0,0 +1,9 @@ +keras +keras2onnx +tensorflow +torch +pandas +skl2onnx +sklearn +onnxmltools +xgboost diff --git a/examples/iris/sklearn/model.py b/examples/iris/models/sklearn_model.py similarity index 100% rename from examples/iris/sklearn/model.py rename to examples/iris/models/sklearn_model.py diff --git a/examples/iris/tensorflow/model.py b/examples/iris/models/tensorflow_model.py similarity index 100% rename from examples/iris/tensorflow/model.py rename to examples/iris/models/tensorflow_model.py diff --git a/examples/iris/xgboost/handler.py b/examples/iris/models/xgboost_model.py similarity index 100% rename from examples/iris/xgboost/handler.py rename to examples/iris/models/xgboost_model.py diff --git a/examples/iris/tensorflow/irises.json b/examples/iris/samples.json similarity index 100% rename from examples/iris/tensorflow/irises.json rename to examples/iris/samples.json