Class: OnnxRuntime::Model

Inherits:
Object
  • Object
show all
Defined in:
lib/onnxruntime/model.rb

Instance Method Summary collapse

Constructor Details

#initialize(path_or_bytes, **session_options) ⇒ Model

Returns a new instance of Model.



3
4
5
# File 'lib/onnxruntime/model.rb', line 3

def initialize(path_or_bytes, **session_options)
  @session = InferenceSession.new(path_or_bytes, **session_options)
end

Instance Method Details

#inputsObject



13
14
15
# File 'lib/onnxruntime/model.rb', line 13

def inputs
  @session.inputs
end

#metadataObject



21
22
23
# File 'lib/onnxruntime/model.rb', line 21

def 
  @session.modelmeta
end

#outputsObject



17
18
19
# File 'lib/onnxruntime/model.rb', line 17

def outputs
  @session.outputs
end

#predict(input_feed, output_names: nil, **run_options) ⇒ Object



7
8
9
10
11
# File 'lib/onnxruntime/model.rb', line 7

def predict(input_feed, output_names: nil, **run_options)
  predictions = @session.run(output_names, input_feed, **run_options)
  output_names ||= outputs.map { |o| o[:name] }
  output_names.zip(predictions).to_h { |k, v| [k.to_s, v] }
end