Skip to content

Commit

Permalink
Restructure iris example (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalbollu authored and deliahu committed Jul 30, 2019
1 parent 1b737d4 commit 93f21e9
Show file tree
Hide file tree
Showing 16 changed files with 48 additions and 29 deletions.
2 changes: 1 addition & 1 deletion cli/cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 @<json_file_path>\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()))
Expand Down
8 changes: 4 additions & 4 deletions docs/apis/packaging-models.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
8 changes: 4 additions & 4 deletions examples/iris/cortex.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions examples/iris/keras/handler.py → examples/iris/handlers/keras.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
File renamed without changes.
File renamed without changes.
19 changes: 19 additions & 0 deletions examples/iris/handlers/xgboost.py
Original file line number Diff line number Diff line change
@@ -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}
16 changes: 0 additions & 16 deletions examples/iris/keras/irises.json

This file was deleted.

4 changes: 0 additions & 4 deletions examples/iris/keras/requirements.txt

This file was deleted.

File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions examples/iris/models/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
keras
keras2onnx
tensorflow
torch
pandas
skl2onnx
sklearn
onnxmltools
xgboost
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 93f21e9

Please sign in to comment.