Skip to content

This repo will share examples of how to integrate ONNX format models into the SAS Viya environment as astore models

License

Notifications You must be signed in to change notification settings

sassoftware/onnx-integration

Repository files navigation

SAS Analytic Store (ASTORE) Integration with ONNX

Overview

Examples showing various applications for SAS ASTORE actions that work with ONNX files.

What's New

Several new ASTORE actions are used in these examples including:

  • aStore.check
  • aStore.describe support ONNX file types
  • aStore.saveas
  • aStore.extract

Prerequisites

Python Requirements:

  • Python 3.+
  • Install the following Python modules:
  • Jupyter Notebook (for running the examples)

SAS Requirements:

Other:

  • a valid ONNX file

Getting Started

The following code snippets will take you through how to use the new ASTORE actions. You will need a valid ONNX file.

Read ONNX

onnxfile = /path/to/onnxmodel.onnx
with open(onnxfile,"rb") as file:
    blob = file.read()
blob_ = swat.blob(blob)

Check if ONNX model is valid

s.aStore.check(onnx=blob_)

Describe ONNX model

s.aStore.describe(onnx=blob_)

Save ONNX model to ASTORE

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")]
)

Score data with saved ASTORE

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_")
                )

Extract ONNX model from previously saved ASTORE

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")

Troubleshooting

Contributing

We are not accepting contributions at this time.

License

This project is licensed under the Apache 2.0 License.

Additional Resources

About

This repo will share examples of how to integrate ONNX format models into the SAS Viya environment as astore models

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published