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.



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

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



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

def build(input_shape)
  super(@input_shape)
end

#forward(x) ⇒ Object



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

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



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

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

#to_hashObject



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

def to_hash
  super(input_shape: @input_shape)
end

#to_procObject



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

def to_proc
  method(:call).to_proc
end