- Install
- Learn
-
API
- Overview
- Python
- C++
- Java
- More
- Resources
- Community
- Why TensorFlow
- GitHub
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
]
Used in the notebooks
|
|
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]]
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]]
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 2022-09-08 UTC.
[{ "type": "thumb-down", "id": "missingTheInformationINeed", "label":"Missing the information I need" },{ "type": "thumb-down", "id": "tooComplicatedTooManySteps", "label":"Too complicated / too many steps" },{ "type": "thumb-down", "id": "outOfDate", "label":"Out of date" },{ "type": "thumb-down", "id": "samplesCodeIssue", "label":"Samples / code issue" },{ "type": "thumb-down", "id": "otherDown", "label":"Other" }] [{ "type": "thumb-up", "id": "easyToUnderstand", "label":"Easy to understand" },{ "type": "thumb-up", "id": "solvedMyProblem", "label":"Solved my problem" },{ "type": "thumb-up", "id": "otherUp", "label":"Other" }]
- Install
- Learn
-
API
- Overview
- Python
- C++
- Java
- More
- Resources
- Community
- Why TensorFlow
- GitHub
Concatenates tensors along one dimension.
View aliases
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.concat
tf.concat[
values, axis, name='concat'
]
Used in the notebooks
|
|
See also tf.tile
, tf.stack
, tf.repeat
.
Concatenates the list of tensors values
along dimension axis
. If values[i].shape = [D0, D1, ... Daxis[i], ...Dn]
, the concatenated result has shape
[D0, D1, ... Raxis, ...Dn]
where
Raxis = sum[Daxis[i]]
That is, the data from the input
tensors is joined along the axis
dimension.
The number of dimensions of the input tensors must match, and all dimensions except axis
must be equal.
For example:
t1 = [[1, 2, 3], [4, 5, 6]]
t2 = [[7, 8, 9], [10, 11, 12]]
tf.concat[[t1, t2], 0]
tf.concat[[t1, t2], 1]
As in Python, the axis
could also be negative numbers. Negative axis
are interpreted as counting from the end of the rank, i.e., axis + rank[values]
-th dimension.
For example:
t1 = [[[1, 2], [2, 3]], [[4, 4], [5, 3]]]
t2 = [[[7, 4], [8, 4]], [[2, 10], [15, 11]]]
tf.concat[[t1, t2], -1]
tf.concat[[tf.expand_dims[t, axis] for t in tensors], axis]
can be rewritten as
tf.stack[tensors, axis=axis]
values
| A list of Tensor objects or a single Tensor .
|
axis
| 0-D int32 Tensor . Dimension along which to concatenate. Must be in the range [-rank[values], rank[values]] . As in Python, indexing for axis is 0-based. Positive axis in the rage of [0, rank[values]] refers to axis -th dimension. And negative axis refers to axis +
rank[values] -th dimension.
|
name
| A name for the operation [optional]. |
A Tensor resulting from concatenation of the input tensors.
|
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 2022-09-08 UTC.
[{ "type": "thumb-down", "id": "missingTheInformationINeed", "label":"Missing the information I need" },{ "type": "thumb-down", "id": "tooComplicatedTooManySteps", "label":"Too complicated / too many steps" },{ "type": "thumb-down", "id": "outOfDate", "label":"Out of date" },{ "type": "thumb-down", "id": "samplesCodeIssue", "label":"Samples / code issue" },{ "type": "thumb-down", "id": "otherDown", "label":"Other" }] [{ "type": "thumb-up", "id": "easyToUnderstand", "label":"Easy to understand" },{ "type": "thumb-up", "id": "solvedMyProblem", "label":"Solved my problem" },{ "type": "thumb-up", "id": "otherUp", "label":"Other" }]