Keras: Lambda layer function with multiple parameters

后端 未结 3 2123
盖世英雄少女心
盖世英雄少女心 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:55

    Just use

    y = Lambda(connection)((x,k)) 
    

    and then var[0], var[1] in connection method

    0 讨论(0)
  • 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)
    
    0 讨论(0)
  • 2021-02-13 16:00

    Found the solution to the problem in this GitHub Pull Request. Using

    y = Lambda(connection, arguments={'k':k})(x)
    

    worked!

    0 讨论(0)
提交回复
热议问题