Class: DNN::Layers::InputLayer
- Inherits:
-
Layer
- Object
- Layer
- DNN::Layers::InputLayer
show all
- Defined in:
- lib/dnn/core/layers.rb
Instance Attribute Summary
Attributes inherited from Layer
#input_shape, #name
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Layer
#built?, from_hash, #output_shape
Constructor Details
#initialize(input_dim_or_shape) ⇒ InputLayer
Returns a new instance of InputLayer.
105
106
107
108
|
# File 'lib/dnn/core/layers.rb', line 105
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
99
100
101
102
|
# File 'lib/dnn/core/layers.rb', line 99
def self.call(input)
shape = input.is_a?(Array) ? input[0].shape : input.shape
self.new(shape[1..-1]).(input)
end
|
Instance Method Details
#backward(dy) ⇒ Object
133
134
135
|
# File 'lib/dnn/core/layers.rb', line 133
def backward(dy)
dy
end
|
#build ⇒ Object
122
123
124
|
# File 'lib/dnn/core/layers.rb', line 122
def build
@built = true
end
|
#call(input) ⇒ Object
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/dnn/core/layers.rb', line 110
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
126
127
128
129
130
131
|
# File 'lib/dnn/core/layers.rb', line 126
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
|
#load_hash(hash) ⇒ Object
141
142
143
|
# File 'lib/dnn/core/layers.rb', line 141
def load_hash(hash)
initialize(hash[:input_shape])
end
|
#to_hash ⇒ Object
137
138
139
|
# File 'lib/dnn/core/layers.rb', line 137
def to_hash
super(input_shape: @input_shape)
end
|