predict.onnx_model: Predict with an ONNX Model

View source: R/onnx.R

predict.onnx_modelR Documentation

Predict with an ONNX Model

Description

Runs inference over x, batching it to the fixed input shape the model was loaded with. This is the keras-compatible entry point: together with the ggml_sequential_model and ggml_functional_model methods it gives ggmlR and ONNX models a single predict() interface.

Usage

## S3 method for class 'onnx_model'
predict(object, x, batch_size = NULL, ...)

Arguments

object

An onnx_model from onnx_load.

x

Input data: an array or matrix whose first dimension indexes samples, or a named list of such arrays for multi-input models.

batch_size

Ignored, with a warning if not NULL. The batch size is fixed when the model is loaded; pass input_shapes to onnx_load to change it. The argument exists so the signature matches the other predict() methods.

...

Ignored.

Details

Unlike onnx_run, which takes a named list of inputs and always returns a named list of outputs, this method takes an array (or a named list for multi-input models) and unwraps a single output. The output keeps the dimensions the model produced: a 2D output comes back as a matrix, a 4D output stays 4D.

An ONNX graph is built for one fixed batch size at onnx_load time and cannot be resized afterwards, so x is split into chunks of that size. A trailing partial chunk is padded to a full batch and the padding is dropped from the result.

Value

For a single-output model, an array with the model's output dimensions and nrow(x) samples in the first one (a matrix when the output is 2D). For a multi-output model, a named list of such arrays.

See Also

onnx_run for the lower-level named-list interface.


ggmlR documentation built on Oct. 23, 2026, 1:07 a.m.