A REST API turns a trained inference model into an online product. It separates model weights and the computation graph from the R or Python application, allowing predictions to be served from another environment. section 6.3.2
Exporting a Keras model for serving
Export a Keras model as a TensorFlow SavedModel, reload the artifact, and call its serving function with input data. An equivalent workflow uses ONNX and ONNX Runtime. section 6.3.2
library(keras3)
model |>
export_savedmodel("path/to/location", format = "tf_saved_model") #1
reloaded_artifact <- tensorflow::tf$saved_model$load("path/to/location") #2
predictions <- reloaded_artifact$serve(input_data)
Runnable R code exports a Keras model, reloads the TensorFlow artifact, and obtains predictions through its serving interface. section 6.3.2
Typical deployment choices include:
- TensorFlow Serving serves a computation graph with saved weights. section 6.3.2
- ONNX exports the model for execution through ONNX Runtime. section 6.3.2
- Posit Connect can directly serve an exported Keras model. section 6.3.2





















