onnxruntime 0.7.2-aarch64-linux → 0.7.4-aarch64-linux
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -1
- data/README.md +5 -5
- data/lib/onnxruntime/inference_session.rb +63 -51
- data/lib/onnxruntime/version.rb +1 -1
- data/vendor/libonnxruntime.arm64.so +0 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e59fdeb57ab195e7ef7723bfa0163a79f660c424fef3e0cfc00f3ce06f66b2c
|
4
|
+
data.tar.gz: d71a8821ff8bd7581567b2cca19b6159fc5f0aa8e15a9105d4ad6c6fad903005
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 816959bdcd21bf44fe1b2d668757945c2f6bf0e8e0cee80de0709dee36301d2f688a3e9847dffed22731625a1a47dcb9ab995739f375c28b1c19af4ea87c1694
|
7
|
+
data.tar.gz: 60110a93cade9aed6df6005362c554af2afc91ff53e7db7d782a408f1b1d1f0fac5211527126f20deeffdb9ad884f0c3009ffa6c02dbf540d5632b6fb2494f0a
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -43,11 +43,11 @@ Get metadata
|
|
43
43
|
model.metadata
|
44
44
|
```
|
45
45
|
|
46
|
-
Load a model from a string
|
46
|
+
Load a model from a string or other `IO` object
|
47
47
|
|
48
48
|
```ruby
|
49
|
-
|
50
|
-
model = OnnxRuntime::Model.new(
|
49
|
+
io = StringIO.new("...")
|
50
|
+
model = OnnxRuntime::Model.new(io)
|
51
51
|
```
|
52
52
|
|
53
53
|
Get specific outputs
|
@@ -59,7 +59,7 @@ model.predict({x: [1, 2, 3]}, output_names: ["label"])
|
|
59
59
|
## Session Options
|
60
60
|
|
61
61
|
```ruby
|
62
|
-
OnnxRuntime::Model.new(
|
62
|
+
OnnxRuntime::Model.new(path_or_io, {
|
63
63
|
enable_cpu_mem_arena: true,
|
64
64
|
enable_mem_pattern: true,
|
65
65
|
enable_profiling: false,
|
@@ -93,7 +93,7 @@ model.predict(input_feed, {
|
|
93
93
|
|
94
94
|
## Inference Session API
|
95
95
|
|
96
|
-
You can also use the Inference Session API, which follows the [Python API](https://
|
96
|
+
You can also use the Inference Session API, which follows the [Python API](https://onnxruntime.ai/docs/api/python/api_summary.html).
|
97
97
|
|
98
98
|
```ruby
|
99
99
|
session = OnnxRuntime::InferenceSession.new("model.onnx")
|
@@ -55,58 +55,12 @@ module OnnxRuntime
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
|
59
|
-
@session = ::FFI::MemoryPointer.new(:pointer)
|
60
|
-
from_memory =
|
61
|
-
if path_or_bytes.respond_to?(:read)
|
62
|
-
path_or_bytes = path_or_bytes.read
|
63
|
-
true
|
64
|
-
else
|
65
|
-
path_or_bytes = path_or_bytes.to_str
|
66
|
-
path_or_bytes.encoding == Encoding::BINARY
|
67
|
-
end
|
68
|
-
|
69
|
-
if from_memory
|
70
|
-
check_status api[:CreateSessionFromArray].call(env.read_pointer, path_or_bytes, path_or_bytes.bytesize, session_options.read_pointer, @session)
|
71
|
-
else
|
72
|
-
check_status api[:CreateSession].call(env.read_pointer, ort_string(path_or_bytes), session_options.read_pointer, @session)
|
73
|
-
end
|
58
|
+
@session = load_session(path_or_bytes, session_options)
|
74
59
|
ObjectSpace.define_finalizer(self, self.class.finalize(@session))
|
75
60
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
check_status api[:GetAllocatorWithDefaultOptions].call(allocator)
|
80
|
-
@allocator = allocator
|
81
|
-
|
82
|
-
@inputs = []
|
83
|
-
@outputs = []
|
84
|
-
|
85
|
-
# input
|
86
|
-
num_input_nodes = ::FFI::MemoryPointer.new(:size_t)
|
87
|
-
check_status api[:SessionGetInputCount].call(read_pointer, num_input_nodes)
|
88
|
-
num_input_nodes.read(:size_t).times do |i|
|
89
|
-
name_ptr = ::FFI::MemoryPointer.new(:string)
|
90
|
-
check_status api[:SessionGetInputName].call(read_pointer, i, @allocator.read_pointer, name_ptr)
|
91
|
-
# freed in node_info
|
92
|
-
typeinfo = ::FFI::MemoryPointer.new(:pointer)
|
93
|
-
check_status api[:SessionGetInputTypeInfo].call(read_pointer, i, typeinfo)
|
94
|
-
@inputs << {name: name_ptr.read_pointer.read_string}.merge(node_info(typeinfo))
|
95
|
-
allocator_free name_ptr
|
96
|
-
end
|
97
|
-
|
98
|
-
# output
|
99
|
-
num_output_nodes = ::FFI::MemoryPointer.new(:size_t)
|
100
|
-
check_status api[:SessionGetOutputCount].call(read_pointer, num_output_nodes)
|
101
|
-
num_output_nodes.read(:size_t).times do |i|
|
102
|
-
name_ptr = ::FFI::MemoryPointer.new(:string)
|
103
|
-
check_status api[:SessionGetOutputName].call(read_pointer, i, allocator.read_pointer, name_ptr)
|
104
|
-
# freed in node_info
|
105
|
-
typeinfo = ::FFI::MemoryPointer.new(:pointer)
|
106
|
-
check_status api[:SessionGetOutputTypeInfo].call(read_pointer, i, typeinfo)
|
107
|
-
@outputs << {name: name_ptr.read_pointer.read_string}.merge(node_info(typeinfo))
|
108
|
-
allocator_free name_ptr
|
109
|
-
end
|
61
|
+
@allocator = load_allocator
|
62
|
+
@inputs = load_inputs
|
63
|
+
@outputs = load_outputs
|
110
64
|
ensure
|
111
65
|
release :SessionOptions, session_options
|
112
66
|
end
|
@@ -223,6 +177,64 @@ module OnnxRuntime
|
|
223
177
|
|
224
178
|
private
|
225
179
|
|
180
|
+
def load_session(path_or_bytes, session_options)
|
181
|
+
session = ::FFI::MemoryPointer.new(:pointer)
|
182
|
+
from_memory =
|
183
|
+
if path_or_bytes.respond_to?(:read)
|
184
|
+
path_or_bytes = path_or_bytes.read
|
185
|
+
true
|
186
|
+
else
|
187
|
+
path_or_bytes = path_or_bytes.to_str
|
188
|
+
# TODO remove ability to load byte string directly in 0.8.0
|
189
|
+
path_or_bytes.encoding == Encoding::BINARY
|
190
|
+
end
|
191
|
+
|
192
|
+
if from_memory
|
193
|
+
check_status api[:CreateSessionFromArray].call(env.read_pointer, path_or_bytes, path_or_bytes.bytesize, session_options.read_pointer, session)
|
194
|
+
else
|
195
|
+
check_status api[:CreateSession].call(env.read_pointer, ort_string(path_or_bytes), session_options.read_pointer, session)
|
196
|
+
end
|
197
|
+
session
|
198
|
+
end
|
199
|
+
|
200
|
+
def load_allocator
|
201
|
+
allocator = ::FFI::MemoryPointer.new(:pointer)
|
202
|
+
check_status api[:GetAllocatorWithDefaultOptions].call(allocator)
|
203
|
+
allocator
|
204
|
+
end
|
205
|
+
|
206
|
+
def load_inputs
|
207
|
+
inputs = []
|
208
|
+
num_input_nodes = ::FFI::MemoryPointer.new(:size_t)
|
209
|
+
check_status api[:SessionGetInputCount].call(read_pointer, num_input_nodes)
|
210
|
+
num_input_nodes.read(:size_t).times do |i|
|
211
|
+
name_ptr = ::FFI::MemoryPointer.new(:string)
|
212
|
+
check_status api[:SessionGetInputName].call(read_pointer, i, @allocator.read_pointer, name_ptr)
|
213
|
+
# freed in node_info
|
214
|
+
typeinfo = ::FFI::MemoryPointer.new(:pointer)
|
215
|
+
check_status api[:SessionGetInputTypeInfo].call(read_pointer, i, typeinfo)
|
216
|
+
inputs << {name: name_ptr.read_pointer.read_string}.merge(node_info(typeinfo))
|
217
|
+
allocator_free name_ptr
|
218
|
+
end
|
219
|
+
inputs
|
220
|
+
end
|
221
|
+
|
222
|
+
def load_outputs
|
223
|
+
outputs = []
|
224
|
+
num_output_nodes = ::FFI::MemoryPointer.new(:size_t)
|
225
|
+
check_status api[:SessionGetOutputCount].call(read_pointer, num_output_nodes)
|
226
|
+
num_output_nodes.read(:size_t).times do |i|
|
227
|
+
name_ptr = ::FFI::MemoryPointer.new(:string)
|
228
|
+
check_status api[:SessionGetOutputName].call(read_pointer, i, @allocator.read_pointer, name_ptr)
|
229
|
+
# freed in node_info
|
230
|
+
typeinfo = ::FFI::MemoryPointer.new(:pointer)
|
231
|
+
check_status api[:SessionGetOutputTypeInfo].call(read_pointer, i, typeinfo)
|
232
|
+
outputs << {name: name_ptr.read_pointer.read_string}.merge(node_info(typeinfo))
|
233
|
+
allocator_free name_ptr
|
234
|
+
end
|
235
|
+
outputs
|
236
|
+
end
|
237
|
+
|
226
238
|
def create_input_tensor(input_feed, refs)
|
227
239
|
allocator_info = ::FFI::MemoryPointer.new(:pointer)
|
228
240
|
check_status api[:CreateCpuMemoryInfo].call(1, 0, allocator_info)
|
@@ -325,7 +337,7 @@ module OnnxRuntime
|
|
325
337
|
check_status api[:GetTensorMutableData].call(out_ptr, tensor_data)
|
326
338
|
|
327
339
|
out_size = ::FFI::MemoryPointer.new(:size_t)
|
328
|
-
|
340
|
+
check_status api[:GetTensorShapeElementCount].call(typeinfo.read_pointer, out_size)
|
329
341
|
output_tensor_size = out_size.read(:size_t)
|
330
342
|
|
331
343
|
release :TensorTypeAndShapeInfo, typeinfo
|
data/lib/onnxruntime/version.rb
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: onnxruntime
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.4
|
5
5
|
platform: aarch64-linux
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|