tensorflow - TensorFlow 中的 tf.nn.sigmoid 实现

标签 tensorflow tensorflow2.0

您能否指出 TensorFlow (2.0) 中 tf.nn.sigmoid 函数的实际 C++ 实现?仅用于教育目的。

谢谢。

最佳答案

Tensorflow 源代码导航起来可能有点棘手。以下是我用来查找实现文件的一些想法。

可以看到这里用python定义了tf.nn.sigmoid

tensorflow/python/ops/math_ops.py .

如果您查看此函数定义,您会发现它返回 gen_math_ops 中定义的 sigmoid 函数。我花了一段时间才弄清楚,但如果你在 tensorflow/python/ops 中搜索 gen_math_ops,你将找不到它。前面带有 gen_ 的任何内容都是 tensorflow 的名称,它给出了由 C++ 代码注册的操作。

我们在内核实现中真正想要的。这些可以在 tensorflow/core/kernels 中找到。 “sigmoid” 的快速 ctrl+f 将我们指向 cwise_op_sigmoid.cc。这不包含实现,但将我们指向头文件 cwise_ops_common.h。这也不包含实现,但将我们指向 cwise_ops.h。在此文件中为 “sigmoid” 按 ctrl+f,我们在 877 行找到“实现” .你可以看到这是一个封装了 Eigen 操作的仿函数 Eigen::internal::scalar_logistic_opHere是该操作的文档。如果您好奇该操作是如何实现的,我会下载源代码。你可以找到它here .

关于tensorflow - TensorFlow 中的 tf.nn.sigmoid 实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58633601/

相关文章:

python - 训练多输出 keras 模型

python - TF2 中的 tf.print 未打印到输出

python-3.x - 如何在 TensorFlow 2.x 中加载 TensorFlow 1.x 保存的模型?

python-3.x - cumalativive 所有其他列都需要 python ML 中带有 cumsum() 的日期列

python - 如何将 tokenizer.fit_on_texts() 应用于包含需要训练的两列对象/字符串的数据框?

python - 模型返回错误 - ValueError : logits and labels must have the same shape ((None, 18) vs (None, 1))

tensorflow - Keras 层级联

python - 属性错误 : 'str' object has no attribute 'ndim'

python - 如何在 tensorflow 2.0 中为自定义量化反向传播?

python-3.x - 如何将 Tensorflow 2.0 SavedModel 转换为 TensorRT?