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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 83bf68ae55435acfd33ccebf5798252ad670c7047f31de52c5b1951e0d0064f0
4
- data.tar.gz: 63edb99dcafd2abb6b66f09a5fe44ada8e50f2674b56af2d3b3100980ba6e841
3
+ metadata.gz: e7500fad8921cbb1efca407a3dac06aee005257e96403654a0047acd1f05bd91
4
+ data.tar.gz: 6b2177271b189de689130e75848b92fe747c9b995cc90d16fe2d656102753fb7
5
5
  SHA512:
6
- metadata.gz: 78baa0705d6062f066d132f46c500277daf03957ddaa4e7530c9f75b8bfcc08d0d4ac6ffd3130d8cbf7e01b32ce6a1e60ab1b046af9ed187c2b658d6ee71bb8e
7
- data.tar.gz: ae2930b1fcccd676f3e3273e0031c63888fe264d069c2e6c16aeb9c7def9a8bf5e05e2de2ee9265d2ce1e633c964e0b91843b3e2c0fa845428c77db09c9a05cd
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.2
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)
@@ -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
- attr_reader :params # The parameters of the layer.
49
- attr_reader :grads # Differential value of parameter of layer.
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
@@ -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
- attr_reader :optimizer
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.respond_to?(:update) }
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
 
@@ -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
@@ -1,3 +1,3 @@
1
1
  module DNN
2
- VERSION = "0.6.3"
2
+ VERSION = "0.6.4"
3
3
  end
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.3
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-19 00:00:00.000000000 Z
11
+ date: 2018-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: numo-narray