Examples showing various applications for SAS ASTORE actions that work with ONNX files.
Several new ASTORE actions are used in these examples including:
- aStore.check
- aStore.describe support ONNX file types
- aStore.saveas
- aStore.extract
Python Requirements:
- Python 3.+
- Install the following Python modules:
- swat
- numpy (optional)
- PIL (optional)
- matplotlib (optional)
- Jupyter Notebook (for running the examples)
SAS Requirements:
- SAS Visual Data Mining and Machine Learning
- SAS Studio
- SAS Event Stream Processing Studio (if following the ESP example)
- a running CAS server
Other:
- a valid ONNX file
The following code snippets will take you through how to use the new ASTORE actions. You will need a valid ONNX file.
onnxfile = /path/to/onnxmodel.onnx
with open(onnxfile,"rb") as file:
blob = file.read()
blob_ = swat.blob(blob)
s.aStore.check(onnx=blob_)
s.aStore.describe(onnx=blob_)
The saveas action parameters are specific to the ONNX model being used. The following code snippet shows saving a VGG model to ASTORE - example can be found in the ImageClassification folder.
...
# load and re-shape images
...
# Create output class index list (1000 classes)
boxidx = [str(i) for i in range(1000)]
s.aStore.saveas(
table="imagesResized",
rstore=dict(name="onnxstore",replace=True),
onnx=blob_,
inputs=[dict(vars=["_image_"],shape=[1,3,224,224],varbinrayType="UINT8",
inputShapeOrder="NHWC", inputColorOrder="BGR",
modelShapeOrder="NCHW", modelColorOrder="RGB",
preprocess="NORMALIZE", normFactor=255,
normmean=normmean_vals,
normstd=normstd_vals)],
outputs=[dict(name="output",shape=[1,1000], labels=boxidx, labeldim=[1], postprocess="SOFTMAX")]
)
Scoring data with an ASTORE generated from an ONNX model is exactly the same as scoring with a regular ASTORE.
s.aStore.score(rstore="onnxstore", table="imagesResized",
out=dict(name="outscore",replace=True),
copyvars=("_path_")
)
The extract action pulls the ONNX model from the generated ASTORE which allows users to investigate the ONNX model contents the ASTORE was created from. This action only works with ASTOREs that were saved from an ONNX model originally.
s.aStore.extract(rstore="onnxstore")
We are not accepting contributions at this time.
This project is licensed under the Apache 2.0 License.
- ASTORE Documentation
- SAS Communities: ASTORE Wrapper for ONNX, Dataviz in Microsoft 365
- SAS Blog post: Integrating ONNX models into ASTORE
- Technical details about how SAS Event Stream Processing deploys offline model
- Reference for Using Python Interface
- Reference for Getting Started with SAS Viya for Python
- An overview of SAS Visual Analytics
- SAS Support Communities website
- SAS Event Stream Processing Free Trial