Reputation: 584
I would like to add skip connections for my inner layers of a fully convolutional network in keras, there is a keras.layers.Add option and there is a keras.layers.concatenate option.
What is the difference? and which one I should use?
Upvotes: 11
Views: 9105
Reputation: 2642
What is the difference?
Add layer adds two input tensor while concatenate appends two tensors. You can refer this documentation for more info.
Example:
import keras
import tensorflow as tf
import keras.backend as K
a = tf.constant([1,2,3])
b = tf.constant([4,5,6])
add = keras.layers.Add()
print(K.eval(add([a,b])))
#output: [5 7 9]
concat = keras.layers.Concatenate()
print(K.eval(concat([a,b])))
#output: array([1, 2, 3, 4, 5, 6], dtype=int32)
which one I should use?
You can use Add for skip connections.
Upvotes: 19