ONNX_RUN()¶
ONNX_RUN(model, input, input_shape, output_shape) evaluates an ONNX model directly from SQL, passing the model as a datalink or varbinary and the input and shape descriptors as JSON strings.
Description¶
ONNX_RUN() runs an ONNX model and returns its output. The model can be supplied either as a DATALINK pointing to an .onnx file or as raw VARBINARY bytes loaded with LOAD_FILE().
The input argument is a JSON array of numeric values that forms the input tensor. The input_shape and output_shape arguments are JSON objects describing the tensor dimensions and data type, for example '{"dim":[1,1,4],"dtype":"float32"}'.
Supported input and output data types include float32, float16, int32, and int8. An unsupported data type, an input length that does not match the declared shape, or an out-of-range value for an integer data type is an error. If the model or input is NULL, the result is NULL.
Syntax¶
ONNX_RUN(model, input, input_shape, output_shape)
Arguments¶
Argument |
Description |
|---|---|
|
A |
|
A JSON array string with the input tensor values. |
|
A JSON object describing the input dimensions and data type, such as |
|
A JSON object describing the output dimensions and data type, or |
Return Value¶
Returns the model output as a JSON-encoded value.
Examples¶
The following example passes NULL as the model, so ONNX_RUN() returns NULL. To evaluate a real model, pass a DATALINK to an .onnx file or a VARBINARY value loaded with LOAD_FILE().
DROP DATABASE IF EXISTS onnx_run_demo;
CREATE DATABASE onnx_run_demo;
USE onnx_run_demo;
SELECT ONNX_RUN(
CAST(NULL AS DATALINK),
'[0.2,0.3,0.6,0.9]',
'{"dim":[1,1,4],"dtype":"float32"}',
'{"dim":[1,1,2],"dtype":"float32"}') AS null_model;
DROP DATABASE onnx_run_demo;