class DNN::Layers::TrainableLayer

This class is a superclass of all classes with learning parameters.

Attributes

trainable[RW]

@return [Boolean] Setting false prevents learning of parameters.

Public Class Methods

new() click to toggle source
Calls superclass method DNN::Layers::Layer::new
# File lib/dnn/core/layers/basic_layers.rb, line 114
def initialize
  super()
  @trainable = true
end

Public Instance Methods

clean() click to toggle source
# File lib/dnn/core/layers/basic_layers.rb, line 124
def clean
  input_shape = @input_shape
  hash = to_hash
  params = get_params
  instance_variables.each do |ivar|
    instance_variable_set(ivar, nil)
  end
  load_hash(hash)
  build(input_shape)
  params.each do |(key, param)|
    param.data = nil
    param.grad = Xumo::SFloat[0] if param.grad
    instance_variable_set("@#{key}", param)
  end
end
get_params() click to toggle source

@return [Array] The parameters of the layer.

# File lib/dnn/core/layers/basic_layers.rb, line 120
def get_params
  raise NotImplementedError, "Class '#{self.class.name}' has implement method 'get_params'"
end