【发布时间】:2019-01-31 09:28:13
【问题描述】:
我想训练一个具有以下形式的共享层的模型:
x --> F(x)
==> G(F(x),F(y))
y --> F(y)
x 和 y 是两个独立的输入层,F 是共享层。 G 是连接F(x) 和F(y) 之后的最后一层。
是否可以在 Keras 中进行建模?怎么样?
【问题讨论】:
标签: python machine-learning keras keras-layer
我想训练一个具有以下形式的共享层的模型:
x --> F(x)
==> G(F(x),F(y))
y --> F(y)
x 和 y 是两个独立的输入层,F 是共享层。 G 是连接F(x) 和F(y) 之后的最后一层。
是否可以在 Keras 中进行建模?怎么样?
【问题讨论】:
标签: python machine-learning keras keras-layer
您可以为此使用Keras functional API:
from keras.layers import Input, concatenate
x = Input(shape=...)
y = Input(shape=...)
shared_layer = MySharedLayer(...)
out_x = shared_layer(x)
out_y = shared_layer(y)
concat = concatenate([out_x, out_y])
# pass concat to other layers ...
请注意,x 和 y 可以是任何层的输出张量,不一定是输入层。
【讨论】:
x 和y)。
out_x 提供给不同的层。在这里使用连接层是因为 OP 在他们的问题中明确提到了这一点:“G 是连接 F(x) 和 F(y) 之后的最后一层”。