美文网首页
Lambda 层

Lambda 层

作者: 光光小丸子 | 来源:发表于2018-11-19 10:53 被阅读0次

    keras中的Lambda 层中的使用

    '''
    from keras.layers import Reshape, Permute, RepeatVector, Dense,Lambda,Embedding,Add
    from keras.layers import Multiply
    from keras.models import Sequential,Input,Model
    import numpy as np
    import keras.backend as K
    a = Input(shape=(2,))
    b = Input(shape=(2,))

    def minus(inputs):
    x,y = inputs
    return K.mean(x-y,axis=1)

    cha = Lambda(minus,name='minus')([a,b])

    model = Model(inputs=[a,b],outputs=[cha])

    print(model.summary())

    v0 = np.array([5,2])
    v1 = np.array([8,4])
    v2 = np.array([3,2])
    print(model.predict([v0.reshape(1,2), v1.reshape(1,2)]))
    print(model.predict([v0.reshape(1,2), v2.reshape(1,2)]))
    print(model.predict([np.array([v0, v0]), np.array([v1, v2])]))
    '''

    相关文章

      网友评论

          本文标题:Lambda 层

          本文链接:https://www.haomeiwen.com/subject/mleofqtx.html