tf.keras.layers.Add
Stay organized with collections
Save and categorize content based on your preferences.
Layer that adds a list of inputs.
Inherits From: Layer
, Module
tf.keras.layers.Add(
**kwargs
)
It takes as input a list of tensors,
all of the same shape, and returns
a single tensor (also of the same shape).
Examples:
input_shape = (2, 3, 4)
x1 = tf.random.normal(input_shape)
x2 = tf.random.normal(input_shape)
y = tf.keras.layers.Add()([x1, x2])
print(y.shape)
(2, 3, 4)
Used in a functional model:
input1 = tf.keras.layers.Input(shape=(16,))
x1 = tf.keras.layers.Dense(8, activation='relu')(input1)
input2 = tf.keras.layers.Input(shape=(32,))
x2 = tf.keras.layers.Dense(8, activation='relu')(input2)
# equivalent to `added = tf.keras.layers.add([x1, x2])`
added = tf.keras.layers.Add()([x1, x2])
out = tf.keras.layers.Dense(4)(added)
model = tf.keras.models.Model(inputs=[input1, input2], outputs=out)
Args |
**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 2021-05-14 UTC.
[null,null,["Last updated 2021-05-14 UTC."],[],[],null,["# tf.keras.layers.Add\n\n\u003cbr /\u003e\n\n|-----------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------|\n| [TensorFlow 1 version](/versions/r1.15/api_docs/python/tf/keras/layers/Add) | [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.5.0/tensorflow/python/keras/layers/merge.py#L218-L251) |\n\nLayer that adds 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.Add`](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Add)\n\n\u003cbr /\u003e\n\n tf.keras.layers.Add(\n **kwargs\n )\n\nIt takes as input a list of tensors,\nall of the same shape, and returns\na single tensor (also of the same shape).\n\n#### Examples:\n\n input_shape = (2, 3, 4)\n x1 = tf.random.normal(input_shape)\n x2 = tf.random.normal(input_shape)\n y = tf.keras.layers.Add()([x1, x2])\n print(y.shape)\n (2, 3, 4)\n\nUsed in a functional model: \n\n input1 = tf.keras.layers.Input(shape=(16,))\n x1 = tf.keras.layers.Dense(8, activation='relu')(input1)\n input2 = tf.keras.layers.Input(shape=(32,))\n x2 = tf.keras.layers.Dense(8, activation='relu')(input2)\n # equivalent to `added = tf.keras.layers.add([x1, x2])`\n added = tf.keras.layers.Add()([x1, x2])\n out = tf.keras.layers.Dense(4)(added)\n model = tf.keras.models.Model(inputs=[input1, input2], outputs=out)\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|------------|-----------------------------------|\n| `**kwargs` | standard layer keyword arguments. |\n\n\u003cbr /\u003e"]]