- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
调用以下方法时:
losses = [tf.nn.sparse_softmax_cross_entropy_with_logits(logits, labels)
for logits, labels in zip(logits_series,labels_series)]
我收到以下 ValueError:
ValueError: Only call `sparse_softmax_cross_entropy_with_logits` with named arguments (labels=..., logits=..., ...)
反对这一点:
[tf.nn.sparse_softmax_cross_entropy_with_logits(logits, labels)
根据 nn_ops.py 的文档,我需要确保登录名和标签已初始化为以下内容:
def _ensure_xent_args(name, sentinel, labels, logits): # Make sure that all arguments were passed as named arguments. if sentinel is not None: raise ValueError("Only call
%s
with " "named arguments (labels=..., logits=..., ...)" % name) if labels is None or logits is None: raise ValueError("Both labels and logits must be provided.")Logits=X, labels =Y
这是什么原因呢?我是否将它们初始化为某个值,例如损失?或者?
最佳答案
原因是 tf.nn.sparse_softmax_cross_entropy_with_logits
的第一个参数是_sentinel
:
_sentinel
: Used to prevent positional parameters. Internal, do not use.
此 API 鼓励您命名您的参数,如下所示:
tf.nn.sparse_softmax_cross_entropy_with_logits(logits=logits, labels=labels)
...这样您就不会意外地将 logits
传递给 labels
,反之亦然。
关于python - tensorflow 值错误: Only call `sparse_softmax_cross_entropy_with_logits` with named arguments,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47909606/
我目前正在使用 tensorflow 解决 SegNet Architecture 上的多类分割问题 我的类(class)严重不平衡,因此我需要整合 median frequency balancin
我尝试手动重新计算该函数的输出,因此我创建了一个最小的示例: logits = tf.pack(np.array([[[[0,1,2]]]],dtype=np.float32)) # img of s
我一直致力于使用 tensorflow 损失(sparse_softmax_cross_entropy_with_logits)编写 keras 模型,并且遇到了这个问题。对于此模型,真实值应该是形状
我开始使用 tensorflow(来自 Caffe),我正在使用损失 sparse_softmax_cross_entropy_with_logits。该函数接受像 0,1,...C-1 这样的标签,
调用以下方法时: losses = [tf.nn.sparse_softmax_cross_entropy_with_logits(logits, labels) for logi
当我尝试在 tensorflow 中使用 sparse_softmax_cross_entropy_with_logits 损失函数时得到 NaN。我有一个简单的网络,例如: layer = tf.n
我已阅读 docs of both functions ,但据我所知,对于函数 tf.nn.softmax_cross_entropy_with_logits(logits, labels, dim=
我是一名优秀的程序员,十分优秀!