Farnaz
Farnaz

Reputation: 584

What is the difference between concatenate and add in keras?

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

Answers (1)

Vivek Mehta
Vivek Mehta

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

Related Questions