What happens when you use tensorflow.keras.layers.Add on different shapes?

Viewed 194

So I just realized according to the documentation, the Add layer of tensorflow keras wants a same shape between the added tensors(which I knew, but by mistake changed the shape of one). But instead of throwing an error, it does something unexpected. Does anyone know what it does?

1 Answers

From what I experienced, it copies and extends the smaller shape tensor to match the larger shaped tensor(if possible) and adds them to give the result. So if you do

x1 = tf.zeros((32, 32, 3))
x2= tf.zeros((32, 32, 1))
temp = tf.keras.layers.add([x1, x2])
print(tf.shape(temp))

it would print (32, 32, 3)

Maybe not super important information but wanted to prevent people make the same mistake like me by using the add layer and not getting the shape they were expecting!

Related