Class: DNN::Layers::InputLayer

Inherits:
Layer
  • Object
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.

Parameters:

  • input_dim_or_shape (Array)

    Setting the shape or dimension of the input data.



142
143
144
145
# File 'lib/dnn/core/layers/basic_layers.rb', line 142

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

#build(input_shape) ⇒ Object



147
148
149
# File 'lib/dnn/core/layers/basic_layers.rb', line 147

def build(input_shape)
  super(@input_shape)
end

#forward(x) ⇒ Object



151
152
153
154
155
156
# File 'lib/dnn/core/layers/basic_layers.rb', line 151

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



166
167
168
# File 'lib/dnn/core/layers/basic_layers.rb', line 166

def load_hash(hash)
  initialize(hash[:input_shape])
end

#to_hashObject



162
163
164
# File 'lib/dnn/core/layers/basic_layers.rb', line 162

def to_hash
  super(input_shape: @input_shape)
end

#to_procObject



158
159
160
# File 'lib/dnn/core/layers/basic_layers.rb', line 158

def to_proc
  method(:call).to_proc
end