-
Notifications
You must be signed in to change notification settings - Fork 607
Add onnx support #182
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
Add onnx support #182
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
de5fa6e
Add onnx support
vishalbollu 48d1562
Add model examples to examples directory
vishalbollu 0da0a8f
Rename to request handler
vishalbollu 9898415
Merge branch 'master' into onnx-support
vishalbollu aca81f7
Optional pre/post
vishalbollu 6405a4a
Merge branch 'master' into onnx-support
vishalbollu c07f3ce
Optional pre and post processing
vishalbollu e8b12f4
Remove unnecessary config
vishalbollu 05e3b1a
Fix linting
vishalbollu 143e27c
Remove unnecessary logs
vishalbollu b2838e3
Move models to cortex-examples bucket
vishalbollu 3ef4eb8
Add docs and respond to PR comments
vishalbollu 52be6ac
Merge branch 'master' into onnx-support
vishalbollu b9261a1
Fix predictions
vishalbollu 905c2d4
Add request handler docs round 1
vishalbollu c7e3b37
Remove commented code
vishalbollu 3892a23
Cleanup examples and docs round 2
vishalbollu 37adbf7
Rename payload to sample
vishalbollu 9fb94a7
Remove trailing whitespace
vishalbollu 5811ab0
Breakout example models into their own directories
vishalbollu d4d614d
Refactor request handlers
vishalbollu 857da8d
Fix linting issue with predict.go
vishalbollu 1bbf6e1
Restructure examples folder
vishalbollu b3b5ffc
ModelType to ModelFormat
vishalbollu c89005c
Merge branch 'master' into onnx-support
vishalbollu 3e9a265
Tweak example post_inference handler doc
vishalbollu 7231e42
Push down error wrapping
vishalbollu c2af7aa
Tweak comment in pre_inference request-handlers doc
vishalbollu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Request Handlers | ||
|
||
Request handlers are python files that can contain a `pre_inference` function and a `post_inference` function. Both functions are optional. | ||
|
||
## Implementation | ||
|
||
```python | ||
def pre_inference(sample, metadata): | ||
"""Prepare a sample before it is passed into the model. | ||
|
||
Args: | ||
sample: A sample from the request payload. | ||
|
||
metadata: Describes the expected shape and type of inputs to the model. | ||
If API model_format is tensorflow: map<string, SignatureDef> | ||
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/protobuf/meta_graph.proto | ||
If API model_format is onnx: list<onnxruntime.NodeArg> | ||
https://microsoft.github.io/onnxruntime/api_summary.html#onnxruntime.NodeArg | ||
|
||
Returns: | ||
A dictionary containing model input names as keys and python lists or numpy arrays as values. If the model only has a single input, then a python list or numpy array can be returned. | ||
""" | ||
pass | ||
|
||
def post_inference(prediction, metadata): | ||
"""Modify a prediction from the model before responding to the request. | ||
|
||
Args: | ||
prediction: The output of the model. | ||
|
||
metadata: Describes the output shape and type of outputs from the model. | ||
If API model_format is tensorflow: map<string, SignatureDef> | ||
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/protobuf/meta_graph.proto | ||
If API model_format is onnx: list<onnxruntime.NodeArg> | ||
https://microsoft.github.io/onnxruntime/api_summary.html#onnxruntime.NodeArg | ||
|
||
Returns: | ||
A python dictionary or list. | ||
""" | ||
``` | ||
|
||
## Example | ||
|
||
```python | ||
import numpy as np | ||
|
||
iris_labels = ["Iris-setosa", "Iris-versicolor", "Iris-virginica"] | ||
|
||
def pre_inference(sample, metadata): | ||
deliahu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Convert a dictionary of features to a flattened in list in the order expected by the model | ||
return { | ||
metadata[0].name : [ | ||
sample["sepal_length"], | ||
sample["sepal_width"], | ||
sample["petal_length"], | ||
sample["petal_width"], | ||
] | ||
} | ||
|
||
|
||
deliahu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def post_inference(prediction, metadata): | ||
# Update the model prediction to include the index and the label of the predicted class | ||
probabilites = prediction[0][0] | ||
predicted_class_id = int(np.argmax(probabilites)) | ||
return { | ||
"class_label": iris_labels[predicted_class_id], | ||
"class_index": predicted_class_id, | ||
"probabilities": probabilites, | ||
} | ||
|
||
``` | ||
|
||
## Pre-installed Packages | ||
|
||
The following packages have been pre-installed and can be used in your implementations: | ||
|
||
```text | ||
boto3==1.9.78 | ||
msgpack==0.6.1 | ||
numpy>=1.13.3,<2 | ||
requirements-parser==0.2.0 | ||
packaging==19.0.0 | ||
``` | ||
|
||
You can install additional PyPI packages and import your own Python packages. See [Python Packages](../piplines/python-packages.md) for more details. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.