ruby-dnn 0.13.0 → 0.13.1
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/lib/dnn/core/activations.rb +1 -3
- data/lib/dnn/core/cnn_layers.rb +4 -7
- data/lib/dnn/core/losses.rb +1 -1
- data/lib/dnn/core/rnn_layers.rb +2 -2
- data/lib/dnn/core/savers.rb +5 -5
- 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: 58ef35a4277a86304c39350b743d308145da921fdc2db4308fa6ed208be47d93
|
4
|
+
data.tar.gz: b8238e52c849e222277284c20723c1a1ab72e70fed409ad1f2962a9ba93190b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd335af25c5d11745960364dc6096f18fbf78387358f5a1b24959328b001e87c3454132960133a74ba9cb81ac90f98e8d2663a9a9492b78d7a8558124471dc44
|
7
|
+
data.tar.gz: 132da9ac8fccee2c0de894543e2800b8066b75e746e4faed609594096e6d894a3938e69c0e1155056aef384dc522d39c647b9dfce8b9a5ceb659716f6ba961f0
|
data/lib/dnn/core/activations.rb
CHANGED
data/lib/dnn/core/cnn_layers.rb
CHANGED
@@ -353,15 +353,14 @@ module DNN
|
|
353
353
|
x = zero_padding(x, @pad_size) if @padding
|
354
354
|
@x_shape = x.shape
|
355
355
|
col = im2col(x, *@out_size, *@pool_size, @strides)
|
356
|
-
col = col.reshape(x.shape[0] * @out_size.reduce(:*), @pool_size.reduce(:*), x.shape[3])
|
357
|
-
.reshape(x.shape[0] * @out_size.reduce(:*) * x.shape[3], @pool_size.reduce(:*))
|
356
|
+
col = col.reshape(x.shape[0] * @out_size.reduce(:*), @pool_size.reduce(:*), x.shape[3])
|
358
357
|
@max_index = col.max_index(1)
|
359
358
|
col.max(1).reshape(x.shape[0], *@out_size, x.shape[3])
|
360
359
|
end
|
361
360
|
|
362
361
|
def backward(dy)
|
363
362
|
dmax = Xumo::SFloat.zeros(dy.size * @pool_size.reduce(:*))
|
364
|
-
dmax[@max_index] = dy.flatten
|
363
|
+
dmax[@max_index.flatten] = dy.flatten
|
365
364
|
dcol = dmax.reshape(dy.shape[0..2].reduce(:*), @pool_size.reduce(:*) * dy.shape[3])
|
366
365
|
dx = col2im(dcol, @x_shape, *@out_size, *@pool_size, @strides)
|
367
366
|
@padding ? zero_padding_bwd(dx, @pad_size) : dx
|
@@ -374,8 +373,7 @@ module DNN
|
|
374
373
|
x = zero_padding(x, @pad_size) if @padding
|
375
374
|
@x_shape = x.shape
|
376
375
|
col = im2col(x, *@out_size, *@pool_size, @strides)
|
377
|
-
col = col.reshape(x.shape[0] * @out_size.reduce(:*), @pool_size.reduce(:*), x.shape[3])
|
378
|
-
.reshape(x.shape[0] * @out_size.reduce(:*) * x.shape[3], @pool_size.reduce(:*))
|
376
|
+
col = col.reshape(x.shape[0] * @out_size.reduce(:*), @pool_size.reduce(:*), x.shape[3])
|
379
377
|
col.mean(1).reshape(x.shape[0], *@out_size, x.shape[3])
|
380
378
|
end
|
381
379
|
|
@@ -436,8 +434,7 @@ module DNN
|
|
436
434
|
def backward(dy)
|
437
435
|
in_size = input_shape[0..1]
|
438
436
|
col = im2col(dy, *in_size, *@unpool_size, @unpool_size)
|
439
|
-
col = col.reshape(dy.shape[0] * in_size.reduce(:*), @unpool_size.reduce(:*), dy.shape[3])
|
440
|
-
.reshape(dy.shape[0] * in_size.reduce(:*) * dy.shape[3], @unpool_size.reduce(:*))
|
437
|
+
col = col.reshape(dy.shape[0] * in_size.reduce(:*), @unpool_size.reduce(:*), dy.shape[3])
|
441
438
|
col.sum(1).reshape(dy.shape[0], *in_size, dy.shape[3])
|
442
439
|
end
|
443
440
|
|
data/lib/dnn/core/losses.rb
CHANGED
data/lib/dnn/core/rnn_layers.rb
CHANGED
@@ -81,7 +81,7 @@ module DNN
|
|
81
81
|
end
|
82
82
|
dxs = Xumo::SFloat.zeros(@xs_shape)
|
83
83
|
dh = 0
|
84
|
-
(
|
84
|
+
(dh2s.shape[1] - 1).downto(0) do |t|
|
85
85
|
dh2 = dh2s[true, t, false]
|
86
86
|
dx, dh = @layers[t].backward(dh2 + dh)
|
87
87
|
dxs[true, t, false] = dx
|
@@ -341,7 +341,7 @@ module DNN
|
|
341
341
|
dxs = Xumo::SFloat.zeros(@xs_shape)
|
342
342
|
dh = 0
|
343
343
|
dc = 0
|
344
|
-
(
|
344
|
+
(dh2s.shape[1] - 1).downto(0) do |t|
|
345
345
|
dh2 = dh2s[true, t, false]
|
346
346
|
dx, dh, dc = @layers[t].backward(dh2 + dh, dc)
|
347
347
|
dxs[true, t, false] = dx
|
data/lib/dnn/core/savers.rb
CHANGED
@@ -55,10 +55,10 @@ module DNN
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def base64_to_params_data(base64_params_data)
|
58
|
-
params_data = base64_params_data.
|
58
|
+
params_data = base64_params_data.to_h do |key, (shape, base64_data)|
|
59
59
|
bin = Base64.decode64(base64_data)
|
60
60
|
[key, Xumo::SFloat.from_binary(bin).reshape(*shape)]
|
61
|
-
|
61
|
+
end
|
62
62
|
set_all_params_data(params_data)
|
63
63
|
end
|
64
64
|
end
|
@@ -94,7 +94,7 @@ module DNN
|
|
94
94
|
all_params = @model.has_param_layers.uniq.map { |layer|
|
95
95
|
layer.get_params.values
|
96
96
|
}.flatten
|
97
|
-
all_params.
|
97
|
+
all_params.to_h { |param| [param.name, param.data] }
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
@@ -127,10 +127,10 @@ module DNN
|
|
127
127
|
end
|
128
128
|
|
129
129
|
def params_data_to_base64
|
130
|
-
get_all_params_data.
|
130
|
+
get_all_params_data.to_h do |key, data|
|
131
131
|
base64_data = Base64.encode64(data.to_binary)
|
132
132
|
[key, [data.shape, base64_data]]
|
133
|
-
|
133
|
+
end
|
134
134
|
end
|
135
135
|
end
|
136
136
|
|
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.13.
|
4
|
+
version: 0.13.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- unagiootoro
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-09-
|
11
|
+
date: 2019-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: numo-narray
|