ruby-dnn 0.14.1 → 0.14.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/api-examples/save_example.rb +1 -1
- data/lib/dnn/core/losses.rb +1 -1
- data/lib/dnn/core/models.rb +3 -3
- data/lib/dnn/image.rb +8 -4
- 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: 26d153a8ef243d2a069fd5b48a08e0216c28d8dd0307f570fce2ef146eef3cfe
|
4
|
+
data.tar.gz: 9130ce3f31d2e7b5b3a3ecb48d9e4e10cddd307b2f900e13799206f8b16c3022
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6167f81c1c7c76ae0539d17e9f9d252f03b603a15ee376cf91d0aa620d8d60aa5f434d3587f3331221679f661d22978207564d60a7ae59cf22551c482beb62c
|
7
|
+
data.tar.gz: 0ab323a64dd7d68692c901257fa38981355c6533eb106a76ed1f4072c4d338bb4c5c72b0a4db2704c146ae49b827c75f45b79db924cdde92352f72f332bd7c9c
|
@@ -76,7 +76,7 @@ model2 = MLP.new
|
|
76
76
|
if SAVE_STYLE == USE_MARSHAL
|
77
77
|
loader = MarshalLoader.new(model2)
|
78
78
|
loader.load("trained_mnist.marshal")
|
79
|
-
# MLP.load("trained_mnist.marshal") # This code is equivalent to the code above.
|
79
|
+
# model2 = MLP.load("trained_mnist.marshal") # This code is equivalent to the code above.
|
80
80
|
elsif SAVE_STYLE == USE_JSON
|
81
81
|
loader = JSONLoader.new(model2)
|
82
82
|
loader.load("trained_mnist.json")
|
data/lib/dnn/core/losses.rb
CHANGED
@@ -174,7 +174,7 @@ module DNN
|
|
174
174
|
|
175
175
|
def forward(y, t)
|
176
176
|
@x = SigmoidCrossEntropy.sigmoid(y)
|
177
|
-
-(t * Xumo::NMath.log(@x) + (1 - t) * Xumo::NMath.log(1 - @x))
|
177
|
+
-(t * Xumo::NMath.log(@x + @eps) + (1 - t) * Xumo::NMath.log(1 - @x + @eps))
|
178
178
|
end
|
179
179
|
|
180
180
|
def backward(y, t)
|
data/lib/dnn/core/models.rb
CHANGED
@@ -145,7 +145,7 @@ module DNN
|
|
145
145
|
# @return [Hash] Hash of contents to be output to log.
|
146
146
|
private def test(x, y, batch_size: 100)
|
147
147
|
acc, test_loss = accuracy(x, y, batch_size: batch_size)
|
148
|
-
{ accuracy: acc, test_loss: test_loss
|
148
|
+
{ accuracy: acc, test_loss: test_loss }
|
149
149
|
end
|
150
150
|
|
151
151
|
# Training once.
|
@@ -180,7 +180,7 @@ module DNN
|
|
180
180
|
batch_size = batch_size >= num_test_datas[0] ? num_test_datas : batch_size
|
181
181
|
iter = Iterator.new(x, y, random: false)
|
182
182
|
total_correct = 0
|
183
|
-
sum_loss =
|
183
|
+
sum_loss = 0
|
184
184
|
max_steps = (num_test_datas.to_f / batch_size).ceil
|
185
185
|
iter.foreach(batch_size) do |x_batch, y_batch|
|
186
186
|
correct, loss_value = test_on_batch(x_batch, y_batch)
|
@@ -202,7 +202,7 @@ module DNN
|
|
202
202
|
call_callbacks(:before_test_on_batch)
|
203
203
|
x = forward(x, false)
|
204
204
|
correct = evaluate(x, y)
|
205
|
-
loss_value = @loss_func.loss(x, y
|
205
|
+
loss_value = @loss_func.loss(x, y)
|
206
206
|
call_callbacks(:after_test_on_batch)
|
207
207
|
[correct, loss_value]
|
208
208
|
end
|
data/lib/dnn/image.rb
CHANGED
@@ -37,7 +37,6 @@ module DNN
|
|
37
37
|
Dir.mkdir(dir_name) unless Dir.exist?(dir_name)
|
38
38
|
end
|
39
39
|
h, w, ch = img.shape
|
40
|
-
bin = img.to_binary
|
41
40
|
match_data = file_name.match(/\.(\w+)$/i)
|
42
41
|
if match_data
|
43
42
|
ext = match_data[1]
|
@@ -47,13 +46,18 @@ module DNN
|
|
47
46
|
case ext
|
48
47
|
when "png"
|
49
48
|
stride_in_bytes = w * ch
|
50
|
-
res = Stb.stbi_write_png(file_name, w, h, ch,
|
49
|
+
res = Stb.stbi_write_png(file_name, w, h, ch, img.to_binary, stride_in_bytes)
|
51
50
|
when "bmp"
|
52
|
-
res = Stb.stbi_write_bmp(file_name, w, h, ch,
|
51
|
+
res = Stb.stbi_write_bmp(file_name, w, h, ch, img.to_binary)
|
53
52
|
when "jpg", "jpeg"
|
54
53
|
raise TypeError, "quality:#{quality.class} is not an instance of Integer class." unless quality.is_a?(Integer)
|
55
54
|
raise ArgumentError, "quality should be between 1 and 100." unless quality.between?(1, 100)
|
56
|
-
res = Stb.stbi_write_jpg(file_name, w, h, ch,
|
55
|
+
res = Stb.stbi_write_jpg(file_name, w, h, ch, img.to_binary, quality)
|
56
|
+
when "hdr"
|
57
|
+
float_img = Numo::SFloat.cast(img) / 255
|
58
|
+
res = Stb.stbi_write_hdr(file_name, w, h, ch, float_img.to_binary)
|
59
|
+
when "tga"
|
60
|
+
res = Stb.stbi_write_tga(file_name, w, h, ch, img.to_binary)
|
57
61
|
else
|
58
62
|
raise ImageWriteError, "Extension '#{ext}' is not support."
|
59
63
|
end
|
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.14.
|
4
|
+
version: 0.14.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- unagiootoro
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-10-
|
11
|
+
date: 2019-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: numo-narray
|