为什么激活函数会降低 CNN 模型的时间性能?

Why does the activation function degrade the time performance of the CNN model?

我正在测试 CNN 模型的时间和准确性性能,并进行一些不同的小改动。在这个模型中,跳过了卷积之间的一些激活层。所以我添加了它们。我注意到添加了 ELU 激活的模型有

performance 3.07 ms per image and 92.26% accuracy on test set

没有它们的模型有

performance 3.52 ms per image and 92.34% accuracy on test set

虽然模型参数个数相同。所以我的问题是为什么激活会如此降低模型的时间性能?

这里举例部分代码:

...
nn.Conv2d(28 * filters_multiplier, 28 * filters_multiplier, kernel_size=(3, 1), padding=(1, 0)),
nn.Conv2d(28 * filters_multiplier, 28 * filters_multiplier, kernel_size=(1, 3), padding=(0, 1)),

# nn.ELU(), 

nn.Conv2d(28 * filters_multiplier, 28 * filters_multiplier, kernel_size=(3, 1), padding=(1, 0)),
nn.Conv2d(28 * filters_multiplier, 40 * filters_multiplier, kernel_size=(1, 3), padding=(0, 1)),
...

因此带有注释块的代码比未注释块运行得更快。

UPD 我刚刚使用 ReLU() 函数进行了测试,它的运行速度与第一个没有激活的模型一样快。所以也许问题只是在 ELU() 中?

ReLU 和 ELU 都没有可学习的参数,但它们仍然需要计算才能执行。

ELU 对所有 x >= 0 执行指数函数。这是计算成本高昂的,因此您的网络速度较慢。

ReLU 的计算成本低,因为操作简单 x[x < 0] = 0,因此您不会真正看到时间峰值。这也是为什么 ReLU 被普遍选择作为激活函数的原因之一。