Keras: Lambda layer function with multiple parameters

后端 未结 3 2122
盖世英雄少女心
盖世英雄少女心 2021-02-13 15:09

I am trying to write a Lambda layer in Keras which calls a function connection, that runs a loop for i in range(0,k) where k

3条回答
  •  广开言路
    2021-02-13 15:58

    Tmodel = Sequential()
    x = layers.Input(shape=[1,])   # Lambda on single input
    out1 = layers.Lambda(lambda x: x ** 2)(x)
    
    y = layers.Input(shape=[1,])   # Lambda on multiple inputs
    z = layers.Input(shape=[1,])
    def conn(IP):
        return IP[0]+IP[1]
    out2 = layers.Lambda(conn)([y,z])
    
    Tmodel = tf.keras.Model(inputs=[x,y,z], outputs=[out1,out2],name='Tmodel')  # Define Model
    Tmodel.summary()
    
    # output
    O1,O2 = Tmodel([2,15,10])
    print(O1)   # tf.Tensor(4, shape=(), dtype=int32)
    print(O2)   # tf.Tensor(25, shape=(), dtype=int32)
    

提交回复
热议问题