當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python tf.keras.layers.add用法及代碼示例

tf.keras.layers.Add 層的函數接口。

用法

tf.keras.layers.add(
    inputs, **kwargs
)

參數

  • inputs 具有相同形狀的輸入張量列表(至少 2 個)。
  • **kwargs 標準層關鍵字參數。

返回

  • 作為輸入總和的張量。它與輸入具有相同的形狀。

例子:

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)

在函數模型中使用:

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)
added = tf.keras.layers.add([x1, x2])
out = tf.keras.layers.Dense(4)(added)
model = tf.keras.models.Model(inputs=[input1, input2], outputs=out)

相關用法


注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.keras.layers.add。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。