How can I perform weighted addition of three layers in keras?
I solved the problem using subclassing in keras. The code is shown below:
class Wt_Add(keras.layers.Layer):
def __init__(self, units=1, input_dim=1):
    super(Wt_Add, self).__init__()
    w_init = tf.random_normal_initializer()
    self.w1 = tf.Variable(
        initial_value=w_init(shape=(input_dim, units), dtype=&quot;float32&quot;),
        trainable=True,
    )
    self.w2 = tf.Variable(
        initial_value=w_init(shape=(input_dim, units), dtype=&quot;float32&quot;),
        trainable=True,
    )  
    self.w3 = tf.Variable(
        initial_value=w_init(shape=(input_dim, units), dtype=&quot;float32&quot;),
        trainable=True,
    )       

def call(self, input1, input2, input3):
    return tf.multiply(input1,self.w1) + tf.multiply(input2, self.w2) + tf.multiply(input3, self.w3)

Usage:
wt_add = Wt_Add(1,1)
sum_layer = wt_add(input1, input2, input3)