| Title: | 'ONNX' Runtime Integration for R |
|---|---|
| Description: | Provides high-performance R bindings for 'ONNX' Runtime, 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/x64), Linux (x64/arm64), and Windows (x64/arm64). |
| Authors: | Chanyub Park [aut, cre]
|
| Maintainer: | Chanyub Park <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.10 |
| Built: | 2026-05-18 09:07:23 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 |
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.23.2", quiet = FALSE, ...)install_onnx_runtime(version = "1.23.2", quiet = FALSE, ...)
version |
Character string specifying the ONNX Runtime version to install. Defaults to "1.23.2". Use "latest" to download the latest stable version. |
quiet |
Logical. If TRUE, suppress download progress messages. |
... |
Additional arguments passed to download.file() |
Invisible TRUE on success, stops with error on failure.
## Not run: # Install ONNX Runtime install_onnx_runtime() # Install specific version install_onnx_runtime(version = "1.23.0") # Install with no output install_onnx_runtime(quiet = TRUE) ## End(Not run)## Not run: # Install ONNX Runtime install_onnx_runtime() # Install specific version install_onnx_runtime(version = "1.23.0") # Install with no output install_onnx_runtime(quiet = TRUE) ## End(Not run)
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
## Not run: session <- onnx_session("path/to/model.onnx") input_info <- onnx_input_info(session) print(input_info) ## End(Not run)## Not run: session <- onnx_session("path/to/model.onnx") input_info <- onnx_input_info(session) print(input_info) ## End(Not run)
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
## Not run: session <- onnx_session("path/to/model.onnx") model_path <- onnx_model_path(session) cat("Model path:", model_path, "\n") ## End(Not run)## Not run: session <- onnx_session("path/to/model.onnx") model_path <- onnx_model_path(session) cat("Model path:", model_path, "\n") ## End(Not run)
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
## Not run: session <- onnx_session("path/to/model.onnx") output_info <- onnx_output_info(session) print(output_info) ## End(Not run)## Not run: session <- onnx_session("path/to/model.onnx") output_info <- onnx_output_info(session) print(output_info) ## End(Not run)
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
## Not run: session <- onnx_session("path/to/model.onnx") providers <- onnx_providers(session) cat("Available execution providers:", paste(providers, collapse = ", "), "\n") ## End(Not run)## Not run: session <- onnx_session("path/to/model.onnx") providers <- onnx_providers(session) cat("Available execution providers:", paste(providers, collapse = ", "), "\n") ## End(Not run)
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
## Not run: session <- onnx_session("path/to/model.onnx") inputs <- list(input_tensor = matrix(rnorm(10), nrow = 2, ncol = 5)) outputs <- onnx_run(session, inputs) ## End(Not run)## Not run: session <- onnx_session("path/to/model.onnx") inputs <- list(input_tensor = matrix(rnorm(10), nrow = 2, ncol = 5)) outputs <- onnx_run(session, inputs) ## End(Not run)
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
## Not run: # Create session with default providers session <- onnx_session("path/to/model.onnx") # Create session with specific providers session <- onnx_session("path/to/model.onnx", providers = c("cuda", "cpu")) ## End(Not run)## Not run: # Create session with default providers session <- onnx_session("path/to/model.onnx") # Create session with specific providers session <- onnx_session("path/to/model.onnx", providers = c("cuda", "cpu")) ## End(Not run)
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