Class: DNN::Models::Sequential

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

Instance Attribute Summary collapse

Attributes inherited from Model

#last_log, #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, #predict, #predict1, #save, #setup, #test_on_batch, #train, #train_by_iterator, #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.



371
372
373
374
# File 'lib/dnn/core/models.rb', line 371

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

Instance Attribute Details

#stackObject (readonly)

Returns the value of attribute stack.



368
369
370
# File 'lib/dnn/core/models.rb', line 368

def stack
  @stack
end

Instance Method Details

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

Add layer to the model.

Parameters:

Returns:



379
380
381
382
383
384
385
# File 'lib/dnn/core/models.rb', line 379

def add(layer)
  unless layer.is_a?(Layers::Layer) || layer.is_a?(Model)
    raise TypeError, "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



399
400
401
402
403
404
# File 'lib/dnn/core/models.rb', line 399

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.



392
393
394
395
396
397
# File 'lib/dnn/core/models.rb', line 392

def remove(layer)
  unless layer.is_a?(Layers::Layer) || layer.is_a?(Model)
    raise TypeError, "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