关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。
想改进这个问题?将问题更新为 on-topic对于堆栈溢出。
3年前关闭。
Improve this question
我都看到了tf.nn.relu和 tf.keras.activations.relu只计算 ReLU 函数(没有额外的全连接层或其他东西,如 here 所述),那么它们之间有什么区别?一个只是包裹另一个吗?
最佳答案
tf.nn.relu
: 它来自 TensorFlow 库。它位于 nn
模块。因此,它被用作神经网络中的操作。如果 x
那么是张量,y = tf.nn.relu( x )
它用于创建自定义层和 NN。如果将它与 Keras 一起使用,则在加载或保存模型或将模型转换为 TF Lite 时可能会遇到一些问题。
tf.keras.activations.relu
:它来自 TensorFlow 中包含的 Keras 库。它位于 activations
该模块还提供了另一个激活功能。它主要用于 Keras 层 ( tf.keras.layers
) 中的 activation=
争论 :model.add( keras.layers.Dense( 25 , activation=tf.keras.activations.relu ) )
但是,它也可以用作上一节中的示例。它更特定于 Keras(
Sequential
或 Model
),而不是原始 TensorFlow 计算。
tf.nn.relu
is a TensorFlow specific whereastf.keras.activations.relu
has more uses in Keras own library. If I create a NN with only TF, I will most probably usetf.nn.relu
and if I am creating a Keras Sequential model then I will usetf.keras.activations.relu
.
关于tensorflow - tf.nn.relu vs tf.keras.activations.relu,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54761088/