百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
O

onnxruntime-ruby

> 编程语言
开源

在 Ruby 中运行 ONNX 模型

165 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

在 Ruby 中运行 ONNX 模型

ONNX Runtime Ruby

:fire: ONNX Runtime - the high performance scoring engine for ML models - for Ruby

Check out an example

For transformer models, check out Informers

Installation

Add this line to your application’s Gemfile:

ruby
gem "onnxruntime"

On Mac x86-64, also run brew install onnxruntime to install the shared library

Getting Started

Load a model and make predictions

ruby
model = OnnxRuntime::Model.new("model.onnx")
model.predict({x: [1, 2, 3]})

Download pre-trained models from the ONNX Model Zoo

Get inputs

ruby
model.inputs

Get outputs

ruby
model.outputs

Get metadata

ruby
model.metadata

Load a model from a string or other IO object

ruby
io = StringIO.new("...")
model = OnnxRuntime::Model.new(io)

Get specific outputs

ruby
model.predict({x: [1, 2, 3]}, output_names: ["label"])

Session Options

ruby
OnnxRuntime::Model.new(
  path_or_io,
  enable_cpu_mem_arena: true,
  enable_mem_pattern: true,
  enable_profiling: false,
  execution_mode: :sequential,    # :sequential or :parallel
  free_dimension_overrides_by_denotation: nil,
  free_dimension_overrides_by_name: nil,
  graph_optimization_level: nil,  # :none, :basic, :extended, or :all
  inter_op_num_threads: nil,
  intra_op_num_threads: nil,
  log_severity_level: 2,
  log_verbosity_level: 0,
  logid: nil,
  optimized_model_filepath: nil,
  profile_file_prefix: "onnxruntime_profile_",
  session_config_entries: nil
)

Run Options

ruby
model.predict(
  input_feed,
  output_names: nil,
  log_severity_level: 2,
  log_verbosity_level: 0,
  logid: nil,
  terminate: false,
  output_type: :ruby       # :ruby or :numo
)

Inference Session API

You can also use the Inference Session API, which follows the Python API.

ruby
session = OnnxRuntime::InferenceSession.new("model.onnx")
session.run(nil, {x: [1, 2, 3]})

The Python example models are included as well.

ruby
OnnxRuntime::Datasets.example("sigmoid.onnx")

GPU Support

Linux and Windows

Download the appropriate GPU release and set:

ruby
OnnxRuntime.ffi_lib = "path/to/lib/libonnxruntime.so" # onnxruntime.dll for Windows

and use:

ruby
model = OnnxRuntime::Model.new("model.onnx", providers: ["CUDAExecutionProvider"])

Mac

Use:

ruby
model = OnnxRuntime::Model.new("model.onnx", providers: ["CoreMLExecutionProvider"])

History

View the changelog

Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help:

  • Report bugs
  • Fix bugs and submit pull requests
  • Write, clarify, or fix documentation
  • Suggest or add new features

To get started with development and testing:

bash
git clone https://github.com/ankane/onnxruntime-ruby.git
cd onnxruntime-ruby
bundle install
bundle exec rake vendor:all
bundle exec rake test

Issues· 1 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Ruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言