Class: DNN::Models::Sequential

Inherits:
Model
  • Object
show all
Defined in:
lib/dnn/core/models.rb

Instance Attribute Summary collapse

Attributes inherited from Model

#loss_func, #optimizer

Instance Method Summary collapse

Methods inherited from Model

#accuracy, #add_callback, #built?, #clear_callbacks, #copy, #get_layer, #has_param_layers, #layers, load, #load_hash_params, #load_json_params, #predict, #predict1, #save, #setup, #test_on_batch, #train, #train_on_batch

Constructor Details

#initialize(stack = []) ⇒ Sequential

Returns a new instance of Sequential.

Parameters:

  • stack (Array) (defaults to: [])

    All layers possessed by the model.



356
357
358
359
# File 'lib/dnn/core/models.rb', line 356

def initialize(stack = [])
  super()
  @stack = stack.clone
end

Instance Attribute Details

#stackObject (readonly)

Returns the value of attribute stack.



353
354
355
# File 'lib/dnn/core/models.rb', line 353

def stack
  @stack
end

Instance Method Details

#add(layer) ⇒ DNN::Models::Model Also known as: <<

Add layer to the model.

Parameters:

Returns:



364
365
366
367
368
369
370
# File 'lib/dnn/core/models.rb', line 364

def add(layer)
  unless layer.is_a?(Layers::Layer) || layer.is_a?(Model)
    raise TypeError.new("layer: #{layer.class.name} is not an instance of the DNN::Layers::Layer class or DNN::Models::Model class.")
  end
  @stack << layer
  self
end

#call(x) ⇒ Object



384
385
386
387
388
389
# File 'lib/dnn/core/models.rb', line 384

def call(x)
  @stack.each do |layer|
    x = layer.(x)
  end
  x
end

#remove(layer) ⇒ Boolean

Remove layer to the model.

Parameters:

Returns:

  • (Boolean)

    Return true if success for remove layer.



377
378
379
380
381
382
# File 'lib/dnn/core/models.rb', line 377

def remove(layer)
  unless layer.is_a?(Layers::Layer) || layer.is_a?(Model)
    raise TypeError.new("layer: #{layer.class.name} is not an instance of the DNN::Layers::Layer class or DNN::Models::Model class.")
  end
  @stack.delete(layer) ? true : false
end