ONNX packages a model’s weights and computation graph outside R or Python so applications can serve predictions from other environments, such as C++. section 6.3.2
Export and serve a Keras model
Export a Keras model in ONNX format, load it with onnxruntime, create an inference session, and run predictions on input data. section 6.3.2
model |> export_savedmodel("path/to/location", format = "onnx") #1reticulate::py_require("onnxruntime") #1
onnxruntime <- reticulate::import("onnxruntime")
ort_session <- onnxruntime$InferenceSession("path/to/location")
predictions <- ort_session$run(NULL, input_data)
Shows the R workflow for exporting a model to ONNX and invoking it through onnxruntime. section 6.3.2






