Reputation: 882
I am trying to get the neural network to multiply two input tensors (I cannot do it before feeding them into the network). Keras' multiply
function can only handle two tensors of the same dimension. Have something like:
scale_, mean_ = 2., 4.
a = Input(shape=(300,), name='Input_vec')
m_num = Input(shape=(1,), name='Input_num')
mulNum = Lambda(lambda x: K.exp(x * scale_ + mean_))(m_num)
output = multiply([mulNum, a]) # tensors not same shape
how can I do the multiplication of two inputs where one is just a scalar?
Upvotes: 1
Views: 115
Reputation: 8585
Use tf.multiply()
(or tf.math.multiply()
) that supports broadcasting:
output = Lambda(lambda x: tf.multiply(x[0], x[1]))((a, mulNum))
Upvotes: 1