Class: DNN::MergeLayers::Concatenate

Inherits:
MergeLayer show all
Defined in:
lib/dnn/core/merge_layers.rb

Instance Attribute Summary collapse

Attributes inherited from Layers::Layer

#input_shape, #name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from MergeLayer

call, #call

Methods inherited from Layers::Layer

#build, #built?, #call, call, #output_shape

Constructor Details

#initialize(axis: 1) ⇒ Concatenate

Returns a new instance of Concatenate.



50
51
52
53
# File 'lib/dnn/core/merge_layers.rb', line 50

def initialize(axis: 1)
  super()
  @axis = axis
end

Instance Attribute Details

#axis ⇒ Object (readonly)

Returns the value of attribute axis.



44
45
46
# File 'lib/dnn/core/merge_layers.rb', line 44

def axis
  @axis
end

Class Method Details

.from_hash(hash) ⇒ Object



46
47
48
# File 'lib/dnn/core/merge_layers.rb', line 46

def self.from_hash(hash)
  self.new(axis: hash[:axis])
end

Instance Method Details

#backward(dy) ⇒ Object



61
62
63
# File 'lib/dnn/core/merge_layers.rb', line 61

def backward(dy)
  dy.split([@x1_dim, @x1_dim + @x2_dim], axis: @axis)
end

#forward(x1, x2) ⇒ Object



55
56
57
58
59
# File 'lib/dnn/core/merge_layers.rb', line 55

def forward(x1, x2)
  @x1_dim = x1.shape[@axis]
  @x2_dim = x2.shape[@axis]
  x1.concatenate(x2, axis: @axis)
end

#to_hash ⇒ Object



65
66
67
# File 'lib/dnn/core/merge_layers.rb', line 65

def to_hash
  super(axis: @axis)
end