C++ TensorFlow SoftmaxCrossEntropWithLogits 返回(成本,梯度),如何访问成本?

标签 c++ tensorflow

我正在尝试在 C++ TensorFlow 中实现一个简单的神经网络。

我无法访问 SoftmaxCrossEntropyWithLogits 函数 ( https://www.tensorflow.org/api_docs/cc/class/tensorflow/ops/softmax-cross-entropy-with-logits ) 返回的损失。

请检查上述链接中的“返回”部分。我只想访问“损失”输出。我无法用 C++ 编写它。

谢谢

最佳答案

这里它不返回任何东西,它是一个属性。您可以从类实例访问它。

#define the loss class instance with your logits and labels
softmax_loss_function = SoftmaxCrossEntropyWithLogits(const ::tensorflow::Scope & scope, ::tensorflow::Input features, ::tensorflow::Input labels) 
# access the loss
loss = softmax_loss_function.loss

关于C++ TensorFlow SoftmaxCrossEntropWithLogits 返回(成本,梯度),如何访问成本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45631925/

相关文章:

c++ - 最佳操作系统抽象?

c++ - 如何在跳过所有内部实现的同时跳转到 GDB 中 std::function 中的函数?

C++ - 用户空间代码中的二级保护代码

tensorflow - 检查点 keras 模型 : TypeError: can't pickle _thread. 锁定对象

python - 在时间序列分析中对 tf.data.dataset 进行批处理

c++ - 在 Ubuntu 中获取 CPU 时间?

C++ 动态分配的 std::vector

python - Tensorflow:将 `tf.data.Dataset` 迭代器转换为张量

tensorflow - Tensorflow 如何计算模型的准确率?

tensorflow - 有什么方法可以使用tensorflow-federated API对真实的多台机器进行联邦学习吗?