Class: DNN::Layers::InputLayer
Instance Attribute Summary
Attributes inherited from Layer
Class Method Summary collapse
Instance Method Summary collapse
- #backward(dy) ⇒ Object
- #build ⇒ Object
- #call(input) ⇒ Object
- #forward(x) ⇒ Object
-
#initialize(input_dim_or_shape) ⇒ InputLayer
constructor
A new instance of InputLayer.
- #to_hash ⇒ Object
Methods inherited from Layer
Constructor Details
#initialize(input_dim_or_shape) ⇒ InputLayer
Returns a new instance of InputLayer.
95 96 97 98 |
# File 'lib/dnn/core/layers.rb', line 95 def initialize(input_dim_or_shape) super() @input_shape = input_dim_or_shape.is_a?(Array) ? input_dim_or_shape : [input_dim_or_shape] end |
Class Method Details
.call(input) ⇒ Object
85 86 87 88 |
# File 'lib/dnn/core/layers.rb', line 85 def self.call(input) shape = input.is_a?(Array) ? input[0].shape : input.shape self.new(shape[1..-1]).(input) end |
.from_hash(hash) ⇒ Object
90 91 92 |
# File 'lib/dnn/core/layers.rb', line 90 def self.from_hash(hash) self.new(hash[:input_shape]) end |
Instance Method Details
#backward(dy) ⇒ Object
123 124 125 |
# File 'lib/dnn/core/layers.rb', line 123 def backward(dy) dy end |
#build ⇒ Object
112 113 114 |
# File 'lib/dnn/core/layers.rb', line 112 def build @built = true end |
#call(input) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/dnn/core/layers.rb', line 100 def call(input) build unless built? if input.is_a?(Array) x, prev_link = *input else x = input prev_link = nil end link = prev_link ? Link.new(prev_link, self) : Link.new(nil, self) [forward(x), link] end |
#forward(x) ⇒ Object
116 117 118 119 120 121 |
# File 'lib/dnn/core/layers.rb', line 116 def forward(x) unless x.shape[1..-1] == @input_shape raise DNN_ShapeError.new("The shape of x does not match the input shape. input shape is #{@input_shape}, but x shape is #{x.shape[1..-1]}.") end x end |
#to_hash ⇒ Object
127 128 129 |
# File 'lib/dnn/core/layers.rb', line 127 def to_hash super(input_shape: @input_shape) end |