Keras 3 API 文档 / 层 API / 合并层 / 串联层

串联层

[源代码]

Concatenate

keras.layers.Concatenate(axis=-1, **kwargs)

串联输入列表。

它接受张量列表作为输入,所有张量除了串联轴之外都具有相同的形状,并返回一个张量,该张量是所有输入的串联结果。

示例

>>> x = np.arange(20).reshape(2, 2, 5)
>>> y = np.arange(20, 30).reshape(2, 1, 5)
>>> keras.layers.Concatenate(axis=1)([x, y])

在 Keras 模型中的用法

>>> x1 = keras.layers.Dense(8)(np.arange(10).reshape(5, 2))
>>> x2 = keras.layers.Dense(8)(np.arange(10, 20).reshape(5, 2))
>>> y = keras.layers.Concatenate()([x1, x2])

参数

  • axis: 串联轴。
  • **kwargs: 标准层关键字参数。

返回

一个张量,它是沿轴 axis 的输入串联结果。