Class: DNN::Models::LayersList

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_hash_list(hash_list) ⇒ Object



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

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.



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

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



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

def to_hash_list
  map { |layer| layer.to_hash }
end