Skip to contents

Generates output predictions for the input samples.


# S3 method for keras.src.models.model.Model
  batch_size = NULL,
  verbose = getOption("keras.verbose", default = "auto"),
  steps = NULL,
  callbacks = NULL



Keras model object


Input samples. It could be:

  • A array (or array-like), or a list of arrays (in case the model has multiple inputs).

  • A tensor, or a list of tensors (in case the model has multiple inputs).

  • A TF Dataset.


For forward/backward compatability.


Integer or NULL. Number of samples per batch. If unspecified, batch_size will default to 32. Do not specify the batch_size if your data is in the form of a TF Dataset or a generator (since they generate batches).


"auto", 0, 1, or 2. Verbosity mode. 0 = silent, 1 = progress bar, 2 = one line per epoch. "auto" becomes 1 for most cases, 2 if in a knitr render or running on a distributed training server. Note that the progress bar is not particularly useful when logged to a file, so verbose=2 is recommended when not running interactively (e.g., in a production environment). Defaults to "auto".


Total number of steps (batches of samples) before declaring the prediction round finished. Ignored with the default value of NULL. If x is a TF Dataset and steps is NULL, predict() will run until the input dataset is exhausted.


List of Callback instances. List of callbacks to apply during prediction.


R array(s) of predictions.


Computation is done in batches. This method is designed for batch processing of large numbers of inputs. It is not intended for use inside of loops that iterate over your data and process small numbers of inputs at a time.

For small numbers of inputs that fit in one batch, directly call the model model$call for faster execution, e.g., model(x), or model(x, training = FALSE) if you have layers such as BatchNormalization that behave differently during inference.


See this FAQ entry for more details about the difference between Model methods predict() and call().