Class: DNN::Layers::Pool2D
- Includes:
- Conv2DModule
- Defined in:
- lib/dnn/core/cnn_layers.rb
Overview
Super class of all pooling2D class.
Instance Attribute Summary collapse
-
#pool_size ⇒ Object
readonly
Returns the value of attribute pool_size.
-
#strides ⇒ Object
readonly
Returns the value of attribute strides.
Class Method Summary collapse
Instance Method Summary collapse
- #build(model) ⇒ Object
-
#initialize(pool_size, strides: nil, padding: false) ⇒ Pool2D
constructor
A new instance of Pool2D.
- #shape ⇒ Object
- #to_hash ⇒ Object
Methods inherited from Layer
#backward, #built?, #forward, #prev_layer
Constructor Details
#initialize(pool_size, strides: nil, padding: false) ⇒ Pool2D
Returns a new instance of Pool2D.
160 161 162 163 164 165 166 167 168 169 |
# File 'lib/dnn/core/cnn_layers.rb', line 160 def initialize(pool_size, strides: nil, padding: false) super() @pool_size = pool_size.is_a?(Integer) ? [pool_size, pool_size] : pool_size @strides = if strides strides.is_a?(Integer) ? [strides, strides] : strides else @pool_size.clone end @padding = padding end |
Instance Attribute Details
#pool_size ⇒ Object (readonly)
Returns the value of attribute pool_size.
153 154 155 |
# File 'lib/dnn/core/cnn_layers.rb', line 153 def pool_size @pool_size end |
#strides ⇒ Object (readonly)
Returns the value of attribute strides.
154 155 156 |
# File 'lib/dnn/core/cnn_layers.rb', line 154 def strides @strides end |
Class Method Details
.load_hash(pool2d_class, hash) ⇒ Object
156 157 158 |
# File 'lib/dnn/core/cnn_layers.rb', line 156 def self.load_hash(pool2d_class, hash) pool2d_class.new(hash[:pool_size], strides: hash[:strides], padding: hash[:padding]) end |
Instance Method Details
#build(model) ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/dnn/core/cnn_layers.rb', line 171 def build(model) super prev_w, prev_h = prev_layer.shape[0..1] @num_channel = prev_layer.shape[2] @out_size = out_size(prev_h, prev_w, *@pool_size, @strides) out_w, out_h = @out_size if @padding @pad = [prev_h - out_h, prev_w - out_w] @out_size = [prev_h, prev_w] end end |
#shape ⇒ Object
183 184 185 |
# File 'lib/dnn/core/cnn_layers.rb', line 183 def shape [*@out_size, @num_channel] end |
#to_hash ⇒ Object
187 188 189 190 191 192 |
# File 'lib/dnn/core/cnn_layers.rb', line 187 def to_hash super({pool_width: @pool_width, pool_height: @pool_height, strides: @strides, padding: @padding}) end |