tf.keras.layers.Average
Stay organized with collections
Save and categorize content based on your preferences.
Layer that averages a list of inputs element-wise.
tf.keras.layers.Average(
**kwargs
)
It takes as input a list of tensors, all of the same shape, and returns
a single tensor (also of the same shape).
Example:
x1 = np.ones((2, 2))
x2 = np.zeros((2, 2))
y = tf.keras.layers.Average()([x1, x2])
y.numpy().tolist()
[[0.5, 0.5], [0.5, 0.5]]
Usage 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)
avg = tf.keras.layers.Average()([x1, x2])
out = tf.keras.layers.Dense(4)(avg)
model = tf.keras.models.Model(inputs=[input1, input2], outputs=out)
Raises |
ValueError
|
If there is a shape mismatch between the inputs and the shapes
cannot be broadcasted to match.
|
Arguments |
**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.
Last updated 2020-10-01 UTC.
[null,null,["Last updated 2020-10-01 UTC."],[],[],null,["# tf.keras.layers.Average\n\n\u003cbr /\u003e\n\n|---------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------|\n| [TensorFlow 1 version](/versions/r1.15/api_docs/python/tf/keras/layers/Average) | [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.3.0/tensorflow/python/keras/layers/merge.py#L327-L360) |\n\nLayer that averages a list of inputs element-wise.\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.Average`](/api_docs/python/tf/keras/layers/Average)\n\n\u003cbr /\u003e\n\n tf.keras.layers.Average(\n **kwargs\n )\n\nIt takes as input a list of tensors, all of the same shape, and returns\na single tensor (also of the same shape).\n\n#### Example:\n\n x1 = np.ones((2, 2))\n x2 = np.zeros((2, 2))\n y = tf.keras.layers.Average()([x1, x2])\n y.numpy().tolist()\n [[0.5, 0.5], [0.5, 0.5]]\n\nUsage 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 avg = tf.keras.layers.Average()([x1, x2])\n out = tf.keras.layers.Dense(4)(avg)\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| Raises ------ ||\n|--------------|------------------------------------------------------------------------------------------------|\n| `ValueError` | If there is a shape mismatch between the inputs and the shapes cannot be broadcasted to match. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Arguments --------- ||\n|------------|-----------------------------------|\n| `**kwargs` | standard layer keyword arguments. |\n\n\u003cbr /\u003e"]]