且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在两个 keras 层之间共享权重?

更新时间:2023-12-02 20:29:46

如果你想在 inp1inp2 张量上应用相同的卷积层,那么你只需要首先创建层,然后在 inp1inp2 上调用它:

If you want to apply the same convolution layer on inp1 and inp2 tensors, then you just need to first create the layer and then call it on inp1 and inp2:

shared_conv = tf.keras.layers.Conv2D(32, 3, strides=(2,2), padding='same', activation='relu')
out1 = shared_conv(inp1)
out2 = shared_conv(inp2)

请参阅 Keras 文档中的共享层部分更多信息.

See shared layers section in Keras documentation for more information.