tf.keras.layers.Concatenate
Stay organized with collections
Save and categorize content based on your preferences.
Layer that concatenates a list of inputs.
Inherits From: Layer
, Module
View aliases
Compat aliases for migration
See
Migration guide for
more details.
`tf.compat.v1.keras.layers.Concatenate`
tf.keras.layers.Concatenate(
axis=-1, **kwargs
)
It takes as input a list of tensors, all of the same shape except
for the concatenation axis, and returns a single tensor that is the
concatenation of all inputs.
x = np.arange(20).reshape(2, 2, 5)
print(x)
[[[ 0 1 2 3 4]
[ 5 6 7 8 9]]
[[10 11 12 13 14]
[15 16 17 18 19]]]
y = np.arange(20, 30).reshape(2, 1, 5)
print(y)
[[[20 21 22 23 24]]
[[25 26 27 28 29]]]
tf.keras.layers.Concatenate(axis=1)([x, y])
<tf.Tensor: shape=(2, 3, 5), dtype=int64, numpy=
array([[[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[20, 21, 22, 23, 24]],
[[10, 11, 12, 13, 14],
[15, 16, 17, 18, 19],
[25, 26, 27, 28, 29]]])>
x1 = tf.keras.layers.Dense(8)(np.arange(10).reshape(5, 2))
x2 = tf.keras.layers.Dense(8)(np.arange(10, 20).reshape(5, 2))
concatted = tf.keras.layers.Concatenate()([x1, x2])
concatted.shape
TensorShape([5, 16])
Args |
axis
|
Axis along which to concatenate.
|
**kwargs
|
standard layer keyword arguments.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2023-10-06 UTC.
[null,null,["Last updated 2023-10-06 UTC."],[],[],null,["# tf.keras.layers.Concatenate\n\n\u003cbr /\u003e\n\n|------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/keras-team/keras/tree/v2.10.0/keras/layers/merging/concatenate.py#L28-L196) |\n\nLayer that concatenates a list of inputs.\n\nInherits From: [`Layer`](../../../tf/keras/layers/Layer), [`Module`](../../../tf/Module)\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n\\`tf.compat.v1.keras.layers.Concatenate\\`\n\n\u003cbr /\u003e\n\n tf.keras.layers.Concatenate(\n axis=-1, **kwargs\n )\n\nIt takes as input a list of tensors, all of the same shape except\nfor the concatenation axis, and returns a single tensor that is the\nconcatenation of all inputs. \n\n x = np.arange(20).reshape(2, 2, 5)\n print(x)\n [[[ 0 1 2 3 4]\n [ 5 6 7 8 9]]\n [[10 11 12 13 14]\n [15 16 17 18 19]]]\n y = np.arange(20, 30).reshape(2, 1, 5)\n print(y)\n [[[20 21 22 23 24]]\n [[25 26 27 28 29]]]\n tf.keras.layers.Concatenate(axis=1)([x, y])\n \u003ctf.Tensor: shape=(2, 3, 5), dtype=int64, numpy=\n array([[[ 0, 1, 2, 3, 4],\n [ 5, 6, 7, 8, 9],\n [20, 21, 22, 23, 24]],\n [[10, 11, 12, 13, 14],\n [15, 16, 17, 18, 19],\n [25, 26, 27, 28, 29]]])\u003e\n\n x1 = tf.keras.layers.Dense(8)(np.arange(10).reshape(5, 2))\n x2 = tf.keras.layers.Dense(8)(np.arange(10, 20).reshape(5, 2))\n concatted = tf.keras.layers.Concatenate()([x1, x2])\n concatted.shape\n TensorShape([5, 16])\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|------------|-----------------------------------|\n| `axis` | Axis along which to concatenate. |\n| `**kwargs` | standard layer keyword arguments. |\n\n\u003cbr /\u003e"]]