如何在keras中建模共享层?

2024-04-20 04:17:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用以下形式训练具有共享层的模型:

x --> F(x)
          ==> G(F(x),F(y))
y --> F(y) 

x和{}是两个独立的输入层,F是共享层。G是连接F(x)F(y)后的最后一层。在

有没有可能在Keras中建模?怎样?在


Tags: 模型建模形式keras
1条回答
网友
1楼 · 发布于 2024-04-20 04:17:51

您可以为此使用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和{}可以是任何层的输出张量,而不一定是输入层。在

相关问题 更多 >