Class: DNN::Models::Chain
- Inherits:
-
Object
- Object
- DNN::Models::Chain
- Defined in:
- lib/dnn/core/models.rb
Direct Known Subclasses
Instance Method Summary collapse
- #call(x) ⇒ Object
-
#layers ⇒ Array
Get the all layers.
- #load_hash(layers_hash) ⇒ Object
- #to_hash ⇒ Object
Instance Method Details
#call(x) ⇒ Object
41 42 43 |
# File 'lib/dnn/core/models.rb', line 41 def call(x) raise NotImplementedError, "Class '#{self.class.name}' has implement method 'call'" end |
#layers ⇒ Array
Get the all layers.
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/dnn/core/models.rb', line 47 def layers layers_array = [] instance_variables.sort.each do |ivar| obj = instance_variable_get(ivar) if obj.is_a?(Layers::Layer) layers_array << obj elsif obj.is_a?(Chain) || obj.is_a?(LayersList) layers_array.concat(obj.layers) end end layers_array end |
#load_hash(layers_hash) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/dnn/core/models.rb', line 73 def load_hash(layers_hash) instance_variables.sort.each do |ivar| hash_or_array = layers_hash[ivar] if hash_or_array.is_a?(Array) instance_variable_set(ivar, LayersList.from_hash_list(hash_or_array)) elsif hash_or_array.is_a?(Hash) obj_class = DNN.const_get(hash_or_array[:class]) obj = obj_class.allocate if obj.is_a?(Chain) obj = obj_class.new obj.load_hash(hash_or_array) instance_variable_set(ivar, obj) else instance_variable_set(ivar, Layers::Layer.from_hash(hash_or_array)) end end end end |
#to_hash ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/dnn/core/models.rb', line 60 def to_hash layers_hash = { class: self.class.name } instance_variables.sort.each do |ivar| obj = instance_variable_get(ivar) if obj.is_a?(Layers::Layer) || obj.is_a?(Chain) layers_hash[ivar] = obj.to_hash elsif obj.is_a?(LayersList) layers_hash[ivar] = obj.to_hash_list end end layers_hash end |