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



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

def inputs
  @session.inputs
end

#metadataObject



26
27
28
# File 'lib/onnxruntime/model.rb', line 26

def 
  @session.modelmeta
end

#outputsObject



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

def outputs
  @session.outputs
end

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



7
8
9
10
11
12
13
14
15
16
# 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] }

  result = {}
  output_names.zip(predictions).each do |k, v|
    result[k.to_s] = v
  end
  result
end