语法 X = Add() ([tensor1, tensor2]) 在使用 keras.layers.add 构造 ResNET 时究竟如何工作?

How does the syntax X = Add() ([tensor1, tensor2]) exactly work in using keras.layers.add to construct a ResNET?

在我查看的一些构建 ResNET 的代码中,我发现了以下语法:

.
.
.
# Save the input value. You'll need this later to add back to the main path. 
X_shortcut = X
.
.
.
# Final step: Add shortcut value to main path, and pass it through a RELU activation (≈2 lines)
X = Add()([X, X_shortcut])
X = Activation('relu')(X)

参考:https://github.com/priya-dwivedi/Deep-Learning/blob/master/resnet_keras/Residual_Networks_yourself.ipynb

我知道 [X, X_shortcut] 是从 keras.layers 到 Add() 层的输入列表,其中 X 和 X_shortcut 是符号张量。但是,我不理解语法。 有人可以向我解释输入是如何传递到这里的,以及为什么张量列表不仅仅是 Add() 函数的参数吗?

Add() 是 keras 层 class 的构造函数。我们首先创建这些(可调用)对象之一,然后使用输入列表调用它。

它 shorthand 是这样的:

addition_layer = Add()
activation_layer = Activation('relu')

.
.
.
added = addition_layer([X, X_shortcut])
after_activation = activation_layer(added)