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.
@@ -23,7 +23,7 @@ module DNN
23
23
 
24
24
  # Return the result of the sigmoid function.
25
25
  def self.sigmoid(x)
26
- Activations::Sigmoid.new.forward(x)
26
+ Layers::Sigmoid.new.forward(x)
27
27
  end
28
28
 
29
29
  # Return the result of the softmax function.
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
- def self.gray_scale(img)
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
@@ -1,3 +1,3 @@
1
1
  module DNN
2
- VERSION = "0.13.4"
2
+ VERSION = "0.14.0"
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.13.4
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-12 00:00:00.000000000 Z
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