张量流中的激活函数之间有区别吗? tf.nn.tanh 对比 tf.tanh

Is there a difference between activations functions in tensorflow? tf.nn.tanh vs tf.tanh

我想建立一个神经元网络,我在问自己这两个功能之间是否有区别?

tf.nn.tanh 对比 tf.tanh

它们与 tensorflow.python.ops.math_ops.tanh.

的别名完全相同

tf.sigmoidtf.nn.sigmoid 也是一样。

不,没有区别。

tensorflow/tensorflow/python/ops/nn.py文件中(就是定义tf.nn的地方)我们可以找到tanh的定义:

from tensorflow.python.ops.math_ops import tanh

还有这个TODOhere

# TODO(cwhipkey): sigmoid and tanh should not be exposed from tf.nn.

因此,tanh 可能会从 tf.nn 包中删除。

因此 tf.tanh(已定义 here)是要使用的。

不,没有任何区别。

两者的可用性可能是由于图书馆不断发展并仍在改变其 API,仍处于成熟的初始状态。 我们可以期望库在最终设置主 API 时避免这些基本重复(我希望在 2.0 中如此)。

很容易确认它们是相同的:

In [1]: import tensorflow as tf

In [2]: tf.nn.tanh
Out[2]: <function tensorflow.python.ops.math_ops.tanh>

In [3]: tf.tanh
Out[3]: <function tensorflow.python.ops.math_ops.tanh>

In [4]: tf.nn.tanh == tf.tanh
Out[4]: True

In [5]: tf.__version__
Out[5]: '0.11.0rc1'