Class: DNN::Models::LayersList

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

Overview

This class is used to hold multiple layers in an array.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_hash_list(hash_list) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/dnn/core/models.rb', line 6

def self.from_hash_list(hash_list)
  layers_list = new
  hash_list.each do |hash|
    obj_class = DNN.const_get(hash[:class])
    obj = obj_class.allocate
    if obj.is_a?(Chain)
      obj = obj_class.new
      obj.load_hash(hash)
    else
      obj = Layers::Layer.from_hash(hash)
    end
    layers_list << obj
  end
  layers_list
end

Instance Method Details

#layersArray

Get the all layers.

Returns:

  • (Array)

    All layers array.



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/dnn/core/models.rb', line 28

def layers
  layers_array = []
  each do |layer|
    if layer.is_a?(Layers::Layer)
      layers_array << layer
    elsif layer.is_a?(Chain) || layer.is_a?(LayersList)
      layers_array.concat(layer.layers)
    end
  end
  layers_array
end

#to_hash_listObject



22
23
24
# File 'lib/dnn/core/models.rb', line 22

def to_hash_list
  map(&:to_hash)
end