Class: DNN::Layers::InputLayer
- Inherits:
-
Layer
- Object
- Layer
- DNN::Layers::InputLayer
show all
- Defined in:
- lib/dnn/core/layers/basic_layers.rb
Instance Attribute Summary
Attributes inherited from Layer
#input_shape, #output_shape
Instance Method Summary
collapse
Methods inherited from Layer
#built?, #call, call, #clean, #compute_output_shape, from_hash
Constructor Details
#initialize(input_dim_or_shape) ⇒ InputLayer
Returns a new instance of InputLayer.
137
138
139
140
|
# File 'lib/dnn/core/layers/basic_layers.rb', line 137
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
|
Instance Method Details
#<<(layer) ⇒ Object
164
165
166
167
168
169
|
# File 'lib/dnn/core/layers/basic_layers.rb', line 164
def <<(layer)
if RUBY_VERSION < "2.6.0"
raise DNNError, "Function composition is not supported before ruby version 2.6.0."
end
to_proc << layer
end
|
#>>(layer) ⇒ Object
157
158
159
160
161
162
|
# File 'lib/dnn/core/layers/basic_layers.rb', line 157
def >>(layer)
if RUBY_VERSION < "2.6.0"
raise DNNError, "Function composition is not supported before ruby version 2.6.0."
end
to_proc >> layer
end
|
#build(input_shape) ⇒ Object
142
143
144
|
# File 'lib/dnn/core/layers/basic_layers.rb', line 142
def build(input_shape)
super(@input_shape)
end
|
#forward(x) ⇒ Object
146
147
148
149
150
151
|
# File 'lib/dnn/core/layers/basic_layers.rb', line 146
def forward(x)
unless x.shape[1..-1] == @input_shape
raise DNNShapeError, "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
|
#load_hash(hash) ⇒ Object
175
176
177
|
# File 'lib/dnn/core/layers/basic_layers.rb', line 175
def load_hash(hash)
initialize(hash[:input_shape])
end
|
#to_hash ⇒ Object
171
172
173
|
# File 'lib/dnn/core/layers/basic_layers.rb', line 171
def to_hash
super(input_shape: @input_shape)
end
|
#to_proc ⇒ Object
153
154
155
|
# File 'lib/dnn/core/layers/basic_layers.rb', line 153
def to_proc
method(:call).to_proc
end
|