调用函数后的 (x) 是什么意思?

What Does (x) After Calling a Function Mean?

我有以下 Python 代码行:

x = layers.Dense(64, activation="relu")(x)

(x) 是什么意思?

看起来您正在专门阅读使用 Keras 库的 Functional API(而不是 Sequential API)编写的代码。这意味着每个神经网络层在创建时 returns 都是一个必须调用的函数。要以这种方式创建一个简单的 feed-forward 神经网络(没有 skip-connections),

a. Create a layer that takes in your input. This yields a function that takes your input.
b. Create another layer and pass the previous layer in as input.
...
n. Create an output layer that takes the second-to-last layer as input.

或者

x_in = layers.Input(...)
x_1 = layers.Dense(...)(x_in)
x_2 = layers.Dense(...)(x_1)
x_out = layers.Dense(...)(x_2)

不过,您不需要为每一层分配自己的变量名称,因此可以将前面的示例重写为(并且通常在教程中也是如此):

x = layers.Input(...)
x = layers.Dense(...)(x)
x = layers.Dense(...)(x)
x = layers.Dense(...)(x)