Documentation Home
MySQL AI
Download this Manual
PDF (US Ltr) - 1.4Mb
PDF (A4) - 1.4Mb


4.7.7.1 ONNX Models Overview

You cannot directly load models in ONNX format (.onnx) into a MySQL table. The models require string serialization and conversion to Base64 encoding before you use the ML_MODEL_IMPORT routine.

AutoML supports the following ONNX model types:

  • An ONNX model that has only one input, and it is the entire MySQL table.

  • An ONNX model that has more than one input, and each input is one column in the MySQL table.

For example, AutoML does not support an ONNX model that takes more than one input, and each input is associated with more than one column in the MySQL table.

The first dimension of the input to the ONNX model provided by the ONNX model get_inputs() API should be the batch size. This should be None, a string, or an integer. None or string indicate a variable batch size, and an integer indicates a fixed batch size.

Examples of input shapes:

[None, 2] 

['batch_size', 2, 3]

[1, 14]

All other dimensions should be integers. For example, AutoML does not support an input shape similar to the following:

input shape = ['batch_size', 'sequence_length']

The output of an ONNX model is a list of results. The ONNX API documentation defines the results as a numpy array, a list, a dictionary, or a sparse tensor. AutoML only supports a numpy array, a list, and a dictionary.

  • Numpy array examples:

    array(['Iris-virginica', 'Iris-versicolor', 'Iris-versicolor', 'Iris-versicolor'], dtype=object)
     
    array([0, 2, 0, 0], dtype=int64)
     
    array([[0.8896357 , 0.11036429],
           [0.28360802, 0.716392  ],
           [0.9404001 , 0.05959991],
           [0.5655978 , 0.43440223]], dtype=float32)
     
    array([[0.96875435],
           [1.081366  ],
           [0.5736201 ],
           [0.90711355]], dtype=float32)
  • Simple list examples:

    ['Iris-virginica', 'Iris-versicolor', 'Iris-versicolor', 'Iris-versicolor']
     
    [0, 2, 0, 0]
  • List of lists examples:

    [[0.8896357 , 0.110364],
    [0.28360802, 0.716392],
    [0.9404001 , 0.059599],
    [0.5655978 , 0.434402]]
     
    [[[0.8896357] , [0.110364]],
    [[0.28360802], [0.716392]],
    [[0.9404001] , [0.059599]],
    [[0.5655978] , [0.434402]]]
     
    [[0.968754],
    [1.081366],
    [0.573620],
    [0.907113]]
     
    [[[0.968754]],
    [[1.081366]],
    [[0.573620]],
    [[0.907113]]]
  • Dictionary examples:

    {'Iris-setosa': 0.0, 'Iris-versicolor': 0.0, 'Iris-virginica': 0.999}
     
    {0: 0.1, 1: 0.9}
  • List of dictionaries examples:

    [{'Iris-setosa': 0.0, 'Iris-versicolor': 0.0, 'Iris-virginica': 0.999},
    {'Iris-setosa': 0.0, 'Iris-versicolor': 0.999, 'Iris-virginica': 0.0},
    {'Iris-setosa': 0.0, 'Iris-versicolor': 0.589, 'Iris-virginica': 0.409},
    {'Iris-setosa': 0.0, 'Iris-versicolor': 0.809, 'Iris-virginica': 0.190}]
     
    [{0: 1.0, 1: 0.0, 2: 0.0},
    {0: 0.0, 1: 0.0, 2: 1.0},
    {0: 1.0, 1: 0.0, 2: 0.0},
    {0: 1.0, 1: 0.0, 2: 0.0}]
     
    [{0: 0.176, 1: 0.823},
    {0: 0.176, 1: 0.823},
    {0: 0.264, 1: 0.735},
    {0: 0.875, 1: 0.124}]
     
    [{0: 0.176, 1: 0.823},
    {0: 0.176, 1: 0.823},
    {0: 0.264, 1: 0.735},
    {0: 0.875, 1: 0.124}]
     
    [{0: 0.176, 1: 0.823},
    {0: 0.176, 1: 0.823},
    {0: 0.264, 1: 0.735},
    {0: 0.875, 1: 0.124}]

For classification and regression tasks, AutoML only supports model explainers and scoring for variable batch sizes.

For forecasting, anomaly detection and recommendation tasks, AutoML does not support model explainers and scoring. The prediction column must contain a JSON object literal of name value keys. For example, for three outputs:

{output1: value1, output2: value2, output3: value3}
What's Next