Class: DNN::Layers::Pool2D
- Includes:
- Conv2DUtils
- Defined in:
- lib/dnn/core/cnn_layers.rb
Overview
Super class of all pooling2D class.
Instance Attribute Summary collapse
-
#padding ⇒ Object
readonly
Returns the value of attribute padding.
-
#pool_size ⇒ Object
readonly
Returns the value of attribute pool_size.
-
#strides ⇒ Object
readonly
Returns the value of attribute strides.
Attributes inherited from Layer
Instance Method Summary collapse
- #build(input_shape) ⇒ Object
-
#initialize(pool_size, strides: nil, padding: false) ⇒ Pool2D
constructor
A new instance of Pool2D.
- #load_hash(hash) ⇒ Object
- #output_shape ⇒ Object
- #to_hash ⇒ Object
Methods inherited from Layer
#backward, #built?, #call, call, #forward, from_hash
Constructor Details
#initialize(pool_size, strides: nil, padding: false) ⇒ Pool2D
Returns a new instance of Pool2D.
304 305 306 307 308 309 310 311 312 313 |
# File 'lib/dnn/core/cnn_layers.rb', line 304 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.is_a?(Integer) ? [padding, padding] : padding end |
Instance Attribute Details
#padding ⇒ Object (readonly)
Returns the value of attribute padding.
298 299 300 |
# File 'lib/dnn/core/cnn_layers.rb', line 298 def padding @padding end |
#pool_size ⇒ Object (readonly)
Returns the value of attribute pool_size.
296 297 298 |
# File 'lib/dnn/core/cnn_layers.rb', line 296 def pool_size @pool_size end |
#strides ⇒ Object (readonly)
Returns the value of attribute strides.
297 298 299 |
# File 'lib/dnn/core/cnn_layers.rb', line 297 def strides @strides end |
Instance Method Details
#build(input_shape) ⇒ Object
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 |
# File 'lib/dnn/core/cnn_layers.rb', line 315 def build(input_shape) unless input_shape.length == 3 raise DNN_ShapeError, "Input shape is #{input_shape}. But input shape must be 3 dimensional." end super prev_h, prev_w = input_shape[0..1] @num_channel = input_shape[2] @pad_size = if @padding == true calc_conv2d_padding_size(prev_h, prev_w, *@pool_size, @strides) elsif @padding.is_a?(Array) @padding else [0, 0] end @out_size = calc_conv2d_out_size(prev_h, prev_w, *@pool_size, *@pad_size, @strides) end |
#load_hash(hash) ⇒ Object
342 343 344 |
# File 'lib/dnn/core/cnn_layers.rb', line 342 def load_hash(hash) initialize(hash[:pool_size], strides: hash[:strides], padding: hash[:padding]) end |
#output_shape ⇒ Object
332 333 334 |
# File 'lib/dnn/core/cnn_layers.rb', line 332 def output_shape [*@out_size, @num_channel] end |
#to_hash ⇒ Object
336 337 338 339 340 |
# File 'lib/dnn/core/cnn_layers.rb', line 336 def to_hash super(pool_size: @pool_size, strides: @strides, padding: @padding) end |