liveBook · Manning

ONNX

As explained in Deep Learning with R, Third Edition

ONNX is an open format and ecosystem for representing and exchanging machine-learning models across frameworks and runtimes.

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

How Deep Learning with R, Third Edition covers it

How deep it goes
Explains the export-and-runtime workflow but stops short of detailing ONNX internals or optimization techniques.
Examples
Uses Keras export_savedmodel(), onnxruntime InferenceSession, and prediction calls as the working deployment example.
What it assumes
Assumes a trained Keras model and input data while demonstrating the deployment steps from export through inference.
What you can do after
Operate/configure ONNX serving by exporting a Keras model and running predictions through onnxruntime.
How it connects
Connects model export with Keras, REST APIs, TensorFlow Serving, inference, and onnxruntime.

Also explained in

Compare how 7 books explain ONNX →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with R, Third Edition. The section links point to the parts of the book it draws on.