Layer that adds a list of inputs. It takes as input a list of tensors, all of the same shape, and returns a single tensor (also of the same shape). Examples: ```python import keras input1 = keras.layers.Input(shape=(16,)) x1 = keras.layers.Dense(8, activation='relu')(
| 220 | |
| 221 | @keras_export('keras.layers.Add') |
| 222 | class Add(_Merge): |
| 223 | """Layer that adds a list of inputs. |
| 224 | |
| 225 | It takes as input a list of tensors, |
| 226 | all of the same shape, and returns |
| 227 | a single tensor (also of the same shape). |
| 228 | |
| 229 | Examples: |
| 230 | |
| 231 | ```python |
| 232 | import keras |
| 233 | |
| 234 | input1 = keras.layers.Input(shape=(16,)) |
| 235 | x1 = keras.layers.Dense(8, activation='relu')(input1) |
| 236 | input2 = keras.layers.Input(shape=(32,)) |
| 237 | x2 = keras.layers.Dense(8, activation='relu')(input2) |
| 238 | # equivalent to `added = keras.layers.add([x1, x2])` |
| 239 | added = keras.layers.Add()([x1, x2]) |
| 240 | out = keras.layers.Dense(4)(added) |
| 241 | model = keras.models.Model(inputs=[input1, input2], outputs=out) |
| 242 | ``` |
| 243 | """ |
| 244 | |
| 245 | def _merge_function(self, inputs): |
| 246 | output = inputs[0] |
| 247 | for i in range(1, len(inputs)): |
| 248 | output += inputs[i] |
| 249 | return output |
| 250 | |
| 251 | |
| 252 | @keras_export('keras.layers.Subtract') |