web-dev-qa-db-ja.com

Tensorflow 2.x Kerasカスタムレイヤで複数の入力を使用する方法

TensorFlow-Kerasのカスタムレイヤーで複数の入力を使用しようとしています。使用法は何でもすることができます。今は、マスクに画像を掛けると定義されます。私は検索SO、そして私が見つけることができる唯一の答えがTF 1.xのためのものであったので、それほど良くなかったので).

class mul(layers.Layer):
def __init__(self, **kwargs):
    super().__init__(**kwargs)
    # I've added pass because this is the simplest form I can come up with.
    pass

def call(self, inputs):
    # magic happens here and multiplications occur
    return(Z)
 _
5

このようにしてみてください

class mul(layers.Layer):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        # I've added pass because this is the simplest form I can come up with.
        pass

    def call(self, inputs):
        inp1, inp2 = inputs
        Z = inp1*inp2
        return Z

inp1 = Input((10))
inp2 = Input((10))
x = mul()([inp1,inp2])
x = Dense(1)(x)
model = Model([inp1,inp2],x)
model.summary()
 _
0
Marco Cerliani