Class: DNN::Models::Sequential
- Defined in:
- lib/dnn/core/models.rb
Instance Attribute Summary collapse
-
#stack ⇒ Object
readonly
Returns the value of attribute stack.
Attributes inherited from Model
#last_log, #loss_func, #optimizer
Instance Method Summary collapse
-
#add(layer) ⇒ DNN::Models::Model
(also: #<<)
Add layer to the model.
- #call(x) ⇒ Object
-
#initialize(stack = []) ⇒ Sequential
constructor
A new instance of Sequential.
-
#insert(index, layer) ⇒ DNN::Models::Model
Insert layer to the model by index position.
-
#remove(layer) ⇒ Boolean
Remove layer to the model.
Methods inherited from Model
#add_callback, #built?, #clean_layers, #clear_callbacks, #copy, #evaluate, #evaluate_by_iterator, #get_all_params_data, #get_layer, load, #load_params, #predict, #predict1, #save, #save_params, #set_all_params_data, #setup, #test_on_batch, #train, #train_by_iterator, #train_on_batch, #trainable_layers
Methods inherited from Chain
Constructor Details
#initialize(stack = []) ⇒ Sequential
Returns a new instance of Sequential.
471 472 473 474 475 476 477 |
# File 'lib/dnn/core/models.rb', line 471 def initialize(stack = []) super() @stack = LayersList.new stack.each do |layer| add(layer) end end |
Instance Attribute Details
#stack ⇒ Object (readonly)
Returns the value of attribute stack.
468 469 470 |
# File 'lib/dnn/core/models.rb', line 468 def stack @stack end |
Instance Method Details
#add(layer) ⇒ DNN::Models::Model Also known as: <<
Add layer to the model.
482 483 484 485 486 487 488 489 490 491 |
# File 'lib/dnn/core/models.rb', line 482 def add(layer) if layer.is_a?(Layers::MergeLayer) raise TypeError, "layer: #{layer.class.name} should not be a DNN::Layers::MergeLayer class." end 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
515 516 517 518 519 520 |
# File 'lib/dnn/core/models.rb', line 515 def call(x) @stack.each do |layer| x = layer.(x) end x end |
#insert(index, layer) ⇒ DNN::Models::Model
Insert layer to the model by index position.
498 499 500 501 502 503 504 505 506 |
# File 'lib/dnn/core/models.rb', line 498 def insert(index, layer) if layer.is_a?(Layers::MergeLayer) raise TypeError, "layer: #{layer.class.name} should not be a DNN::Layers::MergeLayer class." end 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.insert(index, layer) end |
#remove(layer) ⇒ Boolean
Remove layer to the model.
511 512 513 |
# File 'lib/dnn/core/models.rb', line 511 def remove(layer) @stack.delete(layer) ? true : false end |