Specifications for ONNX Format Models
This topic lists the specifications for ONNX image and ONNX non-image models that are supported by the Oracle Machine Learning Services REST API.
- The
"function"
field in themetadata.json
file is required for all models. The value for"function"
inmetadata.json
must either be"classification"
,"regression"
,"clustering"
or"feature_extraction"
. - Supported dimensions of input tensor:
- For non-image models, the dimension of input tensor is
2
. - For image models, the dimension of input tensor is
4
.
Note:
For both image and non-image models, the first dimension should be the tensor batch size. - For non-image models, the dimension of input tensor is
- For Regression Models:
- If there is only one output, then the assumption is that it is a tensor storing regression output. In this case, specifying the
"regressionOutput"
is optional. - If there are more than one output, then specifying the
"regressionOutput"
is mandatory. - For both these cases, the specified
"regressionOutput"
will be validated on the basis of:- Existence: Must be a valid output name
- Type: Must be a tensor
- Value type:
float/double
- Shape: Must be one numerical prediction for each input data sample. That is, the shape of the output tensor must be
[batchSize, 1]
Note:
If any of the validations fail, then an exception will be raised.
- If there is only one output, then the assumption is that it is a tensor storing regression output. In this case, specifying the
- For Classification Models:
- If the model has only one output and it is a tensor storing probabilities, then
"classificationLabelOutput"
is optional. and will be ignored if specified,"classificationProbOutput"
is optional. label.txt is required for this case. - If the model has exactly two outputs, one tensor storing label info, and one sequence storing probabilities,then both
"classificationLabelOutput"
and"classificationProbOutput"
are optional. Thelabel.txt
is not required for this case and it will be ignored if provided. - For all other cases,
"classificationProbOutput"
is required,"classificationLabelOutput"
is optional if label.txt is present."classificationLabelOutput"
is required iflabel.txt
is not provided. If"classificationLabelOutput"
is specified thenlabel.txt
will be ignored if provided. - For all above cases, the specified
"classificationLabelOutput"
and"classificationProbOutput"
will be validated on the basis of:- Existence: Must be a valid output name
- Type:
classificationLabelOutput
must be a tensor.classificationProbOutput
can be a tensor or a sequence - Value type:
classificationProbOutput
must have value typefloat/double
either as a tensor or as a sequence of maps - Shape: The shape of the
classificationProbOutput
tensor must be one of the following:[batchSize x numClass]
or[batchSize x numClass x1]
or[batchSize x numClass x 1 x 1]
, wherenumClass
is the number of different classesNote:
If any of the validations fail, then an exception will be raised.
- If the model has only one output and it is a tensor storing probabilities, then
- For Clustering Models: You must specify either
clusteringDistanceOutput
orclusteringProbOutput
.Note:
You cannot specify both.The specified
clusteringDistanceOutput
orclusteringProbOutput
will be validated on the basis of:- Existence: Must be a valid output name
- Type: Must be a tensor
- Value type: Must have value type
float/double
- Shape: The shape of the tensor must be
[batchSize x numCluster]
wherenumCluster
is the number of different clusters
Note:
If any of the validations fail, then an exception will be raised. - For Feature Extraction Models:
- If there is only one output, then the assumption is that it is a tensor storing feature. In this case, specifying the
"featureExtractionOutput"
is optional. - If there are more than one output, then specifying the
"featureExtractionOutput"
is mandatory.
For both these cases, the specified"featureExtractionOutput"
is validated on the basis of:- Existence: Must be a valid output name
- Type: Must be a tensor
- Value type: Must have value type
float/double
- Shape: Must be a vector for each input data sample. That is, the shape of the output tensor must be
[batchSize, featureLength]
Note:
If any of these validations fail, then an exception will be raised.
- If there is only one output, then the assumption is that it is a tensor storing feature. In this case, specifying the
- For Image Models:
Note:
Currently, Oracle Machine Learning Services REST API supports image Classification models and image Feature Extraction models only.- Supported output structures in the
metadata.json
file for proper image processing are:"inputTensorDimNames"
"height"
"width"
"channel"
- The model must have only one input tensor with numeric values and the shape of the tensor should be 4-dimensional. For example,
[1, 224, 224, 3]
. The first dimension of input tensor must be batch number. If you want to score with deployed image model with image files as input, then the input tensor shape should have1
or-1
as the batch number. - Our services support ONNX image models that consume 3-channel images only. To find this information, you can print the input shape and find the number corresponds to
"channel"
whose position can be found in"inputTensorDimNames"
. For example, input shape is[1, 224, 224, 3]
andinputTensorDimNames
is["batch", "height", "width", "channel"]
, then channel = 3.
- Supported output structures in the