ruby-dnn 0.6.3 → 0.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/API-Reference.ja.md +7 -4
- data/lib/dnn/core/layers.rb +5 -3
- data/lib/dnn/core/model.rb +5 -3
- data/lib/dnn/ext/rb_stb_image/rb_stb_image.c +0 -3
- data/lib/dnn/lib/image_io.rb +3 -3
- data/lib/dnn/version.rb +1 -1
- 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: e7500fad8921cbb1efca407a3dac06aee005257e96403654a0047acd1f05bd91
|
4
|
+
data.tar.gz: 6b2177271b189de689130e75848b92fe747c9b995cc90d16fe2d656102753fb7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dba263057f0ac42d515bfac8ba26c33898329d3ab7e29132f498110eaad22660a2ac8e1b2e9f537ed226c5da07561332ca327123857941598ea7f666fb2d2392
|
7
|
+
data.tar.gz: 3a771401278c68385c9e4a163caee00ffa380ac71ca545ccb500b503c6a92afefb8ca93aa4216dd6783cf10c5187eaa353b916618879e8275b3997a479926117
|
data/API-Reference.ja.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
ruby-dnnのAPIリファレンスです。このリファレンスでは、APIを利用するうえで必要となるクラスとメソッドしか記載していません。
|
3
3
|
そのため、プログラムの詳細が必要な場合は、ソースコードを参照してください。
|
4
4
|
|
5
|
-
最終更新バージョン:0.6.
|
5
|
+
最終更新バージョン:0.6.4
|
6
6
|
|
7
7
|
# module DNN
|
8
8
|
ruby-dnnの名前空間をなすモジュールです。
|
@@ -12,17 +12,20 @@ ruby-dnnの名前空間をなすモジュールです。
|
|
12
12
|
## VERSION
|
13
13
|
ruby-dnnのバージョン。
|
14
14
|
|
15
|
+
# class Model
|
16
|
+
ニューラルネットワークのモデルを作成するクラスです。
|
17
|
+
|
15
18
|
## 【Properties】
|
16
19
|
|
17
20
|
## attr_accessor :layer
|
18
21
|
モデルに追加されたレイヤーの配列を取得します。
|
19
22
|
|
23
|
+
## attr_accessor :trainable
|
24
|
+
falseを設定すると、パラメータの学習を禁止します。
|
25
|
+
|
20
26
|
## attr_reader :optimize
|
21
27
|
モデルのオプティマイザーを取得します。
|
22
28
|
|
23
|
-
# class Model
|
24
|
-
ニューラルネットワークのモデルを作成するクラスです。
|
25
|
-
|
26
29
|
## 【Singleton methods】
|
27
30
|
|
28
31
|
## def self.load(file_name)
|
data/lib/dnn/core/layers.rb
CHANGED
@@ -45,13 +45,15 @@ module DNN
|
|
45
45
|
|
46
46
|
# This class is a superclass of all classes with learning parameters.
|
47
47
|
class HasParamLayer < Layer
|
48
|
-
|
49
|
-
attr_reader :
|
48
|
+
attr_accessor :trainable # Setting false prevents learning of parameters.
|
49
|
+
attr_reader :params # The parameters of the layer.
|
50
|
+
attr_reader :grads # Differential value of parameter of layer.
|
50
51
|
|
51
52
|
def initialize
|
52
53
|
super
|
53
54
|
@params = {}
|
54
55
|
@grads = {}
|
56
|
+
@trainable = true
|
55
57
|
end
|
56
58
|
|
57
59
|
def build(model)
|
@@ -61,7 +63,7 @@ module DNN
|
|
61
63
|
|
62
64
|
# Update the parameters.
|
63
65
|
def update
|
64
|
-
@model.optimizer.update(self)
|
66
|
+
@model.optimizer.update(self) if @trainable
|
65
67
|
end
|
66
68
|
|
67
69
|
private
|
data/lib/dnn/core/model.rb
CHANGED
@@ -3,8 +3,9 @@ require "json"
|
|
3
3
|
module DNN
|
4
4
|
# This class deals with the model of the network.
|
5
5
|
class Model
|
6
|
-
attr_accessor :layers
|
7
|
-
|
6
|
+
attr_accessor :layers # All layers possessed by the model
|
7
|
+
attr_accessor :trainable # Setting false prevents learning of parameters.
|
8
|
+
attr_reader :optimizer # Optimizer possessed by the model
|
8
9
|
|
9
10
|
def self.load(file_name)
|
10
11
|
Marshal.load(File.binread(file_name))
|
@@ -20,6 +21,7 @@ module DNN
|
|
20
21
|
|
21
22
|
def initialize
|
22
23
|
@layers = []
|
24
|
+
@trainable = true
|
23
25
|
@optimizer = nil
|
24
26
|
@training = false
|
25
27
|
@compiled = false
|
@@ -140,7 +142,7 @@ module DNN
|
|
140
142
|
forward(x, true)
|
141
143
|
loss = @layers[-1].loss(y)
|
142
144
|
backward(y)
|
143
|
-
@layers.each { |layer| layer.update if layer.
|
145
|
+
@layers.each { |layer| layer.update if @trainable && layer.is_a?(HasParamLayer) }
|
144
146
|
loss
|
145
147
|
end
|
146
148
|
|
@@ -37,7 +37,6 @@ VALUE rb_stbi_write_png(VALUE self, VALUE rb_filename, VALUE rb_w, VALUE rb_h, V
|
|
37
37
|
int result;
|
38
38
|
|
39
39
|
result = stbi_write_png(filename, w, h, comp, data, stride_in_bytes);
|
40
|
-
stbi_image_free(data);
|
41
40
|
return INT2FIX(result);
|
42
41
|
}
|
43
42
|
|
@@ -51,7 +50,6 @@ VALUE rb_stbi_write_bmp(VALUE self, VALUE rb_filename, VALUE rb_w, VALUE rb_h, V
|
|
51
50
|
int result;
|
52
51
|
|
53
52
|
result = stbi_write_bmp(filename, w, h, comp, data);
|
54
|
-
stbi_image_free(data);
|
55
53
|
return INT2FIX(result);
|
56
54
|
}
|
57
55
|
|
@@ -66,7 +64,6 @@ VALUE rb_stbi_write_jpg(VALUE self, VALUE rb_filename, VALUE rb_w, VALUE rb_h, V
|
|
66
64
|
int result;
|
67
65
|
|
68
66
|
result = stbi_write_jpg(filename, w, h, comp, data, quality);
|
69
|
-
stbi_image_free(data);
|
70
67
|
return INT2FIX(result);
|
71
68
|
}
|
72
69
|
|
data/lib/dnn/lib/image_io.rb
CHANGED
@@ -20,12 +20,12 @@ module DNN
|
|
20
20
|
h, w, ch = img.shape
|
21
21
|
bin = img.to_binary
|
22
22
|
case file_name
|
23
|
-
when /\.png$/
|
23
|
+
when /\.png$/i
|
24
24
|
stride_in_bytes = w * ch
|
25
25
|
Stb.stbi_write_png(file_name, w, h, ch, bin, stride_in_bytes)
|
26
|
-
when /\.bmp$/
|
26
|
+
when /\.bmp$/i
|
27
27
|
Stb.stbi_write_bmp(file_name, w, h, ch, bin)
|
28
|
-
when /\.jpg$/
|
28
|
+
when /\.jpg$/i, /\.jpeg/i
|
29
29
|
Stb.stbi_write_jpg(file_name, w, h, ch, bin, quality)
|
30
30
|
end
|
31
31
|
rescue => ex
|
data/lib/dnn/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-dnn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- unagiootoro
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: numo-narray
|