ruby-dnn 0.13.4 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/cifar100_example.rb +1 -2
- data/examples/cifar10_example.rb +1 -2
- data/examples/dcgan/dcgan.rb +19 -9
- data/examples/dcgan/imgen.rb +9 -2
- data/examples/dcgan/train.rb +7 -22
- data/examples/iris_example.rb +1 -2
- data/examples/mnist_conv2d_example.rb +1 -2
- data/examples/mnist_define_by_run.rb +1 -2
- data/examples/mnist_example.rb +1 -2
- data/examples/mnist_lstm_example.rb +1 -2
- data/examples/xor_example.rb +2 -3
- data/lib/dnn.rb +2 -0
- data/lib/dnn/core/activations.rb +11 -18
- data/lib/dnn/core/callbacks.rb +136 -0
- data/lib/dnn/core/cnn_layers.rb +26 -33
- data/lib/dnn/core/embedding.rb +20 -2
- data/lib/dnn/core/error.rb +0 -2
- data/lib/dnn/core/initializers.rb +2 -8
- data/lib/dnn/core/iterator.rb +17 -13
- data/lib/dnn/core/layers.rb +38 -34
- data/lib/dnn/core/link.rb +1 -2
- data/lib/dnn/core/losses.rb +21 -14
- data/lib/dnn/core/merge_layers.rb +7 -8
- data/lib/dnn/core/models.rb +134 -125
- data/lib/dnn/core/normalizations.rb +2 -2
- data/lib/dnn/core/optimizers.rb +20 -25
- data/lib/dnn/core/regularizers.rb +6 -7
- data/lib/dnn/core/rnn_layers.rb +15 -21
- data/lib/dnn/core/savers.rb +9 -7
- data/lib/dnn/core/tensor.rb +11 -0
- data/lib/dnn/core/utils.rb +1 -1
- data/lib/dnn/image.rb +22 -1
- data/lib/dnn/version.rb +1 -1
- metadata +4 -2
data/lib/dnn/core/utils.rb
CHANGED
data/lib/dnn/image.rb
CHANGED
@@ -14,6 +14,9 @@ module DNN
|
|
14
14
|
RGB = 3
|
15
15
|
RGBA = 4
|
16
16
|
|
17
|
+
# Read image from file.
|
18
|
+
# @param [String] file_name File name to read.
|
19
|
+
# @param [Integer] channel_type Specify channel type of image.
|
17
20
|
def self.read(file_name, channel_type = RGB)
|
18
21
|
raise ImageReadError.new("#{file_name} is not found.") unless File.exist?(file_name)
|
19
22
|
bin, w, h, n = Stb.stbi_load(file_name, channel_type)
|
@@ -22,6 +25,10 @@ module DNN
|
|
22
25
|
img.reshape(h, w, channel_type)
|
23
26
|
end
|
24
27
|
|
28
|
+
# Write image to file.
|
29
|
+
# @param [String] file_name File name to write.
|
30
|
+
# @param [Numo::UInt8] img Image to write.
|
31
|
+
# @param [Integer] quality Image quality when jpeg write.
|
25
32
|
def self.write(file_name, img, quality: 100)
|
26
33
|
img_check(img)
|
27
34
|
match_data = file_name.match(%r`(.*)/.+$`)
|
@@ -38,11 +45,17 @@ module DNN
|
|
38
45
|
when /\.bmp$/i
|
39
46
|
res = Stb.stbi_write_bmp(file_name, w, h, ch, bin)
|
40
47
|
when /\.jpg$/i, /\.jpeg/i
|
48
|
+
raise TypeError, "quality:#{quality.class} is not an instance of Integer class." unless quality.is_a?(Integer)
|
49
|
+
raise ArgumentError, "quality should be between 1 and 100." unless quality.between?(1, 100)
|
41
50
|
res = Stb.stbi_write_jpg(file_name, w, h, ch, bin, quality)
|
42
51
|
end
|
43
52
|
raise ImageWriteError.new("Image write failed.") if res == 0
|
44
53
|
end
|
45
54
|
|
55
|
+
# Resize the image.
|
56
|
+
# @param [Numo::UInt8] img Image to resize.
|
57
|
+
# @param [Integer] out_height Image height to resize.
|
58
|
+
# @param [Integer] out_width Image width to resize.
|
46
59
|
def self.resize(img, out_height, out_width)
|
47
60
|
img_check(img)
|
48
61
|
in_height, in_width, ch = *img.shape
|
@@ -51,12 +64,20 @@ module DNN
|
|
51
64
|
img2
|
52
65
|
end
|
53
66
|
|
67
|
+
# Trimming the image.
|
68
|
+
# @param [Numo::UInt8] img Image to resize.
|
69
|
+
# @param [Integer] y The begin y coordinate of the image to trimming.
|
70
|
+
# @param [Integer] x The begin x coordinate of the image to trimming.
|
71
|
+
# @param [Integer] height Image height to trimming.
|
72
|
+
# @param [Integer] width Image height to trimming.
|
54
73
|
def self.trim(img, y, x, height, width)
|
55
74
|
img_check(img)
|
56
75
|
img[y...(y + height), x...(x + width), true].clone
|
57
76
|
end
|
58
77
|
|
59
|
-
|
78
|
+
# Image convert to gray scale.
|
79
|
+
# @param [Numo::UInt8] img Image to gray scale.
|
80
|
+
def self.to_gray_scale(img)
|
60
81
|
img_check(img)
|
61
82
|
if img.shape[2] == RGB
|
62
83
|
x = Numo::SFloat.cast(img)
|
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.
|
4
|
+
version: 0.14.0
|
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-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: numo-narray
|
@@ -115,6 +115,7 @@ files:
|
|
115
115
|
- ext/rb_stb_image/rb_stb_image.c
|
116
116
|
- lib/dnn.rb
|
117
117
|
- lib/dnn/core/activations.rb
|
118
|
+
- lib/dnn/core/callbacks.rb
|
118
119
|
- lib/dnn/core/cnn_layers.rb
|
119
120
|
- lib/dnn/core/embedding.rb
|
120
121
|
- lib/dnn/core/error.rb
|
@@ -132,6 +133,7 @@ files:
|
|
132
133
|
- lib/dnn/core/regularizers.rb
|
133
134
|
- lib/dnn/core/rnn_layers.rb
|
134
135
|
- lib/dnn/core/savers.rb
|
136
|
+
- lib/dnn/core/tensor.rb
|
135
137
|
- lib/dnn/core/utils.rb
|
136
138
|
- lib/dnn/datasets/cifar10.rb
|
137
139
|
- lib/dnn/datasets/cifar100.rb
|