menoh 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/docs/tutorial.md +1 -1
- data/example/example_mnist.rb +1 -1
- data/example/example_mnist_with_block.rb +1 -1
- data/example/example_vgg16.rb +2 -2
- data/ext/menoh_native/menoh_ruby.c +44 -44
- data/ext/menoh_native/menoh_ruby.h +3 -3
- data/lib/menoh.rb +14 -18
- data/lib/menoh/version.rb +1 -1
- data/menoh.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5e483ff5c77e451a7e6384898da3460c098a098
|
4
|
+
data.tar.gz: 5277658d6ba5c471a6aee27c3c78afd0c6967018
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c230e3d4524c1568c9e50be0fc6043a6ddc7f8d92b55db353e16a86dc69734d3d6e589ca023e62575620c60ccddfa25cfd8b06c90d4ba61ac55f9d4d1267072
|
7
|
+
data.tar.gz: a3849a57262ac65c9df11cd0faaa598bcb3926588546f2b27bd1a8546bfe5a1d09c24135b5f4fec70974f1f71d15bd51e5cfe1bafc3997d38fbd8bc7943b95b6
|
data/README.md
CHANGED
@@ -77,4 +77,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
77
77
|
|
78
78
|
## Code of Conduct
|
79
79
|
|
80
|
-
Everyone interacting in the
|
80
|
+
Everyone interacting in the Menoh Ruby project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/pfnet-research/menoh-ruby/blob/master/CODE_OF_CONDUCT.md).
|
data/docs/tutorial.md
CHANGED
data/example/example_mnist.rb
CHANGED
data/example/example_vgg16.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'open-uri'
|
2
2
|
require 'rmagick'
|
3
3
|
require 'menoh'
|
4
|
-
|
4
|
+
|
5
5
|
# download dependencies
|
6
6
|
def download_file(url, output)
|
7
7
|
return if File.exist? output
|
@@ -45,8 +45,8 @@ model_opt = {
|
|
45
45
|
dims: [
|
46
46
|
image_list.length,
|
47
47
|
input_shape[:channel_num],
|
48
|
+
input_shape[:height],
|
48
49
|
input_shape[:width],
|
49
|
-
input_shape[:height]
|
50
50
|
]
|
51
51
|
}
|
52
52
|
],
|
@@ -164,57 +164,57 @@ static VALUE wrap_model_init(VALUE self, VALUE vonnx, VALUE option) {
|
|
164
164
|
rb_raise(rb_eStandardError, "invalid dimension length");
|
165
165
|
return Qnil;
|
166
166
|
}
|
167
|
+
}
|
167
168
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
169
|
+
// build variable provile table
|
170
|
+
ERROR_CHECK(menoh_build_variable_profile_table(
|
171
|
+
getModel(self)->vpt_builder, getModel(self)->model_data,
|
172
|
+
&(getModel(self)->variable_profile_table)),
|
173
|
+
rb_eStandardError);
|
173
174
|
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
175
|
+
// optimize
|
176
|
+
ERROR_CHECK(
|
177
|
+
menoh_model_data_optimize(getModel(self)->model_data,
|
178
|
+
getModel(self)->variable_profile_table),
|
179
|
+
rb_eStandardError);
|
179
180
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
181
|
+
// get model buildler
|
182
|
+
ERROR_CHECK(menoh_make_model_builder(getModel(self)->variable_profile_table,
|
183
|
+
&(getModel(self)->model_builder)),
|
184
|
+
rb_eStandardError);
|
184
185
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
// prepare input buffer
|
198
|
-
int32_t buffer_length = 1;
|
199
|
-
for (int32_t j = 0; j < dims_length; j++)
|
200
|
-
buffer_length *= NUM2INT(rb_ary_entry(vdims, j));
|
201
|
-
|
202
|
-
float *input_buff = (float *)ruby_xmalloc(sizeof(float) * buffer_length);
|
203
|
-
getModel(self)->input_buffs[i] = input_buff;
|
204
|
-
ERROR_CHECK(
|
205
|
-
menoh_model_builder_attach_external_buffer(
|
206
|
-
getModel(self)->model_builder, StringValueCStr(vname), input_buff),
|
207
|
-
rb_eStandardError);
|
208
|
-
}
|
186
|
+
// attach input buffer to model builder
|
187
|
+
getModel(self)->input_buffs =
|
188
|
+
(float **)ruby_xmalloc(sizeof(float **) * input_layer_num);
|
189
|
+
for (int32_t i = 0; i < input_layer_num; i++) {
|
190
|
+
VALUE vinput_layer = rb_ary_entry(vinput_layers, i);
|
191
|
+
VALUE vname =
|
192
|
+
rb_hash_aref(vinput_layer, rb_to_symbol(rb_str_new2("name")));
|
193
|
+
VALUE vdims =
|
194
|
+
rb_hash_aref(vinput_layer, rb_to_symbol(rb_str_new2("dims")));
|
195
|
+
int32_t dims_length =
|
196
|
+
NUM2INT(rb_funcall(vdims, rb_intern("length"), 0, NULL));
|
209
197
|
|
210
|
-
//
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
rb_eStandardError);
|
198
|
+
// prepare input buffer
|
199
|
+
int32_t buffer_length = 1;
|
200
|
+
for (int32_t j = 0; j < dims_length; j++)
|
201
|
+
buffer_length *= NUM2INT(rb_ary_entry(vdims, j));
|
215
202
|
|
216
|
-
|
203
|
+
float *input_buff = (float *)ruby_xmalloc(sizeof(float) * buffer_length);
|
204
|
+
getModel(self)->input_buffs[i] = input_buff;
|
205
|
+
ERROR_CHECK(
|
206
|
+
menoh_model_builder_attach_external_buffer(
|
207
|
+
getModel(self)->model_builder, StringValueCStr(vname), input_buff),
|
208
|
+
rb_eStandardError);
|
217
209
|
}
|
210
|
+
|
211
|
+
// build model
|
212
|
+
ERROR_CHECK(menoh_build_model(
|
213
|
+
getModel(self)->model_builder, getModel(self)->model_data,
|
214
|
+
StringValueCStr(vbackend), "", &(getModel(self)->model)),
|
215
|
+
rb_eStandardError);
|
216
|
+
|
217
|
+
return Qnil;
|
218
218
|
}
|
219
219
|
|
220
220
|
static VALUE wrap_model_run(VALUE self, VALUE dataset) {
|
data/lib/menoh.rb
CHANGED
@@ -4,35 +4,20 @@ require 'menoh/menoh_native'
|
|
4
4
|
module Menoh
|
5
5
|
class Menoh
|
6
6
|
def initialize(file)
|
7
|
-
|
8
|
-
raise "No such file : #{file}"
|
9
|
-
end
|
7
|
+
raise "No such file : #{file}" unless File.exist?(file)
|
10
8
|
|
11
9
|
native_init file
|
12
10
|
yield self if block_given?
|
13
11
|
end
|
14
12
|
|
15
13
|
def make_model(option)
|
16
|
-
if option[:backend].nil?
|
17
|
-
raise "Required ':backend' : #{option[:backend]}"
|
18
|
-
end
|
14
|
+
raise "Required ':backend' : #{option[:backend]}" if option[:backend].nil?
|
19
15
|
model = MenohModel.new self, option
|
20
16
|
yield model if block_given?
|
21
17
|
model
|
22
18
|
end
|
23
19
|
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def transpose(buffer, shape)
|
27
|
-
sliced_buffer = buffer.each_slice(buffer.length / shape[0]).to_a
|
28
|
-
if shape.length > 2
|
29
|
-
next_shape = shape.slice(1, a.length)
|
30
|
-
sliced_buffer = sliced_buffer.map { |buf| transpose buf, next_shape }
|
31
|
-
end
|
32
|
-
sliced_buffer
|
33
|
-
end
|
34
20
|
|
35
|
-
module Menoh
|
36
21
|
class MenohModel
|
37
22
|
def initialize(menoh, option)
|
38
23
|
if option[:input_layers].nil? || option[:input_layers].empty?
|
@@ -77,11 +62,22 @@ module Menoh
|
|
77
62
|
results.map do |raw|
|
78
63
|
buffer = raw[:data]
|
79
64
|
shape = raw[:shape]
|
80
|
-
raw[:data] =
|
65
|
+
raw[:data] = Util.reshape buffer, shape
|
81
66
|
end
|
82
67
|
|
83
68
|
yield results if block_given?
|
84
69
|
results
|
85
70
|
end
|
86
71
|
end
|
72
|
+
|
73
|
+
module Util
|
74
|
+
def self.reshape(buffer, shape)
|
75
|
+
sliced_buffer = buffer.each_slice(buffer.length / shape[0]).to_a
|
76
|
+
if shape.length > 2
|
77
|
+
next_shape = shape.slice(1, shape.length)
|
78
|
+
sliced_buffer = sliced_buffer.map { |buf| reshape buf, next_shape }
|
79
|
+
end
|
80
|
+
sliced_buffer
|
81
|
+
end
|
82
|
+
end
|
87
83
|
end
|
data/lib/menoh/version.rb
CHANGED
data/menoh.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |spec|
|
|
6
6
|
spec.name = 'menoh'
|
7
7
|
spec.version = Menoh::VERSION
|
8
8
|
spec.authors = ['Kunihiko MIYOSHI']
|
9
|
-
spec.email = ['
|
9
|
+
spec.email = ['menoh-oss@preferred.jp']
|
10
10
|
|
11
11
|
spec.summary = "Ruby binding of ONNX runtime engine 'Menoh'"
|
12
12
|
spec.description = "Ruby binding of ONNX runtime engine 'Menoh'"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: menoh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kunihiko MIYOSHI
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -82,7 +82,7 @@ dependencies:
|
|
82
82
|
version: '0'
|
83
83
|
description: Ruby binding of ONNX runtime engine 'Menoh'
|
84
84
|
email:
|
85
|
-
-
|
85
|
+
- menoh-oss@preferred.jp
|
86
86
|
executables: []
|
87
87
|
extensions:
|
88
88
|
- ext/menoh_native/extconf.rb
|