ComputeModel
Returns a JSON object containing the result of the Core ML model evaluation.
Format
For general models:
ComputeModel ( modelName ; parameterName1 ; value1 )
For vision models:
ComputeModel ( modelName ; "image" ; value1 ; "confidenceLowerLimit" ; returnAtLeastOne )
Parameters
modelName
- the name of the model to evaluate. This value must match the name of a previously loaded model.
parameterName1
- the name of an input parameter as defined by the model's designer. You must know the name of each of these parameters before using the model.
value1
- the value of a model input parameter.
image
(vision models only) - the type of data the model will evaluate.
confidenceLowerLimit
(vision models only) (optional) - a value used that limits the number of results returned by vision models by excluding results that are less than the specified value. This value must be between 0.0 and 1.0.
returnAtLeastOne
(vision models only) - a true (non-zero) or false (zero) value. If all results are excluded by the value of confidenceLowerLimit
and:
- if
returnAtLeastOne
is true, the result with the highest confidence is returned - if
returnAtLeastOne
is false or not specified, an empty string is returned
Data type returned
text
Originated in version
19.0
Description
The object returned is either an array of name-value pairs or a single name-value pair, depending on the definition of the model that's evaluated.
Notes
- A Core ML model must be loaded first with the Configure Machine Learning Model script step before ComputeModel can be used.
- An input parameter must be followed by its respective value, and multiple input parameter-value pairs can be used.
- If a result contains two matches with the same confidence, only the first value is returned.
- This function is supported only on iOS, iPadOS, and macOS.
Example 1
Assuming that a model named MobileNet
has been loaded and a container field named myImageField
is on the current layout (or otherwise available to the calculation):
ComputeModel ( "MobileNet"; "image"; myImageField )
evaluates the image in myImageField
using the given model and returns the following JSON string (formatted for clarity and some lines removed for brevity):
[
{
"classification" : "grand piano, grand",
"confidence" : 0.998073041439056
},
{
"classification" : "upright, upright piano",
"confidence" : 0.00192673446144909
},
{
"classification" : "pool table, billiard table, snooker table",
"confidence" : 8.34678601790984e-08
},
{
"classification" : "dining table, board",
"confidence" : 2.60599577472931e-08
},
{
"classification" : "puffer, pufferfish, blowfish, globefish",
"confidence" : 5.19516656696278e-18
}
]
Example 2
Using the same model, container field, and image from Example 1, the following calculation:
ComputeModel("MobileNet"; "image"; myImageField; "confidenceLowerLimit"; 1.0; "returnAtLeastOne"; 1)
returns the JSON string:
Passing confidenceLowerLimit
a value of 1.0 excludes all the results. But because returnAtLeastOne
is set to a non-zero value, the result with the highest confidence is returned.