激活层和激活关键字参数有什么区别

What is the difference between Activation layer and activation keyword argument

伙计们,tensorflow 中的 activation kwarg 和 Activation 层有什么区别?

这是一个例子:

activation夸格:

model.add(Dense(64,activation="relu"))

Activation层:

model.add(Dense(64))
model.add(Activation("sigmoid"))

PS:我是张量流的新手

Dense(64,activation="relu")中,relu激活函数成为Dense层的一部分,并会在调用此Dense层时自动调用。

Activation("relu")中,relu激活函数本身就是一个层,与Dense层解耦。如果你想引用张量 after Densebefore 激活是为了分支目的。

input_tensor = Input((10,))
intermediate_tensor = Dense(64)(input_tensor)
branch_1_tensor = Activation('relu')(intermediate_tensor)
branch_2_tensor = Dense(64)(intermediate_tensor)
final_tensor = branch_1_tensor + branch_2_tensor

model = Model(inputs=input_tensor, outputs=final_tensor)

但是,您的 modelSequential 模型,因此您的两个样本实际上是相等的:relu 激活函数将被自动调用。在这种情况下,要在 Activation 之前获取对张量的引用,you can go through model.layers 并从内部获取 Dense 层的输出。