tensorflow - tf.nn.relu vs tf.keras.activations.relu

标签 tensorflow tf.keras

关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。












想改进这个问题?将问题更新为 on-topic对于堆栈溢出。

3年前关闭。




Improve this question




我都看到了tf.nn.relutf.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(SequentialModel),而不是原始 TensorFlow 计算。

  • tf.nn.relu is a TensorFlow specific whereas tf.keras.activations.relu has more uses in Keras own library. If I create a NN with only TF, I will most probably use tf.nn.relu and if I am creating a Keras Sequential model then I will use tf.keras.activations.relu.

    关于tensorflow - tf.nn.relu vs tf.keras.activations.relu,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54761088/

    相关文章:

    python - 字符 LSTM 不断生成相同的字符序列

    python - 多 GPU/Tower 设置 Tensorflow 1.2 Estimator

    python - flow_from_directory 似乎找不到图像,但正确识别了类

    python - 在评估 TensorFlow 模型时,如何在单个前向调用中查看特定隐藏层的值?

    tensorflow - 在 TensorFlow 中使用 session.run([]) 评估损失

    用于 debian 的 Tensorflow GPU

    python - 在 keras 上使用 multiple_gpu_model - 导致资源耗尽

    python - 如何实现一个以非全连接层作为最后一层的神经网络?

    Tensorflow 2.0 Keras 模型子类化

    python - 为什么在 Keras 子类化 API 中,永远不会调用 call 方法,而是通过调用此类的对象来传递输入?