| Title: | 'ONNX Runtime' Integration |
|---|---|
| Description: | Provides high-performance R bindings for 'ONNX Runtime' <https://onnxruntime.ai/>, enabling efficient machine learning model inference. Written in 'Rust' for memory safety and speed, the package supports cross-platform model execution with multiple execution providers. Includes comprehensive error handling and validation, with bundled MNIST example model for immediate testing and prototyping. Designed for production use with support for macOS (arm64), Linux (x64/arm64), and Windows (x64). Runtime libraries are downloaded on explicit request from <https://github.com/microsoft/onnxruntime/releases>. |
| Authors: | Chanyub Park [aut, cre] (ORCID: <https://orcid.org/0000-0001-6474-2570>), The authors of the dependency Rust crates [ctb] (See inst/AUTHORS for details), ONNX Project contributors [ctb, cph] (Bundled MNIST model, Apache License 2.0; see inst/COPYRIGHTS), Microsoft Corporation [cph] (ONNX Runtime, downloaded only on explicit user request) |
| Maintainer: | Chanyub Park <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.13 |
| Built: | 2026-09-27 14:14:00 UTC |
| Source: | https://github.com/mrchypark/churon |
These methods provide convenient access to object properties.
## S3 method for class 'TensorInfo' x$name## S3 method for class 'TensorInfo' x$name
x |
A TensorInfo or RSession object |
name |
Property name to access |
For name and data_type, a character scalar identifying the tensor
or its element type. For shape, an integer vector of tensor dimensions
(negative dimensions indicate dynamic sizes). For a method name, a function
bound to the object; for an unknown name, NULL.
Process data in batches for memory efficiency with large datasets.
batch_process_data(session, data_list, batch_size = 32)batch_process_data(session, data_list, batch_size = 32)
session |
An RSession object created by onnx_session() |
data_list |
A list of input data to process |
batch_size |
Number of items to process in each batch |
A list of results from batch processing
This function checks if ONNX Runtime is properly configured and available.
check_onnx_runtime_available()check_onnx_runtime_available()
Logical indicating whether ONNX Runtime is available
This function returns information about the current ONNX Runtime configuration.
get_onnx_runtime_info()get_onnx_runtime_info()
A list containing ONNX Runtime configuration information
Download and install ONNX Runtime library for your platform. This is required before using the churon package if ONNX Runtime is not already installed on your system.
install_onnx_runtime(version = "1.29.0", quiet = FALSE, destdir, ...)install_onnx_runtime(version = "1.29.0", quiet = FALSE, destdir, ...)
version |
Character string specifying the ONNX Runtime version to install. Defaults to "1.29.0". Supported versions are "1.28.0" and "1.29.0"; "latest" selects "1.29.0". |
quiet |
Logical. If TRUE, suppress download progress messages. |
destdir |
Required character string naming the installation directory. |
... |
Additional arguments passed to download.file() |
This function installs external software only when explicitly called. Supply
destdir yourself; no installation directory is selected by default.
The library is placed in destdir/lib and configured for this R session.
In later sessions, set ORT_DYLIB_PATH to the installed library file before
loading churon. Restart R before switching an already loaded runtime.
Invisible TRUE on success, stops with error on failure.
List available example models bundled with the package.
onnx_example_models()onnx_example_models()
A named character vector with model names as names and paths as values
Create a session with an example model.
onnx_example_session(model_name = "mnist", providers = NULL)onnx_example_session(model_name = "mnist", providers = NULL)
model_name |
Character string specifying the model name (default: "mnist") |
providers |
Optional execution providers |
An RSession object
Retrieve information about model input tensors.
onnx_input_info(session)onnx_input_info(session)
session |
An RSession object created by onnx_session() |
A list of TensorInfo objects containing input tensor metadata
if (check_onnx_runtime_available()) { session <- onnx_example_session() input_info <- onnx_input_info(session) print(input_info) }if (check_onnx_runtime_available()) { session <- onnx_example_session() input_info <- onnx_input_info(session) print(input_info) }
Get the model path from a session.
onnx_model_path(session)onnx_model_path(session)
session |
An RSession object created by onnx_session() |
Character string with the model path
if (check_onnx_runtime_available()) { session <- onnx_example_session() model_path <- onnx_model_path(session) cat("Model path:", model_path, "\n") }if (check_onnx_runtime_available()) { session <- onnx_example_session() model_path <- onnx_model_path(session) cat("Model path:", model_path, "\n") }
Retrieve information about model output tensors.
onnx_output_info(session)onnx_output_info(session)
session |
An RSession object created by onnx_session() |
A list of TensorInfo objects containing output tensor metadata
if (check_onnx_runtime_available()) { session <- onnx_example_session() output_info <- onnx_output_info(session) print(output_info) }if (check_onnx_runtime_available()) { session <- onnx_example_session() output_info <- onnx_output_info(session) print(output_info) }
Get the execution providers available for the session.
onnx_providers(session)onnx_providers(session)
session |
An RSession object created by onnx_session() |
A character vector of available execution providers
if (check_onnx_runtime_available()) { session <- onnx_example_session() providers <- onnx_providers(session) cat("Available execution providers:", paste(providers, collapse = ", "), "\n") }if (check_onnx_runtime_available()) { session <- onnx_example_session() providers <- onnx_providers(session) cat("Available execution providers:", paste(providers, collapse = ", "), "\n") }
Execute inference on an ONNX model with input data.
onnx_run(session, inputs)onnx_run(session, inputs)
session |
An RSession object created by onnx_session() |
inputs |
A named list of input tensors. Names should match model input names. |
A named list of output tensors
if (check_onnx_runtime_available()) { session <- onnx_example_session() inputs <- list(Input3 = array(0, dim = c(1, 1, 28, 28))) outputs <- onnx_run(session, inputs) }if (check_onnx_runtime_available()) { session <- onnx_example_session() inputs <- list(Input3 = array(0, dim = c(1, 1, 28, 28))) outputs <- onnx_run(session, inputs) }
Create a new ONNX Runtime session from a model file.
onnx_session(model_path, providers = NULL)onnx_session(model_path, providers = NULL)
model_path |
Character string specifying the path to the ONNX model file |
providers |
Optional character vector specifying execution providers to use. Available providers: "cuda", "tensorrt", "directml", "onednn", "coreml", "cpu". If NULL, uses default provider priority. |
An RSession object for running inference
if (check_onnx_runtime_available()) { # Create session with default providers session <- onnx_example_session() # Create session with specific providers session <- onnx_example_session(providers = "cpu") }if (check_onnx_runtime_available()) { # Create session with default providers session <- onnx_example_session() # Create session with specific providers session <- onnx_example_session(providers = "cpu") }
Run inference with automatic error handling and monitoring.
safe_onnx_run(session, inputs, monitor_performance = FALSE)safe_onnx_run(session, inputs, monitor_performance = FALSE)
session |
An RSession object created by onnx_session() |
inputs |
A named list of input tensors |
monitor_performance |
Logical indicating whether to monitor performance |
Result of inference or NULL if failed
Safe ONNX Session Creation
safe_onnx_session(model_path, providers = NULL)safe_onnx_session(model_path, providers = NULL)
model_path |
Character string specifying the path to the ONNX model file |
providers |
Optional character vector specifying execution providers |
Create an ONNX session with automatic error handling.
An RSession object or NULL if creation fails