I want to merge two CNN deep learning model using Keras and would like to know what is the difference multiply and dot functions that is used to merge layer?
keras.layers.multiply(inputs)
keras.layers.dot(inputs, axes, normalize=False)
The multiply()
function performs element-wise multiplication. For example, let us consider 1D CNN for simplicity and you pass two inputs of batch size b
with a tensor length of 5, the output will be (b,5) as it's element-wise multiplication.
Let us assume two tensors of length 5 as follows: [1,2,3,4,5]
and [6,7,8,9,10]
, the result shall be [6,14,24,36,50]
as it's just element-wise multiplication.
In the case of dot()
, it takes the dot product, and the dot product for 1D is mathematically defined as: a.b = sum(a_i * b_i)
, where i
ranges from 0 to n-1; where n is the number of elements in vector a and b. (For 2-D , you can consider it as matrix multiplication). So the result shall be of length (b,1)
where b
is the batch size. In case of out example, the results of dot product of [1,2,3,4,5]
and [6,7,8,9,10]
shall be [130]